| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 #include "chrome/browser/profiles/profile.h" | 69 #include "chrome/browser/profiles/profile.h" |
| 70 #include "chrome/browser/profiles/profile_manager.h" | 70 #include "chrome/browser/profiles/profile_manager.h" |
| 71 #include "chrome/browser/search_engines/search_engine_type.h" | 71 #include "chrome/browser/search_engines/search_engine_type.h" |
| 72 #include "chrome/browser/search_engines/template_url.h" | 72 #include "chrome/browser/search_engines/template_url.h" |
| 73 #include "chrome/browser/search_engines/template_url_service.h" | 73 #include "chrome/browser/search_engines/template_url_service.h" |
| 74 #include "chrome/browser/search_engines/template_url_service_factory.h" | 74 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 75 #include "chrome/browser/service/service_process_control.h" | 75 #include "chrome/browser/service/service_process_control.h" |
| 76 #include "chrome/browser/shell_integration.h" | 76 #include "chrome/browser/shell_integration.h" |
| 77 #include "chrome/browser/translate/translate_manager.h" | 77 #include "chrome/browser/translate/translate_manager.h" |
| 78 #include "chrome/browser/ui/browser.h" | 78 #include "chrome/browser/ui/browser.h" |
| 79 #include "chrome/browser/ui/browser_init.h" |
| 79 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 80 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
| 80 #include "chrome/browser/web_resource/gpu_blacklist_updater.h" | 81 #include "chrome/browser/web_resource/gpu_blacklist_updater.h" |
| 81 #include "chrome/common/child_process_logging.h" | 82 #include "chrome/common/child_process_logging.h" |
| 82 #include "chrome/common/chrome_constants.h" | 83 #include "chrome/common/chrome_constants.h" |
| 83 #include "chrome/common/chrome_paths.h" | 84 #include "chrome/common/chrome_paths.h" |
| 84 #include "chrome/common/chrome_result_codes.h" | 85 #include "chrome/common/chrome_result_codes.h" |
| 85 #include "chrome/common/chrome_switches.h" | 86 #include "chrome/common/chrome_switches.h" |
| 86 #include "chrome/common/chrome_version_info.h" | 87 #include "chrome/common/chrome_version_info.h" |
| 87 #include "chrome/common/env_vars.h" | 88 #include "chrome/common/env_vars.h" |
| 88 #include "chrome/common/json_pref_store.h" | 89 #include "chrome/common/json_pref_store.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 119 #if defined(USE_LINUX_BREAKPAD) | 120 #if defined(USE_LINUX_BREAKPAD) |
| 120 #include "base/linux_util.h" | 121 #include "base/linux_util.h" |
| 121 #include "chrome/app/breakpad_linux.h" | 122 #include "chrome/app/breakpad_linux.h" |
| 122 #endif | 123 #endif |
| 123 | 124 |
| 124 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 125 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 125 #include "chrome/browser/first_run/upgrade_util_linux.h" | 126 #include "chrome/browser/first_run/upgrade_util_linux.h" |
| 126 #endif | 127 #endif |
| 127 | 128 |
| 128 #if defined(OS_CHROMEOS) | 129 #if defined(OS_CHROMEOS) |
| 129 #include "chrome/browser/chromeos/audio_handler.h" | |
| 130 #include "chrome/browser/chromeos/boot_times_loader.h" | |
| 131 #include "chrome/browser/chromeos/cros/cros_library.h" | 130 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 132 #include "chrome/browser/chromeos/cros_settings.h" | 131 #include "chrome/browser/chromeos/cros_settings.h" |
| 133 #include "chrome/browser/chromeos/cros_settings_names.h" | 132 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 134 #include "chrome/browser/chromeos/customization_document.h" | |
| 135 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | |
| 136 #include "chrome/browser/chromeos/external_metrics.h" | |
| 137 #include "chrome/browser/chromeos/login/authenticator.h" | |
| 138 #include "chrome/browser/chromeos/login/login_utils.h" | |
| 139 #include "chrome/browser/chromeos/login/ownership_service.h" | |
| 140 #include "chrome/browser/chromeos/login/screen_locker.h" | |
| 141 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 142 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | |
| 143 #include "chrome/browser/chromeos/system/runtime_environment.h" | |
| 144 #include "chrome/browser/chromeos/system_key_event_listener.h" | |
| 145 #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" | |
| 146 #include "chrome/browser/oom_priority_manager.h" | |
| 147 #include "chrome/browser/ui/views/browser_dialogs.h" | |
| 148 #endif | 133 #endif |
| 149 | 134 |
| 150 // TODO(port): several win-only methods have been pulled out of this, but | 135 // TODO(port): several win-only methods have been pulled out of this, but |
| 151 // BrowserMain() as a whole needs to be broken apart so that it's usable by | 136 // BrowserMain() as a whole needs to be broken apart so that it's usable by |
| 152 // other platforms. For now, it's just a stub. This is a serious work in | 137 // other platforms. For now, it's just a stub. This is a serious work in |
| 153 // progress and should not be taken as an indication of a real refactoring. | 138 // progress and should not be taken as an indication of a real refactoring. |
| 154 | 139 |
| 155 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
| 156 #include "base/environment.h" // For PreRead experiment. | 141 #include "base/environment.h" // For PreRead experiment. |
| 157 #include "base/win/windows_version.h" | 142 #include "base/win/windows_version.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 #else | 423 #else |
| 439 // TODO(port): fix this. See comments near the definition of | 424 // TODO(port): fix this. See comments near the definition of |
| 440 // user_data_dir. It is better to CHECK-fail here than it is to | 425 // user_data_dir. It is better to CHECK-fail here than it is to |
| 441 // silently exit because of missing code in the above test. | 426 // silently exit because of missing code in the above test. |
| 442 CHECK(profile) << "Cannot get default profile."; | 427 CHECK(profile) << "Cannot get default profile."; |
| 443 #endif | 428 #endif |
| 444 | 429 |
| 445 return NULL; | 430 return NULL; |
| 446 } | 431 } |
| 447 | 432 |
| 448 #if defined(OS_CHROMEOS) | |
| 449 | |
| 450 // Class is used to login using passed username and password. | |
| 451 // The instance will be deleted upon success or failure. | |
| 452 class StubLogin : public chromeos::LoginStatusConsumer, | |
| 453 public chromeos::LoginUtils::Delegate { | |
| 454 public: | |
| 455 StubLogin(std::string username, std::string password) | |
| 456 : pending_requests_(false), | |
| 457 profile_prepared_(false) { | |
| 458 authenticator_ = chromeos::LoginUtils::Get()->CreateAuthenticator(this); | |
| 459 authenticator_.get()->AuthenticateToLogin( | |
| 460 g_browser_process->profile_manager()->GetDefaultProfile(), | |
| 461 username, | |
| 462 password, | |
| 463 std::string(), | |
| 464 std::string()); | |
| 465 } | |
| 466 | |
| 467 ~StubLogin() { | |
| 468 chromeos::LoginUtils::Get()->DelegateDeleted(this); | |
| 469 } | |
| 470 | |
| 471 void OnLoginFailure(const chromeos::LoginFailure& error) { | |
| 472 LOG(ERROR) << "Login Failure: " << error.GetErrorString(); | |
| 473 delete this; | |
| 474 } | |
| 475 | |
| 476 void OnLoginSuccess(const std::string& username, | |
| 477 const std::string& password, | |
| 478 const GaiaAuthConsumer::ClientLoginResult& credentials, | |
| 479 bool pending_requests, | |
| 480 bool using_oauth) { | |
| 481 pending_requests_ = pending_requests; | |
| 482 if (!profile_prepared_) { | |
| 483 // Will call OnProfilePrepared in the end. | |
| 484 chromeos::LoginUtils::Get()->PrepareProfile(username, | |
| 485 password, | |
| 486 credentials, | |
| 487 pending_requests, | |
| 488 using_oauth, | |
| 489 false, | |
| 490 this); | |
| 491 } else if (!pending_requests) { | |
| 492 delete this; | |
| 493 } | |
| 494 } | |
| 495 | |
| 496 // LoginUtils::Delegate implementation: | |
| 497 virtual void OnProfilePrepared(Profile* profile) { | |
| 498 profile_prepared_ = true; | |
| 499 chromeos::LoginUtils::DoBrowserLaunch(profile, NULL); | |
| 500 if (!pending_requests_) | |
| 501 delete this; | |
| 502 } | |
| 503 | |
| 504 scoped_refptr<chromeos::Authenticator> authenticator_; | |
| 505 bool pending_requests_; | |
| 506 bool profile_prepared_; | |
| 507 }; | |
| 508 | |
| 509 void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line, | |
| 510 Profile* profile) { | |
| 511 if (parsed_command_line.HasSwitch(switches::kLoginManager)) { | |
| 512 std::string first_screen = | |
| 513 parsed_command_line.GetSwitchValueASCII(switches::kLoginScreen); | |
| 514 std::string size_arg = | |
| 515 parsed_command_line.GetSwitchValueASCII( | |
| 516 switches::kLoginScreenSize); | |
| 517 gfx::Size size(0, 0); | |
| 518 // Allow the size of the login window to be set explicitly. If not set, | |
| 519 // default to the entire screen. This is mostly useful for testing. | |
| 520 if (size_arg.size()) { | |
| 521 std::vector<std::string> dimensions; | |
| 522 base::SplitString(size_arg, ',', &dimensions); | |
| 523 if (dimensions.size() == 2) { | |
| 524 int width, height; | |
| 525 if (base::StringToInt(dimensions[0], &width) && | |
| 526 base::StringToInt(dimensions[1], &height)) | |
| 527 size.SetSize(width, height); | |
| 528 } | |
| 529 } | |
| 530 browser::ShowLoginWizard(first_screen, size); | |
| 531 } else if (parsed_command_line.HasSwitch(switches::kLoginUser) && | |
| 532 parsed_command_line.HasSwitch(switches::kLoginPassword)) { | |
| 533 chromeos::BootTimesLoader::Get()->RecordLoginAttempted(); | |
| 534 new StubLogin( | |
| 535 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser), | |
| 536 parsed_command_line.GetSwitchValueASCII(switches::kLoginPassword)); | |
| 537 } else { | |
| 538 if (!parsed_command_line.HasSwitch(switches::kTestName)) { | |
| 539 // We did not log in (we crashed or are debugging), so we need to | |
| 540 // set the user name for sync. | |
| 541 chromeos::LoginUtils::Get()->RestoreAuthenticationSession( | |
| 542 chromeos::UserManager::Get()->logged_in_user().email(), profile); | |
| 543 } | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 #endif // defined(OS_CHROMEOS) | |
| 548 | |
| 549 #if defined(OS_MACOSX) | 433 #if defined(OS_MACOSX) |
| 550 OSStatus KeychainCallback(SecKeychainEvent keychain_event, | 434 OSStatus KeychainCallback(SecKeychainEvent keychain_event, |
| 551 SecKeychainCallbackInfo *info, void *context) { | 435 SecKeychainCallbackInfo *info, void *context) { |
| 552 return noErr; | 436 return noErr; |
| 553 } | 437 } |
| 554 #endif | 438 #endif |
| 555 | 439 |
| 556 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) | 440 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) |
| 557 void RegisterTranslateableItems(void) { | 441 void RegisterTranslateableItems(void) { |
| 558 struct { | 442 struct { |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 SpdyFieldTrial(); | 1013 SpdyFieldTrial(); |
| 1130 ConnectBackupJobsFieldTrial(); | 1014 ConnectBackupJobsFieldTrial(); |
| 1131 WarmConnectionFieldTrial(); | 1015 WarmConnectionFieldTrial(); |
| 1132 PredictorFieldTrial(); | 1016 PredictorFieldTrial(); |
| 1133 DefaultAppsFieldTrial(); | 1017 DefaultAppsFieldTrial(); |
| 1134 } | 1018 } |
| 1135 | 1019 |
| 1136 // ----------------------------------------------------------------------------- | 1020 // ----------------------------------------------------------------------------- |
| 1137 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. | 1021 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. |
| 1138 | 1022 |
| 1139 #if defined(OS_CHROMEOS) | |
| 1140 // Allows authenticator to be invoked without adding refcounting. The instances | |
| 1141 // will delete themselves upon completion. | |
| 1142 DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin); | |
| 1143 #endif | |
| 1144 | |
| 1145 #if defined(OS_WIN) | 1023 #if defined(OS_WIN) |
| 1146 #define DLLEXPORT __declspec(dllexport) | 1024 #define DLLEXPORT __declspec(dllexport) |
| 1147 | 1025 |
| 1148 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. | 1026 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. |
| 1149 extern "C" { | 1027 extern "C" { |
| 1150 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 1028 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 1151 } | 1029 } |
| 1152 | 1030 |
| 1153 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { | 1031 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
| 1154 // Need an instance of AtExitManager to handle singleton creations and | 1032 // Need an instance of AtExitManager to handle singleton creations and |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 } | 1294 } |
| 1417 } | 1295 } |
| 1418 | 1296 |
| 1419 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1297 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
| 1420 result_code_ = PreMainMessageLoopRunImpl(); | 1298 result_code_ = PreMainMessageLoopRunImpl(); |
| 1421 | 1299 |
| 1422 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1300 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1423 chrome_extra_parts_[i]->PreMainMessageLoopRun(); | 1301 chrome_extra_parts_[i]->PreMainMessageLoopRun(); |
| 1424 } | 1302 } |
| 1425 | 1303 |
| 1304 // PreMainMessageLoopRun calls these extra stages in the following order: |
| 1305 // PreMainMessageLoopRunImpl() |
| 1306 // ... initial setup, including browser_process_ setup. |
| 1307 // PreProfileInit() |
| 1308 // ... additional setup, including CreateProfile() |
| 1309 // PostProfileInit() |
| 1310 // ... additional setup |
| 1311 // PreBrowserStart() |
| 1312 // ... browser_init_->Start (OR parameters().ui_task->Run()) |
| 1313 // PostBrowserStart() |
| 1314 |
| 1315 void ChromeBrowserMainParts::PreProfileInit() { |
| 1316 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1317 chrome_extra_parts_[i]->PreProfileInit(); |
| 1318 } |
| 1319 |
| 1320 void ChromeBrowserMainParts::PostProfileInit() { |
| 1321 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1322 chrome_extra_parts_[i]->PostProfileInit(); |
| 1323 } |
| 1324 |
| 1325 void ChromeBrowserMainParts::PreBrowserStart() { |
| 1326 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1327 chrome_extra_parts_[i]->PreBrowserStart(); |
| 1328 } |
| 1329 |
| 1330 void ChromeBrowserMainParts::PostBrowserStart() { |
| 1331 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1332 chrome_extra_parts_[i]->PostBrowserStart(); |
| 1333 } |
| 1334 |
| 1426 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1335 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
| 1427 // Create watchdog thread after creating all other threads because it will | 1336 // Create watchdog thread after creating all other threads because it will |
| 1428 // watch the other threads and they must be running. | 1337 // watch the other threads and they must be running. |
| 1429 browser_process_->watchdog_thread(); | 1338 browser_process_->watchdog_thread(); |
| 1430 | 1339 |
| 1431 #if defined(USE_WEBKIT_COMPOSITOR) | 1340 #if defined(USE_WEBKIT_COMPOSITOR) |
| 1432 // We need to ensure WebKit has been initialized before we start the WebKit | 1341 // We need to ensure WebKit has been initialized before we start the WebKit |
| 1433 // compositor. This is done by the ResourceDispatcherHost on creation. | 1342 // compositor. This is done by the ResourceDispatcherHost on creation. |
| 1434 browser_process_->resource_dispatcher_host(); | 1343 browser_process_->resource_dispatcher_host(); |
| 1435 #endif | 1344 #endif |
| 1436 | 1345 |
| 1437 #if defined(OS_CHROMEOS) | |
| 1438 // Now that the file thread exists we can record our stats. | |
| 1439 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); | |
| 1440 | |
| 1441 #if defined(TOOLKIT_USES_GTK) | |
| 1442 // Read locale-specific GTK resource information. | |
| 1443 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); | |
| 1444 if (!gtkrc.empty()) | |
| 1445 gtk_rc_parse_string(gtkrc.c_str()); | |
| 1446 #else | |
| 1447 // TODO(saintlou): Need to provide an Aura equivalent. | |
| 1448 NOTIMPLEMENTED(); | |
| 1449 #endif | |
| 1450 | |
| 1451 // Trigger prefetching of ownership status. | |
| 1452 chromeos::OwnershipService::GetSharedInstance()->Prewarm(); | |
| 1453 #endif | |
| 1454 | |
| 1455 // Record last shutdown time into a histogram. | 1346 // Record last shutdown time into a histogram. |
| 1456 browser_shutdown::ReadLastShutdownInfo(); | 1347 browser_shutdown::ReadLastShutdownInfo(); |
| 1457 | 1348 |
| 1458 #if defined(OS_WIN) | 1349 #if defined(OS_WIN) |
| 1459 // On Windows, we use our startup as an opportunity to do upgrade/uninstall | 1350 // On Windows, we use our startup as an opportunity to do upgrade/uninstall |
| 1460 // tasks. Those care whether the browser is already running. On Linux/Mac, | 1351 // tasks. Those care whether the browser is already running. On Linux/Mac, |
| 1461 // upgrade/uninstall happen separately. | 1352 // upgrade/uninstall happen separately. |
| 1462 bool already_running = browser_util::IsBrowserAlreadyRunning(); | 1353 bool already_running = browser_util::IsBrowserAlreadyRunning(); |
| 1463 | 1354 |
| 1464 // If the command line specifies 'uninstall' then we need to work here | 1355 // If the command line specifies 'uninstall' then we need to work here |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 } | 1421 } |
| 1531 #if !defined(OS_MACOSX) // closing brace for if | 1422 #if !defined(OS_MACOSX) // closing brace for if |
| 1532 } | 1423 } |
| 1533 #endif | 1424 #endif |
| 1534 | 1425 |
| 1535 #if defined(USE_X11) | 1426 #if defined(USE_X11) |
| 1536 SetBrowserX11ErrorHandlers(); | 1427 SetBrowserX11ErrorHandlers(); |
| 1537 #endif | 1428 #endif |
| 1538 | 1429 |
| 1539 // Desktop construction occurs here, (required before profile creation). | 1430 // Desktop construction occurs here, (required before profile creation). |
| 1540 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1431 PreProfileInit(); |
| 1541 chrome_extra_parts_[i]->PostBrowserProcessInit(); | |
| 1542 | 1432 |
| 1543 // Profile creation ---------------------------------------------------------- | 1433 // Profile creation ---------------------------------------------------------- |
| 1544 | 1434 |
| 1545 #if defined(OS_CHROMEOS) | |
| 1546 // This forces the ProfileManager to be created and register for the | |
| 1547 // notification it needs to track the logged in user. | |
| 1548 g_browser_process->profile_manager(); | |
| 1549 | |
| 1550 // TODO(abarth): Should this move to InitializeNetworkOptions()? | |
| 1551 // Allow access to file:// on ChromeOS for tests. | |
| 1552 if (parsed_command_line().HasSwitch(switches::kAllowFileAccess)) | |
| 1553 net::URLRequest::AllowFileAccess(); | |
| 1554 | |
| 1555 // There are two use cases for kLoginUser: | |
| 1556 // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin" | |
| 1557 // 2) if passed alone, to signal that the indicated user has already | |
| 1558 // logged in and we should behave accordingly. | |
| 1559 // This handles case 2. | |
| 1560 if (parsed_command_line().HasSwitch(switches::kLoginUser) && | |
| 1561 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { | |
| 1562 std::string username = | |
| 1563 parsed_command_line().GetSwitchValueASCII(switches::kLoginUser); | |
| 1564 VLOG(1) << "Relaunching browser for user: " << username; | |
| 1565 chromeos::UserManager::Get()->UserLoggedIn(username); | |
| 1566 | |
| 1567 // Redirects Chrome logging to the user data dir. | |
| 1568 logging::RedirectChromeLogging(parsed_command_line()); | |
| 1569 | |
| 1570 // Initialize user policy before creating the profile so the profile | |
| 1571 // initialization code sees policy settings. | |
| 1572 g_browser_process->browser_policy_connector()->InitializeUserPolicy( | |
| 1573 username, false /* wait_for_policy_fetch */); | |
| 1574 } else if (parsed_command_line().HasSwitch(switches::kLoginManager)) { | |
| 1575 // Initialize status area mode early on. | |
| 1576 chromeos::StatusAreaViewChromeos:: | |
| 1577 SetScreenMode(chromeos::StatusAreaViewChromeos::LOGIN_MODE_WEBUI); | |
| 1578 } | |
| 1579 #endif | |
| 1580 | |
| 1581 if (is_first_run_) { | 1435 if (is_first_run_) { |
| 1582 // Warn the ProfileManager that an import process will run, possibly | 1436 // Warn the ProfileManager that an import process will run, possibly |
| 1583 // locking the WebDataService directory of the next Profile created. | 1437 // locking the WebDataService directory of the next Profile created. |
| 1584 g_browser_process->profile_manager()->SetWillImport(); | 1438 g_browser_process->profile_manager()->SetWillImport(); |
| 1585 } | 1439 } |
| 1586 | 1440 |
| 1587 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line()); | 1441 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line()); |
| 1588 if (!profile_) | 1442 if (!profile_) |
| 1589 return content::RESULT_CODE_NORMAL_EXIT; | 1443 return content::RESULT_CODE_NORMAL_EXIT; |
| 1590 | 1444 |
| 1591 // Autoload any profiles which are running background apps. | 1445 // Autoload any profiles which are running background apps. |
| 1592 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. | 1446 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. |
| 1593 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled( | 1447 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled( |
| 1594 &parsed_command_line())) { | 1448 &parsed_command_line())) { |
| 1595 g_browser_process->profile_manager()->AutoloadProfiles(); | 1449 g_browser_process->profile_manager()->AutoloadProfiles(); |
| 1596 } | 1450 } |
| 1597 // Post-profile init --------------------------------------------------------- | 1451 // Post-profile init --------------------------------------------------------- |
| 1598 | 1452 |
| 1599 #if defined(OS_CHROMEOS) | |
| 1600 // Pass the TokenService pointer to the policy connector so user policy can | |
| 1601 // grab a token and register with the policy server. | |
| 1602 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. | |
| 1603 if (parsed_command_line().HasSwitch(switches::kLoginUser) && | |
| 1604 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { | |
| 1605 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( | |
| 1606 profile_->GetTokenService()); | |
| 1607 } | |
| 1608 | |
| 1609 // Tests should be able to tune login manager before showing it. | |
| 1610 // Thus only show login manager in normal (non-testing) mode. | |
| 1611 if (!parameters().ui_task) | |
| 1612 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); | |
| 1613 #endif | |
| 1614 | |
| 1615 #if !defined(OS_MACOSX) | 1453 #if !defined(OS_MACOSX) |
| 1616 // Importing other browser settings is done in a browser-like process | 1454 // Importing other browser settings is done in a browser-like process |
| 1617 // that exits when this task has finished. | 1455 // that exits when this task has finished. |
| 1618 // TODO(port): Port the Mac's IPC-based implementation to other platforms to | 1456 // TODO(port): Port the Mac's IPC-based implementation to other platforms to |
| 1619 // replace this implementation. http://crbug.com/22142 | 1457 // replace this implementation. http://crbug.com/22142 |
| 1620 if (parsed_command_line().HasSwitch(switches::kImport) || | 1458 if (parsed_command_line().HasSwitch(switches::kImport) || |
| 1621 parsed_command_line().HasSwitch(switches::kImportFromFile)) { | 1459 parsed_command_line().HasSwitch(switches::kImportFromFile)) { |
| 1622 return FirstRun::ImportNow(profile_, parsed_command_line()); | 1460 return FirstRun::ImportNow(profile_, parsed_command_line()); |
| 1623 } | 1461 } |
| 1624 #endif | 1462 #endif |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1651 // Disk image installation is sort of a first-run task, so it shares the | 1489 // Disk image installation is sort of a first-run task, so it shares the |
| 1652 // kNoFirstRun switch. | 1490 // kNoFirstRun switch. |
| 1653 if (MaybeInstallFromDiskImage()) { | 1491 if (MaybeInstallFromDiskImage()) { |
| 1654 // The application was installed and the installed copy has been | 1492 // The application was installed and the installed copy has been |
| 1655 // launched. This process is now obsolete. Exit. | 1493 // launched. This process is now obsolete. Exit. |
| 1656 return content::RESULT_CODE_NORMAL_EXIT; | 1494 return content::RESULT_CODE_NORMAL_EXIT; |
| 1657 } | 1495 } |
| 1658 } | 1496 } |
| 1659 #endif | 1497 #endif |
| 1660 | 1498 |
| 1661 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized(). | 1499 // TODO(stevenjb): Move WIN and MACOSX specific code to apprpriate Parts. |
| 1662 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts). | 1500 // (requires supporting early exit). |
| 1663 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1501 PostProfileInit(); |
| 1664 chrome_extra_parts_[i]->PostProfileInitialized(); | |
| 1665 | 1502 |
| 1666 // Show the First Run UI if this is the first time Chrome has been run on | 1503 // Show the First Run UI if this is the first time Chrome has been run on |
| 1667 // this computer, or we're being compelled to do so by a command line flag. | 1504 // this computer, or we're being compelled to do so by a command line flag. |
| 1668 // Note that this be done _after_ the PrefService is initialized and all | 1505 // Note that this be done _after_ the PrefService is initialized and all |
| 1669 // preferences are registered, since some of the code that the importer | 1506 // preferences are registered, since some of the code that the importer |
| 1670 // touches reads preferences. | 1507 // touches reads preferences. |
| 1671 if (is_first_run_) { | 1508 if (is_first_run_) { |
| 1672 if (!first_run_ui_bypass_) { | 1509 if (!first_run_ui_bypass_) { |
| 1673 FirstRun::AutoImport(profile_, | 1510 FirstRun::AutoImport(profile_, |
| 1674 master_prefs_->homepage_defined, | 1511 master_prefs_->homepage_defined, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1806 about_flags::RecordUMAStatistics(local_state_); | 1643 about_flags::RecordUMAStatistics(local_state_); |
| 1807 LanguageUsageMetrics::RecordAcceptLanguages( | 1644 LanguageUsageMetrics::RecordAcceptLanguages( |
| 1808 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1645 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 1809 LanguageUsageMetrics::RecordApplicationLanguage( | 1646 LanguageUsageMetrics::RecordApplicationLanguage( |
| 1810 g_browser_process->GetApplicationLocale()); | 1647 g_browser_process->GetApplicationLocale()); |
| 1811 | 1648 |
| 1812 #if defined(OS_WIN) | 1649 #if defined(OS_WIN) |
| 1813 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); | 1650 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); |
| 1814 #endif | 1651 #endif |
| 1815 | 1652 |
| 1816 #if defined(OS_CHROMEOS) | |
| 1817 metrics_->StartExternalMetrics(); | |
| 1818 | |
| 1819 // Initialize the audio handler on ChromeOS. | |
| 1820 chromeos::AudioHandler::Initialize(); | |
| 1821 | |
| 1822 // Listen for system key events so that the user will be able to adjust the | |
| 1823 // volume on the login screen, if Chrome is running on Chrome OS | |
| 1824 // (i.e. not Linux desktop), and in non-test mode. | |
| 1825 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() && | |
| 1826 !parameters().ui_task) { // ui_task is non-NULL when running tests. | |
| 1827 chromeos::SystemKeyEventListener::Initialize(); | |
| 1828 } | |
| 1829 | |
| 1830 // Listen for XI_HierarchyChanged events. | |
| 1831 chromeos::XInputHierarchyChangedEventListener::GetInstance(); | |
| 1832 #endif | |
| 1833 | |
| 1834 // The extension service may be available at this point. If the command line | 1653 // The extension service may be available at this point. If the command line |
| 1835 // specifies --uninstall-extension, attempt the uninstall extension startup | 1654 // specifies --uninstall-extension, attempt the uninstall extension startup |
| 1836 // action. | 1655 // action. |
| 1837 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { | 1656 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { |
| 1838 ExtensionsStartupUtil ext_startup_util; | 1657 ExtensionsStartupUtil ext_startup_util; |
| 1839 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_)) | 1658 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_)) |
| 1840 return content::RESULT_CODE_NORMAL_EXIT; | 1659 return content::RESULT_CODE_NORMAL_EXIT; |
| 1841 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; | 1660 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; |
| 1842 } | 1661 } |
| 1843 | 1662 |
| 1844 // Start watching for hangs during startup. We disarm this hang detector when | 1663 // Start watching for hangs during startup. We disarm this hang detector when |
| 1845 // ThreadWatcher takes over or when browser is shutdown or when | 1664 // ThreadWatcher takes over or when browser is shutdown or when |
| 1846 // startup_watcher_ is deleted. | 1665 // startup_watcher_ is deleted. |
| 1847 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300)); | 1666 startup_watcher_->Arm(base::TimeDelta::FromSeconds(300)); |
| 1848 | 1667 |
| 1849 // Start watching for a hang. | 1668 // Start watching for a hang. |
| 1850 MetricsService::LogNeedForCleanShutdown(); | 1669 MetricsService::LogNeedForCleanShutdown(); |
| 1851 | 1670 |
| 1852 #if defined(OS_WIN) | 1671 #if defined(OS_WIN) |
| 1853 // We check this here because if the profile is OTR (chromeos possibility) | 1672 // We check this here because if the profile is OTR (chromeos possibility) |
| 1854 // it won't still be accessible after browser is destroyed. | 1673 // it won't still be accessible after browser is destroyed. |
| 1855 record_search_engine_ = is_first_run_ && !profile_->IsOffTheRecord(); | 1674 record_search_engine_ = is_first_run_ && !profile_->IsOffTheRecord(); |
| 1856 #endif | 1675 #endif |
| 1857 | 1676 |
| 1858 #if defined(OS_CHROMEOS) | |
| 1859 // Wait until here to start the out-of-memory priority manager so that | |
| 1860 // we give the most amount of time for the other services to start up | |
| 1861 // before we start adjusting the oom priority. | |
| 1862 g_browser_process->oom_priority_manager()->Start(); | |
| 1863 #endif | |
| 1864 | |
| 1865 // Create the instance of the cloud print proxy service so that it can launch | 1677 // Create the instance of the cloud print proxy service so that it can launch |
| 1866 // the service process if needed. This is needed because the service process | 1678 // the service process if needed. This is needed because the service process |
| 1867 // might have shutdown because an update was available. | 1679 // might have shutdown because an update was available. |
| 1868 // TODO(torne): this should maybe be done with | 1680 // TODO(torne): this should maybe be done with |
| 1869 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? | 1681 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? |
| 1870 CloudPrintProxyServiceFactory::GetForProfile(profile_); | 1682 CloudPrintProxyServiceFactory::GetForProfile(profile_); |
| 1871 | 1683 |
| 1872 // Initialize GpuDataManager and collect preliminary gpu info. | 1684 // Initialize GpuDataManager and collect preliminary gpu info. |
| 1873 GpuBlacklistUpdater::Setup(); | 1685 GpuBlacklistUpdater::Setup(); |
| 1874 | 1686 |
| 1875 // Start watching all browser threads for responsiveness. | 1687 // Start watching all browser threads for responsiveness. |
| 1876 ThreadWatcherList::StartWatchingAll(parsed_command_line()); | 1688 ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
| 1877 | 1689 |
| 1878 #if !defined(DISABLE_NACL) | 1690 #if !defined(DISABLE_NACL) |
| 1879 NaClProcessHost::EarlyStartup(); | 1691 NaClProcessHost::EarlyStartup(); |
| 1880 #endif | 1692 #endif |
| 1881 | 1693 |
| 1694 PreBrowserStart(); |
| 1695 |
| 1882 // Instantiate the notification UI manager, as this triggers a perf timer | 1696 // Instantiate the notification UI manager, as this triggers a perf timer |
| 1883 // used to measure startup time. TODO(stevenjb): Figure out what is actually | 1697 // used to measure startup time. TODO(stevenjb): Figure out what is actually |
| 1884 // triggering the timer and call that explicitly in the approprate place. | 1698 // triggering the timer and call that explicitly in the approprate place. |
| 1885 // http://crbug.com/105065. | 1699 // http://crbug.com/105065. |
| 1886 g_browser_process->notification_ui_manager(); | 1700 g_browser_process->notification_ui_manager(); |
| 1887 | 1701 |
| 1888 if (parameters().ui_task) { | 1702 if (parameters().ui_task) { |
| 1889 // We are in test mode. Run one task and enter the main message loop. | 1703 // We are in test mode. Run one task and enter the main message loop. |
| 1890 #if defined(OS_MACOSX) | 1704 #if defined(OS_MACOSX) |
| 1891 if (parameters().autorelease_pool) | 1705 if (parameters().autorelease_pool) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 profile_->GetPrefs()); | 1762 profile_->GetPrefs()); |
| 1949 } | 1763 } |
| 1950 #endif | 1764 #endif |
| 1951 | 1765 |
| 1952 run_message_loop_ = true; | 1766 run_message_loop_ = true; |
| 1953 } else { | 1767 } else { |
| 1954 run_message_loop_ = false; | 1768 run_message_loop_ = false; |
| 1955 } | 1769 } |
| 1956 } | 1770 } |
| 1957 browser_init_.reset(); | 1771 browser_init_.reset(); |
| 1772 |
| 1773 PostBrowserStart(); |
| 1774 |
| 1958 return result_code_; | 1775 return result_code_; |
| 1959 } | 1776 } |
| 1960 | 1777 |
| 1961 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { | 1778 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 1962 // Set the result code set in PreMainMessageLoopRun or set above. | 1779 // Set the result code set in PreMainMessageLoopRun or set above. |
| 1963 *result_code = result_code_; | 1780 *result_code = result_code_; |
| 1964 | 1781 |
| 1965 if (!run_message_loop_) | 1782 if (!run_message_loop_) |
| 1966 return true; // Don't run the default message loop. | 1783 return true; // Don't run the default message loop. |
| 1967 | 1784 |
| 1968 // This should be invoked as close to the start of the browser's | 1785 // This should be invoked as close to the start of the browser's |
| 1969 // UI thread message loop as possible to get a stable measurement | 1786 // UI thread message loop as possible to get a stable measurement |
| 1970 // across versions. | 1787 // across versions. |
| 1971 RecordBrowserStartupTime(); | 1788 RecordBrowserStartupTime(); |
| 1972 | 1789 |
| 1973 #if defined(USE_AURA) | 1790 #if defined(USE_AURA) |
| 1974 aura::Desktop::GetInstance()->Run(); | 1791 aura::Desktop::GetInstance()->Run(); |
| 1975 #elif defined(TOOLKIT_VIEWS) | 1792 #elif defined(TOOLKIT_VIEWS) |
| 1976 views::AcceleratorHandler accelerator_handler; | 1793 views::AcceleratorHandler accelerator_handler; |
| 1977 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 1794 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
| 1978 #elif defined(USE_X11) | 1795 #elif defined(USE_X11) |
| 1979 MessageLoopForUI::current()->RunWithDispatcher(NULL); | 1796 MessageLoopForUI::current()->RunWithDispatcher(NULL); |
| 1980 #elif defined(OS_POSIX) | 1797 #elif defined(OS_POSIX) |
| 1981 MessageLoopForUI::current()->Run(); | 1798 MessageLoopForUI::current()->Run(); |
| 1982 #endif | 1799 #endif |
| 1983 #if defined(OS_CHROMEOS) | |
| 1984 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded", | |
| 1985 true); | |
| 1986 #endif | |
| 1987 | 1800 |
| 1988 return true; | 1801 return true; |
| 1989 } | 1802 } |
| 1990 | 1803 |
| 1991 void ChromeBrowserMainParts::PostMainMessageLoopRun() { | 1804 void ChromeBrowserMainParts::PostMainMessageLoopRun() { |
| 1992 // Start watching for jank during shutdown. It gets disarmed when | 1805 // Start watching for jank during shutdown. It gets disarmed when |
| 1993 // |shutdown_watcher_| object is destructed. | 1806 // |shutdown_watcher_| object is destructed. |
| 1994 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(90)); | 1807 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(90)); |
| 1995 | 1808 |
| 1996 // Disarm the startup hang detector time bomb if it is still Arm'ed. | 1809 // Disarm the startup hang detector time bomb if it is still Arm'ed. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2034 } | 1847 } |
| 2035 } else { | 1848 } else { |
| 2036 UMA_HISTOGRAM_ENUMERATION( | 1849 UMA_HISTOGRAM_ENUMERATION( |
| 2037 "Chrome.SearchSelectExempt", | 1850 "Chrome.SearchSelectExempt", |
| 2038 search_engine_type, | 1851 search_engine_type, |
| 2039 SEARCH_ENGINE_MAX); | 1852 SEARCH_ENGINE_MAX); |
| 2040 } | 1853 } |
| 2041 } | 1854 } |
| 2042 #endif | 1855 #endif |
| 2043 | 1856 |
| 2044 #if defined(OS_CHROMEOS) | |
| 2045 g_browser_process->oom_priority_manager()->Stop(); | |
| 2046 #endif | |
| 2047 | |
| 2048 // Some tests don't set parameters.ui_task, so they started translate | 1857 // Some tests don't set parameters.ui_task, so they started translate |
| 2049 // language fetch that was never completed so we need to cleanup here | 1858 // language fetch that was never completed so we need to cleanup here |
| 2050 // otherwise it will be done by the destructor in a wrong thread. | 1859 // otherwise it will be done by the destructor in a wrong thread. |
| 2051 if (parameters().ui_task == NULL && translate_manager_ != NULL) | 1860 if (parameters().ui_task == NULL && translate_manager_ != NULL) |
| 2052 translate_manager_->CleanupPendingUlrFetcher(); | 1861 translate_manager_->CleanupPendingUlrFetcher(); |
| 2053 | 1862 |
| 2054 if (notify_result_ == ProcessSingleton::PROCESS_NONE) | 1863 if (notify_result_ == ProcessSingleton::PROCESS_NONE) |
| 2055 process_singleton_->Cleanup(); | 1864 process_singleton_->Cleanup(); |
| 2056 | 1865 |
| 2057 // Stop all tasks that might run on WatchDogThread. | 1866 // Stop all tasks that might run on WatchDogThread. |
| 2058 ThreadWatcherList::StopWatchingAll(); | 1867 ThreadWatcherList::StopWatchingAll(); |
| 2059 | 1868 |
| 2060 g_browser_process->metrics_service()->Stop(); | 1869 g_browser_process->metrics_service()->Stop(); |
| 2061 | 1870 |
| 2062 #if defined(OS_CHROMEOS) | |
| 2063 // The XInput2 event listener needs to be shut down earlier than when | |
| 2064 // Singletons are finally destroyed in AtExitManager. | |
| 2065 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop(); | |
| 2066 | |
| 2067 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call, | |
| 2068 // even if Initialize() wasn't called. | |
| 2069 chromeos::SystemKeyEventListener::Shutdown(); | |
| 2070 chromeos::AudioHandler::Shutdown(); | |
| 2071 #endif | |
| 2072 | |
| 2073 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); | 1871 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop(); |
| 2074 browser_process_->StartTearDown(); | 1872 browser_process_->StartTearDown(); |
| 2075 } | 1873 } |
| 2076 | 1874 |
| 2077 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) { | 1875 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) { |
| 2078 browser_process_->PreStopThread(identifier); | 1876 browser_process_->PreStopThread(identifier); |
| 2079 } | 1877 } |
| 2080 | 1878 |
| 2081 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) { | 1879 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) { |
| 2082 browser_process_->PostStopThread(identifier); | 1880 browser_process_->PostStopThread(identifier); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && | 1927 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && |
| 2130 (pre_read == "0" || pre_read == "1")) { | 1928 (pre_read == "0" || pre_read == "1")) { |
| 2131 std::string uma_name(name); | 1929 std::string uma_name(name); |
| 2132 uma_name += "_PreRead"; | 1930 uma_name += "_PreRead"; |
| 2133 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | 1931 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
| 2134 AddPreReadHistogramTime(uma_name.c_str(), time); | 1932 AddPreReadHistogramTime(uma_name.c_str(), time); |
| 2135 } | 1933 } |
| 2136 #endif | 1934 #endif |
| 2137 #endif | 1935 #endif |
| 2138 } | 1936 } |
| OLD | NEW |