-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "--upgrade-from-muon" flag to auto-import from Muon #729
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ImporterList>(); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is fine because the profile is initialized in PreMainMessageLoopRun and this will run after the chrome extra parts, but I think we want to guard this with local_state pref that is set after import instead of using a command line flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think guarding with a local_state pref would be preferable to conditioning auto-import on first run, e.g. via first_run::IsChromeFirstRun?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a command line flag to distinguish "Brave-Core is running for the first time after being installed by the Muon upgrader" and "Brave-Core is running for the first time after being downloaded and installed de novo". See brave/brave-browser#1545 (comment) for discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we just upgrade by default if we detect a previous browser-laptop install? Then no command line flag is necessary and a pref would work fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this in a meeting last week and consensus was that auto-import should only happen in the case where the user is running browser-laptop and performs the update that migrates them to brave-core. We need a way to distinguish this from the case where the user downloads and installs brave-core separately, but may also have an existing browser-laptop installation (which could be their current/default browser, or defunct and unused and therefore probably not desirable to auto-import from). We agreed that passing a command line argument to the brave-core binary from the auto-update was the best way to distinguish these cases.
cc @bsclifton @davidtemkin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridiver What do you think of the local state pref I added in 51c68d4? With this addition,
--upgrade-from-muon
command line flag