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

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 2047483003: Add fallback behavior if the last used profile cannot initialize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bug-614753-fix
Patch Set: Refactored startup profile choosing code, reduced number of messages, bug fix (oops) Created 4 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/chrome_browser_main.h" 5 #include "chrome/browser/chrome_browser_main.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #include "chrome/browser/profiles/profile_attributes_storage.h" 81 #include "chrome/browser/profiles/profile_attributes_storage.h"
82 #include "chrome/browser/profiles/profile_manager.h" 82 #include "chrome/browser/profiles/profile_manager.h"
83 #include "chrome/browser/profiles/profiles_state.h" 83 #include "chrome/browser/profiles/profiles_state.h"
84 #include "chrome/browser/shell_integration.h" 84 #include "chrome/browser/shell_integration.h"
85 #include "chrome/browser/tracing/navigation_tracing.h" 85 #include "chrome/browser/tracing/navigation_tracing.h"
86 #include "chrome/browser/translate/translate_service.h" 86 #include "chrome/browser/translate/translate_service.h"
87 #include "chrome/browser/ui/app_list/app_list_service.h" 87 #include "chrome/browser/ui/app_list/app_list_service.h"
88 #include "chrome/browser/ui/app_modal/chrome_javascript_native_dialog_factory.h" 88 #include "chrome/browser/ui/app_modal/chrome_javascript_native_dialog_factory.h"
89 #include "chrome/browser/ui/browser.h" 89 #include "chrome/browser/ui/browser.h"
90 #include "chrome/browser/ui/browser_finder.h" 90 #include "chrome/browser/ui/browser_finder.h"
91 #include "chrome/browser/ui/profile_error_dialog.h"
92 #include "chrome/browser/ui/simple_message_box.h"
91 #include "chrome/browser/ui/startup/bad_flags_prompt.h" 93 #include "chrome/browser/ui/startup/bad_flags_prompt.h"
92 #include "chrome/browser/ui/startup/default_browser_prompt.h" 94 #include "chrome/browser/ui/startup/default_browser_prompt.h"
93 #include "chrome/browser/ui/startup/startup_browser_creator.h" 95 #include "chrome/browser/ui/startup/startup_browser_creator.h"
94 #include "chrome/browser/ui/uma_browsing_activity_observer.h" 96 #include "chrome/browser/ui/uma_browsing_activity_observer.h"
95 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 97 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
96 #include "chrome/common/channel_info.h" 98 #include "chrome/common/channel_info.h"
97 #include "chrome/common/chrome_constants.h" 99 #include "chrome/common/chrome_constants.h"
98 #include "chrome/common/chrome_features.h" 100 #include "chrome/common/chrome_features.h"
99 #include "chrome/common/chrome_paths.h" 101 #include "chrome/common/chrome_paths.h"
100 #include "chrome/common/chrome_result_codes.h" 102 #include "chrome/common/chrome_result_codes.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 profiles::SetLastUsedProfile( 386 profiles::SetLastUsedProfile(
385 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); 387 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory));
386 // Clear kProfilesLastActive since the user only wants to launch a specific 388 // Clear kProfilesLastActive since the user only wants to launch a specific
387 // profile. 389 // profile.
388 ListPrefUpdate update(g_browser_process->local_state(), 390 ListPrefUpdate update(g_browser_process->local_state(),
389 prefs::kProfilesLastActive); 391 prefs::kProfilesLastActive);
390 base::ListValue* profile_list = update.Get(); 392 base::ListValue* profile_list = update.Get();
391 profile_list->Clear(); 393 profile_list->Clear();
392 } 394 }
393 395
394 Profile* profile = NULL; 396 Profile* profile = nullptr;
395 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 397 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
396 // On ChromeOS and Android the ProfileManager will use the same path as the 398 // On ChromeOS and Android the ProfileManager will use the same path as the
397 // one we got passed. GetActiveUserProfile will therefore use the correct path 399 // one we got passed. GetActiveUserProfile will therefore use the correct path
398 // automatically. 400 // automatically.
399 DCHECK_EQ(user_data_dir.value(), 401 DCHECK_EQ(user_data_dir.value(),
400 g_browser_process->profile_manager()->user_data_dir().value()); 402 g_browser_process->profile_manager()->user_data_dir().value());
401 profile = ProfileManager::GetActiveUserProfile(); 403 profile = ProfileManager::GetActiveUserProfile();
402 #else 404 #else
403 base::FilePath profile_path = 405 profile = GetStartupProfile(user_data_dir, parsed_command_line);
404 GetStartupProfilePath(user_data_dir, parsed_command_line);
405 406
406 profile = g_browser_process->profile_manager()->GetProfile( 407 bool profile_dir_specified =
407 profile_path); 408 profiles::IsMultipleProfilesEnabled() &&
409 parsed_command_line.HasSwitch(switches::kProfileDirectory);
408 410
409 // If we're using the --new-profile-management flag and this profile is 411 if (!profile && !profile_dir_specified)
410 // signed out, then we should show the user manager instead. By switching 412 profile = GetFallbackStartupProfile();
411 // the active profile to the guest profile we ensure that no 413
412 // browser windows will be opened for the guest profile. 414 if (!profile) {
413 if (switches::IsNewProfileManagement() && 415 ProfileErrorType error_type = profile_dir_specified ?
414 profile && 416 PROFILE_ERROR_CREATE_FAILURE_SPECIFIED :
415 !profile->IsGuestSession()) { 417 PROFILE_ERROR_CREATE_FAILURE_ALL;
416 ProfileAttributesEntry* entry; 418
417 bool has_entry = g_browser_process->profile_manager()-> 419 ShowProfileErrorDialog(error_type, IDS_COULDNT_STARTUP_PROFILE_ERROR);
418 GetProfileAttributesStorage(). 420 return nullptr;
419 GetProfileAttributesWithPath(profile_path, &entry);
420 if (has_entry && entry->IsSigninRequired()) {
421 profile = g_browser_process->profile_manager()->GetProfile(
422 ProfileManager::GetGuestProfilePath());
423 }
424 } 421 }
425 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) 422 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID)
426 if (profile) { 423 if (profile) {
427 UMA_HISTOGRAM_LONG_TIMES( 424 UMA_HISTOGRAM_LONG_TIMES(
428 "Startup.CreateFirstProfile", base::Time::Now() - start); 425 "Startup.CreateFirstProfile", base::Time::Now() - start);
429 return profile; 426 return profile;
430 } 427 }
431 428
432 #if !defined(OS_WIN)
433 // TODO(port): fix this. See comments near the definition of 429 // TODO(port): fix this. See comments near the definition of
434 // user_data_dir. It is better to CHECK-fail here than it is to 430 // user_data_dir. It is better to CHECK-fail here than it is to
435 // silently exit because of missing code in the above test. 431 // silently exit because of missing code in the above test.
436 CHECK(profile) << "Cannot get default profile."; 432 CHECK(profile) << "Cannot get default profile.";
Peter Kasting 2016/06/16 06:37:49 This block should be moved up into the #if defined
WC Leung 2016/06/19 17:56:19 Done.
437 #endif // !defined(OS_WIN)
438 433
439 return NULL; 434 return nullptr;
440 } 435 }
441 436
442 #if defined(OS_MACOSX) 437 #if defined(OS_MACOSX)
443 OSStatus KeychainCallback(SecKeychainEvent keychain_event, 438 OSStatus KeychainCallback(SecKeychainEvent keychain_event,
444 SecKeychainCallbackInfo* info, void* context) { 439 SecKeychainCallbackInfo* info, void* context) {
445 return noErr; 440 return noErr;
446 } 441 }
447 #endif // defined(OS_MACOSX) 442 #endif // defined(OS_MACOSX)
448 443
449 void RegisterComponentsForUpdate() { 444 void RegisterComponentsForUpdate() {
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 chromeos::CrosSettings::Shutdown(); 1978 chromeos::CrosSettings::Shutdown();
1984 #endif // defined(OS_CHROMEOS) 1979 #endif // defined(OS_CHROMEOS)
1985 #endif // defined(OS_ANDROID) 1980 #endif // defined(OS_ANDROID)
1986 } 1981 }
1987 1982
1988 // Public members: 1983 // Public members:
1989 1984
1990 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 1985 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1991 chrome_extra_parts_.push_back(parts); 1986 chrome_extra_parts_.push_back(parts);
1992 } 1987 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698