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

Side by Side 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: Added check for Oauth data consistency. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/about_flags.h" 31 #include "chrome/browser/about_flags.h"
32 #include "chrome/browser/app_mode/app_mode_utils.h" 32 #include "chrome/browser/app_mode/app_mode_utils.h"
33 #include "chrome/browser/browser_process.h" 33 #include "chrome/browser/browser_process.h"
34 #include "chrome/browser/browser_shutdown.h" 34 #include "chrome/browser/browser_shutdown.h"
35 #include "chrome/browser/chrome_notification_types.h" 35 #include "chrome/browser/chrome_notification_types.h"
36 #include "chrome/browser/chromeos/boot_times_loader.h" 36 #include "chrome/browser/chromeos/boot_times_loader.h"
37 #include "chrome/browser/chromeos/login/auth/parallel_authenticator.h" 37 #include "chrome/browser/chromeos/login/auth/parallel_authenticator.h"
38 #include "chrome/browser/chromeos/login/auth/user_context.h" 38 #include "chrome/browser/chromeos/login/auth/user_context.h"
39 #include "chrome/browser/chromeos/login/chrome_restart_request.h" 39 #include "chrome/browser/chromeos/login/chrome_restart_request.h"
40 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" 40 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
41 #include "chrome/browser/chromeos/login/existing_user_controller.h"
41 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 42 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
42 #include "chrome/browser/chromeos/login/profile_auth_data.h" 43 #include "chrome/browser/chromeos/login/profile_auth_data.h"
43 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" 44 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h"
44 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h" 45 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory .h"
45 #include "chrome/browser/chromeos/login/session/session_manager.h" 46 #include "chrome/browser/chromeos/login/session/session_manager.h"
46 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" 47 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
47 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h" 48 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager_factory.h"
48 #include "chrome/browser/chromeos/login/startup_utils.h" 49 #include "chrome/browser/chromeos/login/startup_utils.h"
49 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h" 50 #include "chrome/browser/chromeos/login/ui/input_events_blocker.h"
50 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 51 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
(...skipping 30 matching lines...) Expand all
81 #include "google_apis/gaia/gaia_auth_consumer.h" 82 #include "google_apis/gaia/gaia_auth_consumer.h"
82 #include "net/base/network_change_notifier.h" 83 #include "net/base/network_change_notifier.h"
83 #include "net/url_request/url_request_context.h" 84 #include "net/url_request/url_request_context.h"
84 #include "net/url_request/url_request_context_getter.h" 85 #include "net/url_request/url_request_context_getter.h"
85 #include "url/gurl.h" 86 #include "url/gurl.h"
86 87
87 using content::BrowserThread; 88 using content::BrowserThread;
88 89
89 namespace chromeos { 90 namespace chromeos {
90 91
92 namespace {
93
94 // Returns new CommandLine with per-user flags.
95 CommandLine CreatePerSessionCommandLine(Profile* profile) {
96 CommandLine user_flags(CommandLine::NO_PROGRAM);
97 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs());
98 about_flags::ConvertFlagsToSwitches(
99 &flags_storage_, &user_flags, about_flags::kAddSentinels);
100 return user_flags;
101 }
102
103 // Returns true if restart is needed to apply per-session flags.
104 bool NeedRestartToApplyPerSessionFlags(const CommandLine& user_flags) {
105 // Don't restart browser if it is not first profile in session.
106 if (UserManager::Get()->GetLoggedInUsers().size() != 1)
107 return false;
108
109 // Only restart if needed and if not going into managed mode.
110 if (UserManager::Get()->IsLoggedInAsLocallyManagedUser())
111 return false;
112
113 if (about_flags::AreSwitchesIdenticalToCurrentCommandLine(
114 user_flags, *CommandLine::ForCurrentProcess())) {
115 return false;
116 }
117
118 return true;
119 }
120
121 bool CanPerformEarlyRestart() {
122 LOG(ERROR) << "CanPerformEarlyRestart(): called.";
123 const ExistingUserController* controller =
124 ExistingUserController::current_controller();
125 if (!controller)
Nikita (slow) 2014/06/18 12:23:30 Could be simplified as return !controller ||
Alexander Alekseev 2014/06/18 15:06:55 I decided to add comments here and rely on optimiz
126 return true;
127
128 // Early restart is possible only if user keys are up to date.
Nikita (slow) 2014/06/18 12:23:30 nit: I guess this should say "OAuth token is up to
Alexander Alekseev 2014/06/18 15:06:55 Done.
129
130 if (controller->password_changed())
131 return false;
132
133 if (controller->auth_mode() != LoginPerformer::AUTH_MODE_INTERNAL)
134 return false;
135
136 return true;
137 }
138
139 } // namespace
140
91 struct DoBrowserLaunchOnLocaleLoadedData; 141 struct DoBrowserLaunchOnLocaleLoadedData;
92 142
93 class LoginUtilsImpl 143 class LoginUtilsImpl
94 : public LoginUtils, 144 : public LoginUtils,
95 public base::SupportsWeakPtr<LoginUtilsImpl>, 145 public base::SupportsWeakPtr<LoginUtilsImpl>,
96 public SessionManager::Delegate { 146 public SessionManager::Delegate {
97 public: 147 public:
98 LoginUtilsImpl() 148 LoginUtilsImpl()
99 : delegate_(NULL) { 149 : delegate_(NULL) {
100 } 150 }
101 151
102 virtual ~LoginUtilsImpl() { 152 virtual ~LoginUtilsImpl() {
103 } 153 }
104 154
105 // LoginUtils implementation: 155 // LoginUtils implementation:
106 virtual void DoBrowserLaunch(Profile* profile, 156 virtual void DoBrowserLaunch(Profile* profile,
107 LoginDisplayHost* login_host) OVERRIDE; 157 LoginDisplayHost* login_host) OVERRIDE;
108 virtual void PrepareProfile( 158 virtual void PrepareProfile(
109 const UserContext& user_context, 159 const UserContext& user_context,
110 bool has_cookies, 160 bool has_cookies,
111 bool has_active_session, 161 bool has_active_session,
112 LoginUtils::Delegate* delegate) OVERRIDE; 162 LoginUtils::Delegate* delegate) OVERRIDE;
113 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE; 163 virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE;
114 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; 164 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE;
115 virtual scoped_refptr<Authenticator> CreateAuthenticator( 165 virtual scoped_refptr<Authenticator> CreateAuthenticator(
116 LoginStatusConsumer* consumer) OVERRIDE; 166 LoginStatusConsumer* consumer) OVERRIDE;
167 virtual bool RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
168 bool early_restart) OVERRIDE;
117 169
118 // SessionManager::Delegate implementation: 170 // SessionManager::Delegate implementation:
119 virtual void OnProfilePrepared(Profile* profile) OVERRIDE; 171 virtual void OnProfilePrepared(Profile* profile) OVERRIDE;
120 #if defined(ENABLE_RLZ) 172 #if defined(ENABLE_RLZ)
121 virtual void OnRlzInitialized() OVERRIDE; 173 virtual void OnRlzInitialized() OVERRIDE;
122 #endif 174 #endif
123 175
124 private: 176 private:
125 // DoBrowserLaunch is split into two parts. 177 // DoBrowserLaunch is split into two parts.
126 // This one is called after asynchronous locale switch. 178 // This one is called after asynchronous locale switch.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // DoBrowserLaunchOnLocaleLoaded() depending on 257 // DoBrowserLaunchOnLocaleLoaded() depending on
206 // if locale switch was needed. 258 // if locale switch was needed.
207 void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl( 259 void LoginUtilsImpl::DoBrowserLaunchOnLocaleLoadedImpl(
208 Profile* profile, 260 Profile* profile,
209 LoginDisplayHost* login_host) { 261 LoginDisplayHost* login_host) {
210 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { 262 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) {
211 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); 263 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile);
212 return; 264 return;
213 } 265 }
214 266
215 CommandLine user_flags(CommandLine::NO_PROGRAM); 267 if (RestartToApplyPerSessionFlagsIfNeed(profile, false))
216 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs());
217 about_flags::ConvertFlagsToSwitches(&flags_storage_, &user_flags,
218 about_flags::kAddSentinels);
219 // Only restart if needed and if not going into managed mode.
220 // Don't restart browser if it is not first profile in session.
221 if (UserManager::Get()->GetLoggedInUsers().size() == 1 &&
222 !UserManager::Get()->IsLoggedInAsLocallyManagedUser() &&
223 !about_flags::AreSwitchesIdenticalToCurrentCommandLine(
224 user_flags, *CommandLine::ForCurrentProcess())) {
225 CommandLine::StringVector flags;
226 // argv[0] is the program name |CommandLine::NO_PROGRAM|.
227 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
228 VLOG(1) << "Restarting to apply per-session flags...";
229 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
230 UserManager::Get()->GetActiveUser()->email(), flags);
231 AttemptRestart(profile);
232 return; 268 return;
233 }
234 269
235 if (login_host) { 270 if (login_host) {
236 login_host->SetStatusAreaVisible(true); 271 login_host->SetStatusAreaVisible(true);
237 login_host->BeforeSessionStart(); 272 login_host->BeforeSessionStart();
238 } 273 }
239 274
240 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false); 275 BootTimesLoader::Get()->AddLoginTimeMarker("BrowserLaunched", false);
241 276
242 VLOG(1) << "Launching browser..."; 277 VLOG(1) << "Launching browser...";
278 TRACE_EVENT0("login", "LaunchBrowser");
243 StartupBrowserCreator browser_creator; 279 StartupBrowserCreator browser_creator;
244 int return_code; 280 int return_code;
245 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? 281 chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ?
246 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; 282 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN;
247 283
248 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), 284 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(),
249 profile, 285 profile,
250 base::FilePath(), 286 base::FilePath(),
251 chrome::startup::IS_PROCESS_STARTUP, 287 chrome::startup::IS_PROCESS_STARTUP,
252 first_run, 288 first_run,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 has_cookies, 338 has_cookies,
303 has_active_session, 339 has_active_session,
304 this); 340 this);
305 } 341 }
306 342
307 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { 343 void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) {
308 if (delegate_ == delegate) 344 if (delegate_ == delegate)
309 delegate_ = NULL; 345 delegate_ = NULL;
310 } 346 }
311 347
348 bool LoginUtilsImpl::RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
349 bool early_restart) {
350 if (early_restart && !CanPerformEarlyRestart())
351 return false;
352
353 const CommandLine user_flags(CreatePerSessionCommandLine(profile));
354 if (!NeedRestartToApplyPerSessionFlags(user_flags))
355 return false;
356
357 CommandLine::StringVector flags;
358 // argv[0] is the program name |CommandLine::NO_PROGRAM|.
359 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
360 VLOG(1) << "Restarting to apply per-session flags...";
361 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
362 UserManager::Get()->GetActiveUser()->email(), flags);
363 AttemptRestart(profile);
364 return true;
365 }
366
312 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) { 367 void LoginUtilsImpl::CompleteOffTheRecordLogin(const GURL& start_url) {
313 VLOG(1) << "Completing incognito login"; 368 VLOG(1) << "Completing incognito login";
314 369
315 // For guest session we ask session manager to restart Chrome with --bwsi 370 // For guest session we ask session manager to restart Chrome with --bwsi
316 // flag. We keep only some of the arguments of this process. 371 // flag. We keep only some of the arguments of this process.
317 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 372 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
318 CommandLine command_line(browser_command_line.GetProgram()); 373 CommandLine command_line(browser_command_line.GetProgram());
319 std::string cmd_line_str = 374 std::string cmd_line_str =
320 GetOffTheRecordCommandLine(start_url, 375 GetOffTheRecordCommandLine(start_url,
321 StartupUtils::IsOobeCompleted(), 376 StartupUtils::IsOobeCompleted(),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 CrosSettings* cros_settings = CrosSettings::Get(); 455 CrosSettings* cros_settings = CrosSettings::Get();
401 bool allow_new_user = false; 456 bool allow_new_user = false;
402 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 457 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
403 if (allow_new_user) 458 if (allow_new_user)
404 return true; 459 return true;
405 return cros_settings->FindEmailInList( 460 return cros_settings->FindEmailInList(
406 kAccountsPrefUsers, username, wildcard_match); 461 kAccountsPrefUsers, username, wildcard_match);
407 } 462 }
408 463
409 } // namespace chromeos 464 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698