Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 322533002: Restart Chrome on ChromeOS as early as possible to speed up restart. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win build. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.h ('k') | chrome/browser/chromeos/login/mock_login_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/login_utils.cc
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index a39d6cbfeac4cb01a28b8325bbf31372ce995df7..b7be64146ce1ac0e862aed809019d72d6f4c9e09 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -38,6 +38,7 @@
#include "chrome/browser/chromeos/login/auth/user_context.h"
#include "chrome/browser/chromeos/login/chrome_restart_request.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
+#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/chromeos/login/profile_auth_data.h"
#include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
@@ -88,6 +89,55 @@ using content::BrowserThread;
namespace chromeos {
+namespace {
+
+// Returns new CommandLine with per-user flags.
+CommandLine CreatePerSessionCommandLine(Profile* profile) {
+ CommandLine user_flags(CommandLine::NO_PROGRAM);
+ about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs());
+ about_flags::ConvertFlagsToSwitches(
+ &flags_storage_, &user_flags, about_flags::kAddSentinels);
+ return user_flags;
+}
+
+// Returns true if restart is needed to apply per-session flags.
+bool NeedRestartToApplyPerSessionFlags(const CommandLine& user_flags) {
+ // Don't restart browser if it is not first profile in session.
+ if (UserManager::Get()->GetLoggedInUsers().size() != 1)
+ return false;
+
+ // Only restart if needed and if not going into managed mode.
+ if (UserManager::Get()->IsLoggedInAsLocallyManagedUser())
+ return false;
+
+ if (about_flags::AreSwitchesIdenticalToCurrentCommandLine(
+ user_flags, *CommandLine::ForCurrentProcess())) {
+ return false;
+ }
+
+ return true;
+}
+
+bool CanPerformEarlyRestart() {
+ LOG(ERROR) << "CanPerformEarlyRestart(): called.";
Nikita (slow) 2014/06/27 17:19:46 I don't think that this LOG(ERROR) is really neede
+ const ExistingUserController* controller =
+ ExistingUserController::current_controller();
+ if (!controller)
+ return true;
+
+ // Early restart is possible only if OAuth token is up to date.
+
+ if (controller->password_changed())
+ return false;
+
+ if (controller->auth_mode() != LoginPerformer::AUTH_MODE_INTERNAL)
+ return false;
+
+ return true;
+}
+
+} // namespace
+
struct DoBrowserLaunchOnLocaleLoadedData;
class LoginUtilsImpl
@@ -114,6 +164,8 @@ class LoginUtilsImpl
virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE;
virtual scoped_refptr<Authenticator> CreateAuthenticator(
LoginStatusConsumer* consumer) OVERRIDE;
+ virtual bool RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
+ bool early_restart) OVERRIDE;
// SessionManager::Delegate implementation:
virtual void OnProfilePrepared(Profile* profile) OVERRIDE;
@@ -212,25 +264,8 @@ void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl(
return;
}
- CommandLine user_flags(CommandLine::NO_PROGRAM);
- about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs());
- about_flags::ConvertFlagsToSwitches(&flags_storage_, &user_flags,
- about_flags::kAddSentinels);
- // Only restart if needed and if not going into managed mode.
- // Don't restart browser if it is not first profile in session.
- if (UserManager::Get()->GetLoggedInUsers().size() == 1 &&
- !UserManager::Get()->IsLoggedInAsLocallyManagedUser() &&
- !about_flags::AreSwitchesIdenticalToCurrentCommandLine(
- user_flags, *CommandLine::ForCurrentProcess())) {
- CommandLine::StringVector flags;
- // argv[0] is the program name |CommandLine::NO_PROGRAM|.
- flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
- VLOG(1) << "Restarting to apply per-session flags...";
- DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
- UserManager::Get()->GetActiveUser()->email(), flags);
- AttemptRestart(profile);
+ if (RestartToApplyPerSessionFlagsIfNeed(profile, false))
return;
- }
if (login_host) {
login_host->SetStatusAreaVisible(true);
@@ -240,6 +275,7 @@ void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl(
BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false);
VLOG(1) << "Launching browser...";
+ TRACE_EVENT0("login", "LaunchBrowser");
StartupBrowserCreator browser_creator;
int return_code;
chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
@@ -309,6 +345,25 @@ void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) {
delegate_ = NULL;
}
+bool LoginUtilsImpl::RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
+ bool early_restart) {
+ if (early_restart && !CanPerformEarlyRestart())
+ return false;
+
+ const CommandLine user_flags(CreatePerSessionCommandLine(profile));
+ if (!NeedRestartToApplyPerSessionFlags(user_flags))
+ return false;
+
+ CommandLine::StringVector flags;
+ // argv[0] is the program name |CommandLine::NO_PROGRAM|.
+ flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
+ VLOG(1) << "Restarting to apply per-session flags...";
+ DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
+ UserManager::Get()->GetActiveUser()->email(), flags);
+ AttemptRestart(profile);
+ return true;
+}
+
void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) {
VLOG(1) << "Completing incognito login";
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.h ('k') | chrome/browser/chromeos/login/mock_login_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698