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/simple_message_box.h" | |
93 #include "chrome/browser/ui/startup/bad_flags_prompt.h" | 94 #include "chrome/browser/ui/startup/bad_flags_prompt.h" |
94 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 95 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
95 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 96 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
96 #include "chrome/browser/ui/uma_browsing_activity_observer.h" | 97 #include "chrome/browser/ui/uma_browsing_activity_observer.h" |
97 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 98 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
98 #include "chrome/common/channel_info.h" | 99 #include "chrome/common/channel_info.h" |
99 #include "chrome/common/chrome_constants.h" | 100 #include "chrome/common/chrome_constants.h" |
100 #include "chrome/common/chrome_features.h" | 101 #include "chrome/common/chrome_features.h" |
101 #include "chrome/common/chrome_paths.h" | 102 #include "chrome/common/chrome_paths.h" |
102 #include "chrome/common/chrome_result_codes.h" | 103 #include "chrome/common/chrome_result_codes.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 profiles::SetLastUsedProfile( | 383 profiles::SetLastUsedProfile( |
383 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); | 384 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); |
384 // Clear kProfilesLastActive since the user only wants to launch a specific | 385 // Clear kProfilesLastActive since the user only wants to launch a specific |
385 // profile. | 386 // profile. |
386 ListPrefUpdate update(g_browser_process->local_state(), | 387 ListPrefUpdate update(g_browser_process->local_state(), |
387 prefs::kProfilesLastActive); | 388 prefs::kProfilesLastActive); |
388 base::ListValue* profile_list = update.Get(); | 389 base::ListValue* profile_list = update.Get(); |
389 profile_list->Clear(); | 390 profile_list->Clear(); |
390 } | 391 } |
391 | 392 |
392 Profile* profile = NULL; | 393 Profile* profile = nullptr; |
393 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 394 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
394 // On ChromeOS and Android the ProfileManager will use the same path as the | 395 // 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 | 396 // one we got passed. GetActiveUserProfile will therefore use the correct path |
396 // automatically. | 397 // automatically. |
397 DCHECK_EQ(user_data_dir.value(), | 398 DCHECK_EQ(user_data_dir.value(), |
398 g_browser_process->profile_manager()->user_data_dir().value()); | 399 g_browser_process->profile_manager()->user_data_dir().value()); |
399 profile = ProfileManager::GetActiveUserProfile(); | 400 profile = ProfileManager::GetActiveUserProfile(); |
400 #else | 401 #else |
401 base::FilePath profile_path = | 402 base::FilePath profile_path = |
402 GetStartupProfilePath(user_data_dir, parsed_command_line); | 403 GetStartupProfilePath(user_data_dir, parsed_command_line); |
403 | 404 |
404 profile = g_browser_process->profile_manager()->GetProfile( | 405 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
405 profile_path); | 406 profile = profile_manager->GetProfile(profile_path); |
406 | 407 |
407 // If we're using the --new-profile-management flag and this profile is | 408 // 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 | 409 // 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 | 410 // profile to the guest profile we ensure that no browser windows will be |
410 // browser windows will be opened for the guest profile. | 411 // opened for the guest profile. The initialization of guest profile is |
412 // possible to fail. | |
411 if (switches::IsNewProfileManagement() && | 413 if (switches::IsNewProfileManagement() && |
412 profile && | 414 profile && |
413 !profile->IsGuestSession()) { | 415 !profile->IsGuestSession()) { |
414 ProfileAttributesEntry* entry; | 416 ProfileAttributesEntry* entry; |
415 bool has_entry = g_browser_process->profile_manager()-> | 417 bool has_entry = g_browser_process->profile_manager() |
416 GetProfileAttributesStorage(). | 418 ->GetProfileAttributesStorage() |
417 GetProfileAttributesWithPath(profile_path, &entry); | 419 .GetProfileAttributesWithPath(profile_path, &entry); |
418 if (has_entry && entry->IsSigninRequired()) { | 420 if (has_entry && entry->IsSigninRequired()) { |
419 profile = g_browser_process->profile_manager()->GetProfile( | 421 profile = profile_manager->GetProfile( |
420 ProfileManager::GetGuestProfilePath()); | 422 ProfileManager::GetGuestProfilePath()); |
421 } | 423 } |
422 } | 424 } |
425 | |
426 // If the user specified a profile and it fails to initialize, do not start | |
427 // chromium. | |
428 if (profiles::IsMultipleProfilesEnabled() && | |
429 parsed_command_line.HasSwitch(switches::kProfileDirectory) && | |
430 !profile) { | |
431 chrome::ShowWarningMessageBox(NULL, | |
432 base::UTF8ToUTF16("Unable to start chrome"), | |
433 base::UTF8ToUTF16("Cannot open or create the specified profile.")); | |
434 return nullptr; | |
WC Leung
2016/06/06 20:01:36
We need to get help from the UI team to determine
| |
435 } | |
436 | |
437 // If the last used profile is unable to initialize, see if any of other last | |
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.. | |
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(), | |
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 chrome::ShowWarningMessageBox(NULL, | |
484 base::UTF8ToUTF16("Unable to start chrome"), | |
485 base::UTF8ToUTF16( | |
486 "Cannot load or create any profile in the user data directory.\n" | |
487 "The user data directory is possibly corrupted.")); | |
WC Leung
2016/06/06 20:01:36
Same for here. Anyway, should we also add some UMA
| |
488 return nullptr; | |
489 } | |
423 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 490 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) |
424 if (profile) { | 491 if (profile) { |
425 UMA_HISTOGRAM_LONG_TIMES( | 492 UMA_HISTOGRAM_LONG_TIMES( |
426 "Startup.CreateFirstProfile", base::Time::Now() - start); | 493 "Startup.CreateFirstProfile", base::Time::Now() - start); |
427 return profile; | 494 return profile; |
428 } | 495 } |
429 | 496 |
430 #if !defined(OS_WIN) | |
431 // TODO(port): fix this. See comments near the definition of | 497 // 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 | 498 // 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. | 499 // silently exit because of missing code in the above test. |
434 CHECK(profile) << "Cannot get default profile."; | 500 CHECK(profile) << "Cannot get default profile."; |
435 #endif // !defined(OS_WIN) | |
436 | 501 |
437 return NULL; | 502 return nullptr; |
438 } | 503 } |
439 | 504 |
440 #if defined(OS_MACOSX) | 505 #if defined(OS_MACOSX) |
441 OSStatus KeychainCallback(SecKeychainEvent keychain_event, | 506 OSStatus KeychainCallback(SecKeychainEvent keychain_event, |
442 SecKeychainCallbackInfo* info, void* context) { | 507 SecKeychainCallbackInfo* info, void* context) { |
443 return noErr; | 508 return noErr; |
444 } | 509 } |
445 #endif // defined(OS_MACOSX) | 510 #endif // defined(OS_MACOSX) |
446 | 511 |
447 void RegisterComponentsForUpdate() { | 512 void RegisterComponentsForUpdate() { |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1993 chromeos::CrosSettings::Shutdown(); | 2058 chromeos::CrosSettings::Shutdown(); |
1994 #endif // defined(OS_CHROMEOS) | 2059 #endif // defined(OS_CHROMEOS) |
1995 #endif // defined(OS_ANDROID) | 2060 #endif // defined(OS_ANDROID) |
1996 } | 2061 } |
1997 | 2062 |
1998 // Public members: | 2063 // Public members: |
1999 | 2064 |
2000 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2065 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
2001 chrome_extra_parts_.push_back(parts); | 2066 chrome_extra_parts_.push_back(parts); |
2002 } | 2067 } |
OLD | NEW |