diff --git a/browser/BUILD.gn b/browser/BUILD.gn index f240b5504a7a..0a58b89a1e06 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -33,20 +33,6 @@ source_set("browser_process") { "geolocation/brave_geolocation_permission_context.h", "guest_window_search_engine_provider_controller.cc", "guest_window_search_engine_provider_controller.h", - "importer/brave_external_process_importer_client.cc", - "importer/brave_external_process_importer_client.h", - "importer/brave_external_process_importer_host.cc", - "importer/brave_external_process_importer_host.h", - "importer/brave_importer_lock_dialog.h", - "importer/brave_in_process_importer_bridge.cc", - "importer/brave_in_process_importer_bridge.h", - "importer/brave_profile_writer.cc", - "importer/brave_profile_writer.h", - "importer/brave_profile_lock.cc", - "importer/brave_profile_lock.h", - "importer/browser_profile_lock.h", - "importer/chrome_profile_lock.cc", - "importer/chrome_profile_lock.h", "mac/sparkle_glue.mm", "mac/sparkle_glue.h", "mac/su_updater.h", @@ -123,6 +109,7 @@ source_set("browser") { "//chrome/browser", "download", "extensions", + "importer", "net", "permissions", "profiles", diff --git a/browser/brave_browser_main_extra_parts.cc b/browser/brave_browser_main_extra_parts.cc index dc195bd075d2..33a5384617ef 100644 --- a/browser/brave_browser_main_extra_parts.cc +++ b/browser/brave_browser_main_extra_parts.cc @@ -5,6 +5,7 @@ #include "brave/browser/brave_browser_main_extra_parts.h" #include "brave/common/resource_bundle_helper.h" +#include "chrome/browser/first_run/first_run.h" BraveBrowserMainExtraParts::BraveBrowserMainExtraParts() { } @@ -15,3 +16,7 @@ BraveBrowserMainExtraParts::~BraveBrowserMainExtraParts() { void BraveBrowserMainExtraParts::PreCreateThreads() { brave::InitializeResourceBundle(); } + +void BraveBrowserMainExtraParts::PreMainMessageLoopRun() { + brave::AutoImportMuon(); +} diff --git a/browser/brave_browser_main_extra_parts.h b/browser/brave_browser_main_extra_parts.h index 65207e835825..c08e0da6257f 100644 --- a/browser/brave_browser_main_extra_parts.h +++ b/browser/brave_browser_main_extra_parts.h @@ -17,6 +17,7 @@ class BraveBrowserMainExtraParts : public ChromeBrowserMainExtraParts { // ChromeBrowserMainExtraParts overrides. void PreCreateThreads() override; + void PreMainMessageLoopRun() override; private: DISALLOW_COPY_AND_ASSIGN(BraveBrowserMainExtraParts); diff --git a/browser/brave_local_state_prefs.cc b/browser/brave_local_state_prefs.cc index 016976153112..6980234bec78 100644 --- a/browser/brave_local_state_prefs.cc +++ b/browser/brave_local_state_prefs.cc @@ -8,6 +8,7 @@ #include "brave/browser/brave_stats_updater.h" #include "brave/browser/referrals/brave_referrals_service.h" #include "brave/browser/tor/tor_profile_service.h" +#include "chrome/browser/first_run/first_run.h" #include "chrome/common/pref_names.h" #include "components/prefs/pref_registry_simple.h" @@ -22,6 +23,7 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) { base::Value(false)); #endif tor::TorProfileService::RegisterLocalStatePrefs(registry); + RegisterPrefsForMuonMigration(registry); } } // namespace brave diff --git a/browser/importer/BUILD.gn b/browser/importer/BUILD.gn new file mode 100644 index 000000000000..15e129f4287e --- /dev/null +++ b/browser/importer/BUILD.gn @@ -0,0 +1,24 @@ +import("//build/config/features.gni") + +source_set("importer") { + sources = [ + "brave_external_process_importer_client.cc", + "brave_external_process_importer_client.h", + "brave_external_process_importer_host.cc", + "brave_external_process_importer_host.h", + "brave_importer_lock_dialog.h", + "brave_in_process_importer_bridge.cc", + "brave_in_process_importer_bridge.h", + "brave_profile_writer.cc", + "brave_profile_writer.h", + "brave_profile_lock.cc", + "brave_profile_lock.h", + "browser_profile_lock.h", + "chrome_profile_lock.cc", + "chrome_profile_lock.h", + ] + + deps = [ + "//chrome/browser", + ] +} diff --git a/chromium_src/chrome/browser/first_run/first_run.cc b/chromium_src/chrome/browser/first_run/first_run.cc new file mode 100644 index 000000000000..a6e35410e224 --- /dev/null +++ b/chromium_src/chrome/browser/first_run/first_run.cc @@ -0,0 +1,82 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/brave_browser_process_impl.h" +#include "brave/common/brave_switches.h" +#include "brave/common/pref_names.h" + +#include "base/command_line.h" +#include "base/logging.h" +#include "base/run_loop.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/importer/external_process_importer_host.h" +#include "chrome/browser/importer/importer_list.h" +#include "chrome/browser/importer/importer_progress_observer.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/common/importer/importer_data_types.h" +#include "components/prefs/pref_registry_simple.h" +#include "components/prefs/pref_service.h" + +#include "../../../../../chrome/browser/first_run/first_run.cc" + +namespace brave { + +void AutoImportMuon() { + base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + if (!command_line.HasSwitch(switches::kUpgradeFromMuon)) + return; + + PrefService* local_state = g_browser_process->local_state(); + if (local_state->GetBoolean(kMigratedMuonProfile)) { + LOG(WARNING) << "Muon profile already migrated, ignoring --upgrade-from-muon"; + return; + } + + LOG(INFO) << "Auto-importing Muon profile"; + + base::RunLoop run_loop; + auto importer_list = std::make_unique(); + importer_list->DetectSourceProfiles( + g_browser_process->GetApplicationLocale(), + false, // include_interactive_profiles + run_loop.QuitClosure()); + run_loop.Run(); + + bool brave_profile_found = false; + size_t brave_profile_index = 0; + for (size_t i = 0; i < importer_list->count(); i++) { + const auto& source_profile = importer_list->GetSourceProfileAt(i); + if (source_profile.importer_type == importer::TYPE_BRAVE) { + brave_profile_found = true; + brave_profile_index = i; + break; + } + } + if (!brave_profile_found) { + LOG(INFO) << "Muon profile not found"; + return; + } + + const importer::SourceProfile& source_profile = + importer_list->GetSourceProfileAt(brave_profile_index); + + // Import every possible type of data from the Muon profile. + uint16_t items_to_import = 0; + items_to_import |= source_profile.services_supported; + + ProfileManager* profile_manager = g_browser_process->profile_manager(); + Profile* target_profile = profile_manager->GetLastUsedProfile(); + + ImportFromSourceProfile(source_profile, target_profile, items_to_import); + + // Mark Muon profile as migrated so we don't attempt to import it again. + local_state->SetBoolean(kMigratedMuonProfile, true); +} + +void RegisterPrefsForMuonMigration(PrefRegistrySimple* registry) { + registry->RegisterBooleanPref(kMigratedMuonProfile, false); +} + +} // namespace brave diff --git a/chromium_src/chrome/browser/first_run/first_run.h b/chromium_src/chrome/browser/first_run/first_run.h new file mode 100644 index 000000000000..8c3728c607ee --- /dev/null +++ b/chromium_src/chrome/browser/first_run/first_run.h @@ -0,0 +1,21 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_ + +#include "../../../../../chrome/browser/first_run/first_run.h" + +class PrefRegistrySimple; + +namespace brave { + +void AutoImportMuon(); + +// Registers the preferences used to track the state of migration from Muon +void RegisterPrefsForMuonMigration(PrefRegistrySimple* registry); + +} // namespace brave + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FIRST_RUN_FIRST_RUN_H_ diff --git a/common/brave_switches.cc b/common/brave_switches.cc index 1507ebf98434..1896be336fb6 100644 --- a/common/brave_switches.cc +++ b/common/brave_switches.cc @@ -38,4 +38,8 @@ const char kRewardsReconcileInterval[] = "rewards-reconcile-interval"; // Valid values are: "dark" | "light". const char kUiMode[] = "ui-mode"; +// Triggers auto-import of profile data from Brave browser-laptop/Muon, if +// available. +const char kUpgradeFromMuon[] = "upgrade-from-muon"; + } // namespace switches diff --git a/common/brave_switches.h b/common/brave_switches.h index 256db0ee9cb9..a611fc15ac77 100644 --- a/common/brave_switches.h +++ b/common/brave_switches.h @@ -27,6 +27,8 @@ extern const char kRewardsReconcileInterval[]; extern const char kUiMode[]; +extern const char kUpgradeFromMuon[]; + } // namespace switches #endif // BRAVE_COMMON_BRAVE_SWITCHES_H_ diff --git a/common/pref_names.cc b/common/pref_names.cc index 375181b45322..8d497373da96 100644 --- a/common/pref_names.cc +++ b/common/pref_names.cc @@ -32,3 +32,4 @@ const char kReferralCheckedForPromoCodeFile[] = "brave.referral.checked_for_prom const char kHTTPSEVerywhereControlType[] = "brave.https_everywhere_default"; const char kNoScriptControlType[] = "brave.no_script_default"; const char kRewardsNotifications[] = "brave.rewards.notifications"; +const char kMigratedMuonProfile[] = "brave.muon.migrated_profile"; diff --git a/common/pref_names.h b/common/pref_names.h index d947b8063eaa..12a9767bad39 100644 --- a/common/pref_names.h +++ b/common/pref_names.h @@ -31,5 +31,6 @@ extern const char kReferralCheckedForPromoCodeFile[]; extern const char kHTTPSEVerywhereControlType[]; extern const char kNoScriptControlType[]; extern const char kRewardsNotifications[]; +extern const char kMigratedMuonProfile[]; #endif // BRAVE_COMMON_PREF_NAMES_H_