Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 #include "chrome/browser/profiles/profile_attributes_storage.h" | 83 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 84 #include "chrome/browser/profiles/profile_manager.h" | 84 #include "chrome/browser/profiles/profile_manager.h" |
| 85 #include "chrome/browser/profiles/profiles_state.h" | 85 #include "chrome/browser/profiles/profiles_state.h" |
| 86 #include "chrome/browser/shell_integration.h" | 86 #include "chrome/browser/shell_integration.h" |
| 87 #include "chrome/browser/tracing/navigation_tracing.h" | 87 #include "chrome/browser/tracing/navigation_tracing.h" |
| 88 #include "chrome/browser/translate/translate_service.h" | 88 #include "chrome/browser/translate/translate_service.h" |
| 89 #include "chrome/browser/ui/app_list/app_list_service.h" | 89 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 90 #include "chrome/browser/ui/app_modal/chrome_javascript_native_dialog_factory.h" | 90 #include "chrome/browser/ui/app_modal/chrome_javascript_native_dialog_factory.h" |
| 91 #include "chrome/browser/ui/browser.h" | 91 #include "chrome/browser/ui/browser.h" |
| 92 #include "chrome/browser/ui/browser_finder.h" | 92 #include "chrome/browser/ui/browser_finder.h" |
| 93 #include "chrome/browser/ui/profile_error_dialog.h" | |
| 94 #include "chrome/browser/ui/simple_message_box.h" | |
| 93 #include "chrome/browser/ui/startup/bad_flags_prompt.h" | 95 #include "chrome/browser/ui/startup/bad_flags_prompt.h" |
| 94 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 96 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 95 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 97 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 96 #include "chrome/browser/ui/uma_browsing_activity_observer.h" | 98 #include "chrome/browser/ui/uma_browsing_activity_observer.h" |
| 97 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 99 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 98 #include "chrome/common/channel_info.h" | 100 #include "chrome/common/channel_info.h" |
| 99 #include "chrome/common/chrome_constants.h" | 101 #include "chrome/common/chrome_constants.h" |
| 100 #include "chrome/common/chrome_features.h" | 102 #include "chrome/common/chrome_features.h" |
| 101 #include "chrome/common/chrome_paths.h" | 103 #include "chrome/common/chrome_paths.h" |
| 102 #include "chrome/common/chrome_result_codes.h" | 104 #include "chrome/common/chrome_result_codes.h" |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 profiles::SetLastUsedProfile( | 384 profiles::SetLastUsedProfile( |
| 383 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); | 385 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); |
| 384 // Clear kProfilesLastActive since the user only wants to launch a specific | 386 // Clear kProfilesLastActive since the user only wants to launch a specific |
| 385 // profile. | 387 // profile. |
| 386 ListPrefUpdate update(g_browser_process->local_state(), | 388 ListPrefUpdate update(g_browser_process->local_state(), |
| 387 prefs::kProfilesLastActive); | 389 prefs::kProfilesLastActive); |
| 388 base::ListValue* profile_list = update.Get(); | 390 base::ListValue* profile_list = update.Get(); |
| 389 profile_list->Clear(); | 391 profile_list->Clear(); |
| 390 } | 392 } |
| 391 | 393 |
| 392 Profile* profile = NULL; | 394 Profile* profile = nullptr; |
| 393 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 395 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 394 // On ChromeOS and Android the ProfileManager will use the same path as the | 396 // On ChromeOS and Android the ProfileManager will use the same path as the |
| 395 // one we got passed. GetActiveUserProfile will therefore use the correct path | 397 // one we got passed. GetActiveUserProfile will therefore use the correct path |
| 396 // automatically. | 398 // automatically. |
| 397 DCHECK_EQ(user_data_dir.value(), | 399 DCHECK_EQ(user_data_dir.value(), |
| 398 g_browser_process->profile_manager()->user_data_dir().value()); | 400 g_browser_process->profile_manager()->user_data_dir().value()); |
| 399 profile = ProfileManager::GetActiveUserProfile(); | 401 profile = ProfileManager::GetActiveUserProfile(); |
| 400 #else | 402 #else |
| 401 base::FilePath profile_path = | 403 base::FilePath profile_path = |
| 402 GetStartupProfilePath(user_data_dir, parsed_command_line); | 404 GetStartupProfilePath(user_data_dir, parsed_command_line); |
| 403 | 405 |
| 404 profile = g_browser_process->profile_manager()->GetProfile( | 406 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 405 profile_path); | 407 profile = profile_manager->GetProfile(profile_path); |
| 406 | 408 |
| 407 // If we're using the --new-profile-management flag and this profile is | 409 // If we're using the --new-profile-management flag and this profile is signed |
| 408 // signed out, then we should show the user manager instead. By switching | 410 // out, then we should show the user manager instead. By switching the active |
| 409 // the active profile to the guest profile we ensure that no | 411 // profile to the guest profile we ensure that no browser windows will be |
| 410 // browser windows will be opened for the guest profile. | 412 // opened for the guest profile. The initialization of guest profile is |
| 413 // possible to fail. | |
| 411 if (switches::IsNewProfileManagement() && | 414 if (switches::IsNewProfileManagement() && |
| 412 profile && | 415 profile && |
| 413 !profile->IsGuestSession()) { | 416 !profile->IsGuestSession()) { |
| 414 ProfileAttributesEntry* entry; | 417 ProfileAttributesEntry* entry; |
| 415 bool has_entry = g_browser_process->profile_manager()-> | 418 bool has_entry = g_browser_process->profile_manager() |
| 416 GetProfileAttributesStorage(). | 419 ->GetProfileAttributesStorage() |
| 417 GetProfileAttributesWithPath(profile_path, &entry); | 420 .GetProfileAttributesWithPath(profile_path, &entry); |
| 418 if (has_entry && entry->IsSigninRequired()) { | 421 if (has_entry && entry->IsSigninRequired()) { |
| 419 profile = g_browser_process->profile_manager()->GetProfile( | 422 profile = profile_manager->GetProfile( |
| 420 ProfileManager::GetGuestProfilePath()); | 423 ProfileManager::GetGuestProfilePath()); |
| 421 } | 424 } |
| 422 } | 425 } |
| 426 | |
| 427 // If the user specified a profile and it fails to initialize, do not start | |
| 428 // chromium. | |
| 429 if (profiles::IsMultipleProfilesEnabled() && | |
| 430 parsed_command_line.HasSwitch(switches::kProfileDirectory) && | |
| 431 !profile) { | |
| 432 ShowProfileErrorDialog(PROFILE_ERROR_CREATE_FAILURE_SPECIFIED, | |
| 433 IDS_COULDNT_OPEN_SPECIFIED_PROFILE_ERROR); | |
| 434 return nullptr; | |
| 435 } | |
| 436 | |
| 437 // If the last used profile is unable to initialize, see if any of other last | |
|
brettw
2016/06/14 00:02:07
Can the code added from here be moved to a helper
WC Leung
2016/06/15 17:44:08
SGTM. Agree that the current function is too long,
| |
| 438 // opened profiles can initialize successfully. At this stage we assume | |
| 439 // creation of all new profile (including guest profile) to fail. | |
| 440 if (!profile) { | |
| 441 std::vector<Profile*> last_opened_profiles = | |
| 442 ProfileManager::GetLastOpenedProfiles(); | |
| 443 // Get the first profile that is not signed out.. | |
|
brettw
2016/06/14 00:02:07
nit: remove extra "."
WC Leung
2016/06/15 17:44:08
Oops. Thanks for catching. Done.
| |
| 444 if (last_opened_profiles.size()) { | |
| 445 for (Profile* last_opened_profile : last_opened_profiles) { | |
| 446 ProfileAttributesEntry* entry; | |
| 447 bool has_entry = | |
| 448 g_browser_process->profile_manager() | |
| 449 ->GetProfileAttributesStorage() | |
| 450 .GetProfileAttributesWithPath(profile->GetPath(), | |
|
WC Leung
2016/06/15 17:44:08
profile should be last_opened_profile instead. Oop
| |
| 451 &entry); | |
| 452 if (!has_entry || !entry->IsSigninRequired()) { | |
| 453 profile = last_opened_profile; | |
| 454 break; | |
| 455 } | |
| 456 } | |
| 457 } | |
| 458 } | |
| 459 | |
| 460 // If it still fails, try to create a guest profile. Show the user manager | |
| 461 // if this is successful. | |
| 462 if (!profile) { | |
| 463 profile = profile_manager->GetProfile( | |
| 464 ProfileManager::GetGuestProfilePath()); | |
| 465 } | |
| 466 | |
| 467 // If still fails, try to open any non-signin profile. | |
| 468 if (!profile) { | |
| 469 std::vector<ProfileAttributesEntry*> entries = | |
| 470 profile_manager->GetProfileAttributesStorage() | |
| 471 .GetAllProfilesAttributes(); | |
| 472 for (ProfileAttributesEntry* entry : entries) { | |
| 473 if (!entry->IsSigninRequired()) { | |
| 474 profile = profile_manager->GetProfile(entry->GetPath()); | |
| 475 if (profile) | |
| 476 break; | |
| 477 } | |
| 478 } | |
| 479 } | |
| 480 | |
| 481 // If it continues to fail, we have to show an error message and give up. | |
| 482 if (!profile) { | |
| 483 ShowProfileErrorDialog(PROFILE_ERROR_CREATE_FAILURE_ALL, | |
| 484 IDS_COULDNT_OPEN_ANY_PROFILE_ERROR); | |
| 485 return nullptr; | |
| 486 } | |
| 423 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 487 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 424 if (profile) { | 488 if (profile) { |
| 425 UMA_HISTOGRAM_LONG_TIMES( | 489 UMA_HISTOGRAM_LONG_TIMES( |
| 426 "Startup.CreateFirstProfile", base::Time::Now() - start); | 490 "Startup.CreateFirstProfile", base::Time::Now() - start); |
| 427 return profile; | 491 return profile; |
| 428 } | 492 } |
| 429 | 493 |
| 430 #if !defined(OS_WIN) | |
| 431 // TODO(port): fix this. See comments near the definition of | 494 // TODO(port): fix this. See comments near the definition of |
| 432 // user_data_dir. It is better to CHECK-fail here than it is to | 495 // user_data_dir. It is better to CHECK-fail here than it is to |
| 433 // silently exit because of missing code in the above test. | 496 // silently exit because of missing code in the above test. |
| 434 CHECK(profile) << "Cannot get default profile."; | 497 CHECK(profile) << "Cannot get default profile."; |
| 435 #endif // !defined(OS_WIN) | |
| 436 | 498 |
| 437 return NULL; | 499 return nullptr; |
| 438 } | 500 } |
| 439 | 501 |
| 440 #if defined(OS_MACOSX) | 502 #if defined(OS_MACOSX) |
| 441 OSStatus KeychainCallback(SecKeychainEvent keychain_event, | 503 OSStatus KeychainCallback(SecKeychainEvent keychain_event, |
| 442 SecKeychainCallbackInfo* info, void* context) { | 504 SecKeychainCallbackInfo* info, void* context) { |
| 443 return noErr; | 505 return noErr; |
| 444 } | 506 } |
| 445 #endif // defined(OS_MACOSX) | 507 #endif // defined(OS_MACOSX) |
| 446 | 508 |
| 447 void RegisterComponentsForUpdate() { | 509 void RegisterComponentsForUpdate() { |
| (...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1993 chromeos::CrosSettings::Shutdown(); | 2055 chromeos::CrosSettings::Shutdown(); |
| 1994 #endif // defined(OS_CHROMEOS) | 2056 #endif // defined(OS_CHROMEOS) |
| 1995 #endif // defined(OS_ANDROID) | 2057 #endif // defined(OS_ANDROID) |
| 1996 } | 2058 } |
| 1997 | 2059 |
| 1998 // Public members: | 2060 // Public members: |
| 1999 | 2061 |
| 2000 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2062 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 2001 chrome_extra_parts_.push_back(parts); | 2063 chrome_extra_parts_.push_back(parts); |
| 2002 } | 2064 } |
| OLD | NEW |