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

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

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

Powered by Google App Engine
This is Rietveld 408576698