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

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

Issue 8670001: Move chromeos specific code to ChromeBrowserMainPartsChromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "chrome/browser/metrics/thread_watcher.h" 52 #include "chrome/browser/metrics/thread_watcher.h"
53 #include "chrome/browser/metrics/tracking_synchronizer.h" 53 #include "chrome/browser/metrics/tracking_synchronizer.h"
54 #include "chrome/browser/nacl_host/nacl_process_host.h" 54 #include "chrome/browser/nacl_host/nacl_process_host.h"
55 #include "chrome/browser/net/chrome_dns_cert_provenance_checker.h" 55 #include "chrome/browser/net/chrome_dns_cert_provenance_checker.h"
56 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h" 56 #include "chrome/browser/net/chrome_dns_cert_provenance_checker_factory.h"
57 #include "chrome/browser/net/chrome_net_log.h" 57 #include "chrome/browser/net/chrome_net_log.h"
58 #include "chrome/browser/net/predictor.h" 58 #include "chrome/browser/net/predictor.h"
59 #include "chrome/browser/notifications/desktop_notification_service.h" 59 #include "chrome/browser/notifications/desktop_notification_service.h"
60 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 60 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
61 #include "chrome/browser/plugin_prefs.h" 61 #include "chrome/browser/plugin_prefs.h"
62 #include "chrome/browser/policy/browser_policy_connector.h"
63 #include "chrome/browser/prefs/pref_service.h" 62 #include "chrome/browser/prefs/pref_service.h"
64 #include "chrome/browser/prefs/pref_value_store.h" 63 #include "chrome/browser/prefs/pref_value_store.h"
65 #include "chrome/browser/prerender/prerender_field_trial.h" 64 #include "chrome/browser/prerender/prerender_field_trial.h"
66 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 65 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
67 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 66 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
68 #include "chrome/browser/process_singleton.h" 67 #include "chrome/browser/process_singleton.h"
69 #include "chrome/browser/profiles/profile.h" 68 #include "chrome/browser/profiles/profile.h"
70 #include "chrome/browser/profiles/profile_manager.h" 69 #include "chrome/browser/profiles/profile_manager.h"
71 #include "chrome/browser/search_engines/search_engine_type.h" 70 #include "chrome/browser/search_engines/search_engine_type.h"
72 #include "chrome/browser/search_engines/template_url.h" 71 #include "chrome/browser/search_engines/template_url.h"
73 #include "chrome/browser/search_engines/template_url_service.h" 72 #include "chrome/browser/search_engines/template_url_service.h"
74 #include "chrome/browser/search_engines/template_url_service_factory.h" 73 #include "chrome/browser/search_engines/template_url_service_factory.h"
75 #include "chrome/browser/service/service_process_control.h" 74 #include "chrome/browser/service/service_process_control.h"
76 #include "chrome/browser/shell_integration.h" 75 #include "chrome/browser/shell_integration.h"
77 #include "chrome/browser/translate/translate_manager.h" 76 #include "chrome/browser/translate/translate_manager.h"
78 #include "chrome/browser/ui/browser.h" 77 #include "chrome/browser/ui/browser.h"
79 #include "chrome/browser/ui/browser_init.h" 78 #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/web_resource/gpu_blacklist_updater.h" 80 #include "chrome/browser/web_resource/gpu_blacklist_updater.h"
82 #include "chrome/common/child_process_logging.h" 81 #include "chrome/common/child_process_logging.h"
83 #include "chrome/common/chrome_constants.h" 82 #include "chrome/common/chrome_constants.h"
84 #include "chrome/common/chrome_paths.h" 83 #include "chrome/common/chrome_paths.h"
85 #include "chrome/common/chrome_result_codes.h" 84 #include "chrome/common/chrome_result_codes.h"
86 #include "chrome/common/chrome_switches.h" 85 #include "chrome/common/chrome_switches.h"
87 #include "chrome/common/chrome_version_info.h" 86 #include "chrome/common/chrome_version_info.h"
88 #include "chrome/common/env_vars.h" 87 #include "chrome/common/env_vars.h"
89 #include "chrome/common/json_pref_store.h" 88 #include "chrome/common/json_pref_store.h"
90 #include "chrome/common/jstemplate_builder.h" 89 #include "chrome/common/jstemplate_builder.h"
91 #include "chrome/common/logging_chrome.h"
92 #include "chrome/common/net/net_resource_provider.h" 90 #include "chrome/common/net/net_resource_provider.h"
93 #include "chrome/common/pref_names.h" 91 #include "chrome/common/pref_names.h"
94 #include "chrome/common/profiling.h" 92 #include "chrome/common/profiling.h"
95 #include "chrome/installer/util/google_update_settings.h" 93 #include "chrome/installer/util/google_update_settings.h"
96 #include "content/browser/renderer_host/resource_dispatcher_host.h" 94 #include "content/browser/renderer_host/resource_dispatcher_host.h"
97 #include "content/common/child_process.h" 95 #include "content/common/child_process.h"
98 #include "content/public/browser/browser_thread.h" 96 #include "content/public/browser/browser_thread.h"
99 #include "content/public/common/content_client.h" 97 #include "content/public/common/content_client.h"
100 #include "content/public/common/main_function_params.h" 98 #include "content/public/common/main_function_params.h"
101 #include "grit/app_locale_settings.h" 99 #include "grit/app_locale_settings.h"
(...skipping 19 matching lines...) Expand all
121 #if defined(USE_LINUX_BREAKPAD) 119 #if defined(USE_LINUX_BREAKPAD)
122 #include "base/linux_util.h" 120 #include "base/linux_util.h"
123 #include "chrome/app/breakpad_linux.h" 121 #include "chrome/app/breakpad_linux.h"
124 #endif 122 #endif
125 123
126 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 124 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
127 #include "chrome/browser/first_run/upgrade_util_linux.h" 125 #include "chrome/browser/first_run/upgrade_util_linux.h"
128 #endif 126 #endif
129 127
130 #if defined(OS_CHROMEOS) 128 #if defined(OS_CHROMEOS)
131 #include "chrome/browser/chromeos/audio_handler.h"
132 #include "chrome/browser/chromeos/boot_times_loader.h"
133 #include "chrome/browser/chromeos/cros/cros_library.h" 129 #include "chrome/browser/chromeos/cros/cros_library.h"
134 #include "chrome/browser/chromeos/cros/screen_lock_library.h"
135 #include "chrome/browser/chromeos/cros_settings.h" 130 #include "chrome/browser/chromeos/cros_settings.h"
136 #include "chrome/browser/chromeos/cros_settings_names.h" 131 #include "chrome/browser/chromeos/cros_settings_names.h"
137 #include "chrome/browser/chromeos/customization_document.h"
138 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
139 #include "chrome/browser/chromeos/external_metrics.h"
140 #include "chrome/browser/chromeos/login/authenticator.h"
141 #include "chrome/browser/chromeos/login/login_utils.h"
142 #include "chrome/browser/chromeos/login/ownership_service.h"
143 #include "chrome/browser/chromeos/login/screen_locker.h"
144 #include "chrome/browser/chromeos/login/user_manager.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"
satorux1 2011/11/23 23:51:53 Great to see them gone!
150 #endif 132 #endif
151 133
152 // TODO(port): several win-only methods have been pulled out of this, but 134 // TODO(port): several win-only methods have been pulled out of this, but
153 // BrowserMain() as a whole needs to be broken apart so that it's usable by 135 // BrowserMain() as a whole needs to be broken apart so that it's usable by
154 // other platforms. For now, it's just a stub. This is a serious work in 136 // other platforms. For now, it's just a stub. This is a serious work in
155 // progress and should not be taken as an indication of a real refactoring. 137 // progress and should not be taken as an indication of a real refactoring.
156 138
157 #if defined(OS_WIN) 139 #if defined(OS_WIN)
158 #include "base/environment.h" // For PreRead experiment. 140 #include "base/environment.h" // For PreRead experiment.
159 #include "base/win/windows_version.h" 141 #include "base/win/windows_version.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 #else 446 #else
465 // TODO(port): fix this. See comments near the definition of 447 // TODO(port): fix this. See comments near the definition of
466 // user_data_dir. It is better to CHECK-fail here than it is to 448 // user_data_dir. It is better to CHECK-fail here than it is to
467 // silently exit because of missing code in the above test. 449 // silently exit because of missing code in the above test.
468 CHECK(profile) << "Cannot get default profile."; 450 CHECK(profile) << "Cannot get default profile.";
469 #endif 451 #endif
470 452
471 return NULL; 453 return NULL;
472 } 454 }
473 455
474 #if defined(OS_CHROMEOS)
475
476 // Class is used to login using passed username and password.
477 // The instance will be deleted upon success or failure.
478 class StubLogin : public chromeos::LoginStatusConsumer,
479 public chromeos::LoginUtils::Delegate {
480 public:
481 StubLogin(std::string username, std::string password)
482 : pending_requests_(false),
483 profile_prepared_(false) {
484 authenticator_ = chromeos::LoginUtils::Get()->CreateAuthenticator(this);
485 authenticator_.get()->AuthenticateToLogin(
486 g_browser_process->profile_manager()->GetDefaultProfile(),
487 username,
488 password,
489 std::string(),
490 std::string());
491 }
492
493 ~StubLogin() {
494 chromeos::LoginUtils::Get()->DelegateDeleted(this);
495 }
496
497 void OnLoginFailure(const chromeos::LoginFailure& error) {
498 LOG(ERROR) << "Login Failure: " << error.GetErrorString();
499 delete this;
500 }
501
502 void OnLoginSuccess(const std::string& username,
503 const std::string& password,
504 const GaiaAuthConsumer::ClientLoginResult& credentials,
505 bool pending_requests,
506 bool using_oauth) {
507 pending_requests_ = pending_requests;
508 if (!profile_prepared_) {
509 // Will call OnProfilePrepared in the end.
510 chromeos::LoginUtils::Get()->PrepareProfile(username,
511 password,
512 credentials,
513 pending_requests,
514 using_oauth,
515 false,
516 this);
517 } else if (!pending_requests) {
518 delete this;
519 }
520 }
521
522 // LoginUtils::Delegate implementation:
523 virtual void OnProfilePrepared(Profile* profile) {
524 profile_prepared_ = true;
525 chromeos::LoginUtils::DoBrowserLaunch(profile, NULL);
526 if (!pending_requests_)
527 delete this;
528 }
529
530 scoped_refptr<chromeos::Authenticator> authenticator_;
531 bool pending_requests_;
532 bool profile_prepared_;
533 };
534
535 void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line,
536 Profile* profile) {
537 if (parsed_command_line.HasSwitch(switches::kLoginManager)) {
538 std::string first_screen =
539 parsed_command_line.GetSwitchValueASCII(switches::kLoginScreen);
540 std::string size_arg =
541 parsed_command_line.GetSwitchValueASCII(
542 switches::kLoginScreenSize);
543 gfx::Size size(0, 0);
544 // Allow the size of the login window to be set explicitly. If not set,
545 // default to the entire screen. This is mostly useful for testing.
546 if (size_arg.size()) {
547 std::vector<std::string> dimensions;
548 base::SplitString(size_arg, ',', &dimensions);
549 if (dimensions.size() == 2) {
550 int width, height;
551 if (base::StringToInt(dimensions[0], &width) &&
552 base::StringToInt(dimensions[1], &height))
553 size.SetSize(width, height);
554 }
555 }
556 browser::ShowLoginWizard(first_screen, size);
557 } else if (parsed_command_line.HasSwitch(switches::kLoginUser) &&
558 parsed_command_line.HasSwitch(switches::kLoginPassword)) {
559 chromeos::BootTimesLoader::Get()->RecordLoginAttempted();
560 new StubLogin(
561 parsed_command_line.GetSwitchValueASCII(switches::kLoginUser),
562 parsed_command_line.GetSwitchValueASCII(switches::kLoginPassword));
563 } else {
564 if (!parsed_command_line.HasSwitch(switches::kTestName)) {
565 // We did not log in (we crashed or are debugging), so we need to
566 // set the user name for sync.
567 chromeos::LoginUtils::Get()->RestoreAuthenticationSession(
568 chromeos::UserManager::Get()->logged_in_user().email(), profile);
569 }
570 }
571 }
572
573 #endif // defined(OS_CHROMEOS)
574
575 #if defined(OS_MACOSX) 456 #if defined(OS_MACOSX)
576 OSStatus KeychainCallback(SecKeychainEvent keychain_event, 457 OSStatus KeychainCallback(SecKeychainEvent keychain_event,
577 SecKeychainCallbackInfo *info, void *context) { 458 SecKeychainCallbackInfo *info, void *context) {
578 return noErr; 459 return noErr;
579 } 460 }
580 #endif 461 #endif
581 462
582 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) 463 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK)
583 void RegisterTranslateableItems(void) { 464 void RegisterTranslateableItems(void) {
584 struct { 465 struct {
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 SpdyFieldTrial(); 1030 SpdyFieldTrial();
1150 ConnectBackupJobsFieldTrial(); 1031 ConnectBackupJobsFieldTrial();
1151 WarmConnectionFieldTrial(); 1032 WarmConnectionFieldTrial();
1152 PredictorFieldTrial(); 1033 PredictorFieldTrial();
1153 DefaultAppsFieldTrial(); 1034 DefaultAppsFieldTrial();
1154 } 1035 }
1155 1036
1156 // ----------------------------------------------------------------------------- 1037 // -----------------------------------------------------------------------------
1157 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts. 1038 // TODO(viettrungluu): move more/rest of BrowserMain() into BrowserMainParts.
1158 1039
1159 #if defined(OS_CHROMEOS)
1160 // Allows authenticator to be invoked without adding refcounting. The instances
1161 // will delete themselves upon completion.
1162 DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin);
1163 #endif
1164
1165 #if defined(OS_WIN) 1040 #if defined(OS_WIN)
1166 #define DLLEXPORT __declspec(dllexport) 1041 #define DLLEXPORT __declspec(dllexport)
1167 1042
1168 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. 1043 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling.
1169 extern "C" { 1044 extern "C" {
1170 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 1045 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded();
1171 } 1046 }
1172 1047
1173 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { 1048 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
1174 // Need an instance of AtExitManager to handle singleton creations and 1049 // Need an instance of AtExitManager to handle singleton creations and
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 chrome_extra_parts_[i]->PostMainMessageLoopStart(); 1081 chrome_extra_parts_[i]->PostMainMessageLoopStart();
1207 } 1082 }
1208 1083
1209 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1084 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1210 result_code_ = PreMainMessageLoopRunImpl(); 1085 result_code_ = PreMainMessageLoopRunImpl();
1211 1086
1212 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1087 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1213 chrome_extra_parts_[i]->PreMainMessageLoopRun(); 1088 chrome_extra_parts_[i]->PreMainMessageLoopRun();
1214 } 1089 }
1215 1090
1091 void ChromeBrowserMainParts::PostBrowserProcessInit() {
1092 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1093 chrome_extra_parts_[i]->PostBrowserProcessInit();
1094 }
1095
1096 void ChromeBrowserMainParts::PostProfileInitialized() {
1097 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1098 chrome_extra_parts_[i]->PostProfileInitialized();
1099 }
1100
1101 void ChromeBrowserMainParts::PreBrowserStart() {
1102 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1103 chrome_extra_parts_[i]->PreBrowserStart();
1104 }
1105
1106 void ChromeBrowserMainParts::PostBrowserStart() {
1107 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1108 chrome_extra_parts_[i]->PostBrowserStart();
1109 }
1110
1216 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1111 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1217 run_message_loop_ = false; 1112 run_message_loop_ = false;
1218 FilePath user_data_dir; 1113 FilePath user_data_dir;
1219 #if defined(OS_WIN) 1114 #if defined(OS_WIN)
1220 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1115 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
1221 #else 1116 #else
1222 // Getting the user data dir can fail if the directory isn't 1117 // Getting the user data dir can fail if the directory isn't
1223 // creatable, for example; on Windows in code below we bring up a 1118 // creatable, for example; on Windows in code below we bring up a
1224 // dialog prompting the user to pick a different directory. 1119 // dialog prompting the user to pick a different directory.
1225 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, 1120 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 // thread, which has a proper CFRunloop, instead of later on the I/O thread, 1310 // thread, which has a proper CFRunloop, instead of later on the I/O thread,
1416 // which doesn't. This ensures those notifications will get delivered 1311 // which doesn't. This ensures those notifications will get delivered
1417 // properly. See issue 37766. 1312 // properly. See issue 37766.
1418 // (Note that the callback mask here is empty. I don't want to register for 1313 // (Note that the callback mask here is empty. I don't want to register for
1419 // any callbacks, I just want to initialize the mechanism.) 1314 // any callbacks, I just want to initialize the mechanism.)
1420 SecKeychainAddCallback(&KeychainCallback, 0, NULL); 1315 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1421 #endif 1316 #endif
1422 1317
1423 CreateChildThreads(browser_process_.get()); 1318 CreateChildThreads(browser_process_.get());
1424 1319
1425 #if defined(OS_CHROMEOS)
1426 // Now that the file thread exists we can record our stats.
1427 chromeos::BootTimesLoader::Get()->RecordChromeMainStats();
1428
1429 #if defined(TOOLKIT_USES_GTK)
1430 // Read locale-specific GTK resource information.
1431 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC);
1432 if (!gtkrc.empty())
1433 gtk_rc_parse_string(gtkrc.c_str());
1434 #else
1435 // TODO(saintlou): Need to provide an Aura equivalent.
1436 NOTIMPLEMENTED();
1437 #endif
1438
1439 // Trigger prefetching of ownership status.
1440 chromeos::OwnershipService::GetSharedInstance()->Prewarm();
1441 #endif
1442
1443 // Record last shutdown time into a histogram. 1320 // Record last shutdown time into a histogram.
1444 browser_shutdown::ReadLastShutdownInfo(); 1321 browser_shutdown::ReadLastShutdownInfo();
1445 1322
1446 #if defined(OS_WIN) 1323 #if defined(OS_WIN)
1447 // On Windows, we use our startup as an opportunity to do upgrade/uninstall 1324 // On Windows, we use our startup as an opportunity to do upgrade/uninstall
1448 // tasks. Those care whether the browser is already running. On Linux/Mac, 1325 // tasks. Those care whether the browser is already running. On Linux/Mac,
1449 // upgrade/uninstall happen separately. 1326 // upgrade/uninstall happen separately.
1450 bool already_running = browser_util::IsBrowserAlreadyRunning(); 1327 bool already_running = browser_util::IsBrowserAlreadyRunning();
1451 1328
1452 // If the command line specifies 'uninstall' then we need to work here 1329 // If the command line specifies 'uninstall' then we need to work here
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 } 1395 }
1519 #if !defined(OS_MACOSX) // closing brace for if 1396 #if !defined(OS_MACOSX) // closing brace for if
1520 } 1397 }
1521 #endif 1398 #endif
1522 1399
1523 #if defined(USE_X11) 1400 #if defined(USE_X11)
1524 SetBrowserX11ErrorHandlers(); 1401 SetBrowserX11ErrorHandlers();
1525 #endif 1402 #endif
1526 1403
1527 // Desktop construction occurs here, (required before profile creation). 1404 // Desktop construction occurs here, (required before profile creation).
1528 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1405 PostBrowserProcessInit();
1529 chrome_extra_parts_[i]->PostBrowserProcessInit();
1530 1406
1531 // Profile creation ---------------------------------------------------------- 1407 // Profile creation ----------------------------------------------------------
1532 1408
1533 #if defined(OS_CHROMEOS)
1534 // Initialize the screen locker now so that it can receive
1535 // LOGIN_USER_CHANGED notification from UserManager.
1536 chromeos::ScreenLocker::InitClass();
1537
1538 // This forces the ProfileManager to be created and register for the
1539 // notification it needs to track the logged in user.
1540 g_browser_process->profile_manager();
1541
1542 // TODO(abarth): Should this move to InitializeNetworkOptions()?
1543 // Allow access to file:// on ChromeOS for tests.
1544 if (parsed_command_line().HasSwitch(switches::kAllowFileAccess))
1545 net::URLRequest::AllowFileAccess();
1546
1547 // There are two use cases for kLoginUser:
1548 // 1) if passed in tandem with kLoginPassword, to drive a "StubLogin"
1549 // 2) if passed alone, to signal that the indicated user has already
1550 // logged in and we should behave accordingly.
1551 // This handles case 2.
1552 if (parsed_command_line().HasSwitch(switches::kLoginUser) &&
1553 !parsed_command_line().HasSwitch(switches::kLoginPassword)) {
1554 std::string username =
1555 parsed_command_line().GetSwitchValueASCII(switches::kLoginUser);
1556 VLOG(1) << "Relaunching browser for user: " << username;
1557 chromeos::UserManager::Get()->UserLoggedIn(username);
1558
1559 // Redirects Chrome logging to the user data dir.
1560 logging::RedirectChromeLogging(parsed_command_line());
1561
1562 // Initialize user policy before creating the profile so the profile
1563 // initialization code sees policy settings.
1564 g_browser_process->browser_policy_connector()->InitializeUserPolicy(
1565 username, false /* wait_for_policy_fetch */);
1566 }
1567 #endif
1568
1569 if (is_first_run) { 1409 if (is_first_run) {
1570 // Warn the ProfileManager that an import process will run, possibly 1410 // Warn the ProfileManager that an import process will run, possibly
1571 // locking the WebDataService directory of the next Profile created. 1411 // locking the WebDataService directory of the next Profile created.
1572 g_browser_process->profile_manager()->SetWillImport(); 1412 g_browser_process->profile_manager()->SetWillImport();
1573 } 1413 }
1574 1414
1575 profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); 1415 profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line());
1576 if (!profile_) 1416 if (!profile_)
1577 return content::RESULT_CODE_NORMAL_EXIT; 1417 return content::RESULT_CODE_NORMAL_EXIT;
1578 1418
1579 // Autoload any profiles which are running background apps. 1419 // Autoload any profiles which are running background apps.
1580 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. 1420 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
1581 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled( 1421 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled(
1582 &parsed_command_line())) { 1422 &parsed_command_line())) {
1583 g_browser_process->profile_manager()->AutoloadProfiles(); 1423 g_browser_process->profile_manager()->AutoloadProfiles();
1584 } 1424 }
1585 // Post-profile init --------------------------------------------------------- 1425 // Post-profile init ---------------------------------------------------------
1586 1426
1587 #if defined(OS_CHROMEOS)
1588 // Pass the TokenService pointer to the policy connector so user policy can
1589 // grab a token and register with the policy server.
1590 // TODO(mnissler): Remove once OAuth is the only authentication mechanism.
1591 if (parsed_command_line().HasSwitch(switches::kLoginUser) &&
1592 !parsed_command_line().HasSwitch(switches::kLoginPassword)) {
1593 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService(
1594 profile_->GetTokenService());
1595 }
1596
1597 // Tests should be able to tune login manager before showing it.
1598 // Thus only show login manager in normal (non-testing) mode.
1599 if (!parameters().ui_task)
1600 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_);
1601 #endif
1602
1603 #if !defined(OS_MACOSX) 1427 #if !defined(OS_MACOSX)
1604 // Importing other browser settings is done in a browser-like process 1428 // Importing other browser settings is done in a browser-like process
1605 // that exits when this task has finished. 1429 // that exits when this task has finished.
1606 // TODO(port): Port the Mac's IPC-based implementation to other platforms to 1430 // TODO(port): Port the Mac's IPC-based implementation to other platforms to
1607 // replace this implementation. http://crbug.com/22142 1431 // replace this implementation. http://crbug.com/22142
1608 if (parsed_command_line().HasSwitch(switches::kImport) || 1432 if (parsed_command_line().HasSwitch(switches::kImport) ||
1609 parsed_command_line().HasSwitch(switches::kImportFromFile)) { 1433 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1610 return FirstRun::ImportNow(profile_, parsed_command_line()); 1434 return FirstRun::ImportNow(profile_, parsed_command_line());
1611 } 1435 }
1612 #endif 1436 #endif
(...skipping 28 matching lines...) Expand all
1641 if (MaybeInstallFromDiskImage()) { 1465 if (MaybeInstallFromDiskImage()) {
1642 // The application was installed and the installed copy has been 1466 // The application was installed and the installed copy has been
1643 // launched. This process is now obsolete. Exit. 1467 // launched. This process is now obsolete. Exit.
1644 return content::RESULT_CODE_NORMAL_EXIT; 1468 return content::RESULT_CODE_NORMAL_EXIT;
1645 } 1469 }
1646 } 1470 }
1647 #endif 1471 #endif
1648 1472
1649 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized(). 1473 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized().
1650 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts). 1474 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts).
1651 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1475 PostProfileInitialized();
1652 chrome_extra_parts_[i]->PostProfileInitialized();
1653 1476
1654 // Show the First Run UI if this is the first time Chrome has been run on 1477 // Show the First Run UI if this is the first time Chrome has been run on
1655 // this computer, or we're being compelled to do so by a command line flag. 1478 // this computer, or we're being compelled to do so by a command line flag.
1656 // Note that this be done _after_ the PrefService is initialized and all 1479 // Note that this be done _after_ the PrefService is initialized and all
1657 // preferences are registered, since some of the code that the importer 1480 // preferences are registered, since some of the code that the importer
1658 // touches reads preferences. 1481 // touches reads preferences.
1659 if (is_first_run) { 1482 if (is_first_run) {
1660 if (!first_run_ui_bypass) { 1483 if (!first_run_ui_bypass) {
1661 FirstRun::AutoImport(profile_, 1484 FirstRun::AutoImport(profile_,
1662 master_prefs_->homepage_defined, 1485 master_prefs_->homepage_defined,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 1623 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
1801 LanguageUsageMetrics::RecordApplicationLanguage( 1624 LanguageUsageMetrics::RecordApplicationLanguage(
1802 g_browser_process->GetApplicationLocale()); 1625 g_browser_process->GetApplicationLocale());
1803 1626
1804 #if defined(OS_WIN) 1627 #if defined(OS_WIN)
1805 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); 1628 fragmentation_checker::RecordFragmentationMetricForCurrentModule();
1806 #endif 1629 #endif
1807 1630
1808 #if defined(OS_CHROMEOS) 1631 #if defined(OS_CHROMEOS)
1809 metrics->StartExternalMetrics(); 1632 metrics->StartExternalMetrics();
1810
1811 // Initialize the audio handler on ChromeOS.
1812 chromeos::AudioHandler::Initialize();
1813
1814 // Listen for system key events so that the user will be able to adjust the
1815 // volume on the login screen, if Chrome is running on Chrome OS
1816 // (i.e. not Linux desktop), and in non-test mode.
1817 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() &&
1818 !parameters().ui_task) { // ui_task is non-NULL when running tests.
1819 chromeos::SystemKeyEventListener::Initialize();
1820 }
1821
1822 // Listen for XI_HierarchyChanged events.
1823 chromeos::XInputHierarchyChangedEventListener::GetInstance();
1824 #endif 1633 #endif
1825 1634
1826 // The extension service may be available at this point. If the command line 1635 // The extension service may be available at this point. If the command line
1827 // specifies --uninstall-extension, attempt the uninstall extension startup 1636 // specifies --uninstall-extension, attempt the uninstall extension startup
1828 // action. 1637 // action.
1829 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) { 1638 if (parsed_command_line().HasSwitch(switches::kUninstallExtension)) {
1830 ExtensionsStartupUtil ext_startup_util; 1639 ExtensionsStartupUtil ext_startup_util;
1831 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_)) 1640 if (ext_startup_util.UninstallExtension(parsed_command_line(), profile_))
1832 return content::RESULT_CODE_NORMAL_EXIT; 1641 return content::RESULT_CODE_NORMAL_EXIT;
1833 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; 1642 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
1834 } 1643 }
1835 1644
1836 // Start watching for a hang. 1645 // Start watching for a hang.
1837 MetricsService::LogNeedForCleanShutdown(); 1646 MetricsService::LogNeedForCleanShutdown();
1838 1647
1839 #if defined(OS_WIN) 1648 #if defined(OS_WIN)
1840 // We check this here because if the profile is OTR (chromeos possibility) 1649 // We check this here because if the profile is OTR (chromeos possibility)
1841 // it won't still be accessible after browser is destroyed. 1650 // it won't still be accessible after browser is destroyed.
1842 record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); 1651 record_search_engine_ = is_first_run && !profile_->IsOffTheRecord();
1843 #endif 1652 #endif
1844 1653
1845 // ChildProcess:: is a misnomer unless you consider context. Use 1654 // ChildProcess:: is a misnomer unless you consider context. Use
1846 // of --wait-for-debugger only makes sense when Chrome itself is a 1655 // of --wait-for-debugger only makes sense when Chrome itself is a
1847 // child process (e.g. when launched by PyAuto). 1656 // child process (e.g. when launched by PyAuto).
1848 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { 1657 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) {
1849 ChildProcess::WaitForDebugger("Browser"); 1658 ChildProcess::WaitForDebugger("Browser");
1850 } 1659 }
1851 1660
1852 #if defined(OS_CHROMEOS)
1853 // Wait until here to start the out-of-memory priority manager so that
1854 // we give the most amount of time for the other services to start up
1855 // before we start adjusting the oom priority.
1856 g_browser_process->oom_priority_manager()->Start();
1857 #endif
1858
1859 // Create the instance of the cloud print proxy service so that it can launch 1661 // Create the instance of the cloud print proxy service so that it can launch
1860 // the service process if needed. This is needed because the service process 1662 // the service process if needed. This is needed because the service process
1861 // might have shutdown because an update was available. 1663 // might have shutdown because an update was available.
1862 // TODO(torne): this should maybe be done with 1664 // TODO(torne): this should maybe be done with
1863 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead? 1665 // ProfileKeyedServiceFactory::ServiceIsCreatedWithProfile() instead?
1864 CloudPrintProxyServiceFactory::GetForProfile(profile_); 1666 CloudPrintProxyServiceFactory::GetForProfile(profile_);
1865 1667
1866 // Initialize GpuDataManager and collect preliminary gpu info. 1668 // Initialize GpuDataManager and collect preliminary gpu info.
1867 GpuBlacklistUpdater::Setup(); 1669 GpuBlacklistUpdater::Setup();
1868 1670
1869 // Start watching all browser threads for responsiveness. 1671 // Start watching all browser threads for responsiveness.
1870 ThreadWatcherList::StartWatchingAll(parsed_command_line()); 1672 ThreadWatcherList::StartWatchingAll(parsed_command_line());
1871 1673
1872 #if !defined(DISABLE_NACL) 1674 #if !defined(DISABLE_NACL)
1873 NaClProcessHost::EarlyStartup(); 1675 NaClProcessHost::EarlyStartup();
1874 #endif 1676 #endif
1875 1677
1678 PreBrowserStart();
1679
1876 // Instantiate the notification UI manager, as this triggers a perf timer 1680 // Instantiate the notification UI manager, as this triggers a perf timer
1877 // used to measure startup time. TODO(stevenjb): Figure out what is actually 1681 // used to measure startup time. TODO(stevenjb): Figure out what is actually
1878 // triggering the timer and call that explicitly in the approprate place. 1682 // triggering the timer and call that explicitly in the approprate place.
1879 // http://crbug.com/105065. 1683 // http://crbug.com/105065.
1880 g_browser_process->notification_ui_manager(); 1684 g_browser_process->notification_ui_manager();
1881 1685
1882 if (parameters().ui_task) { 1686 if (parameters().ui_task) {
1883 // We are in test mode. Run one task and enter the main message loop. 1687 // We are in test mode. Run one task and enter the main message loop.
1884 #if defined(OS_MACOSX) 1688 #if defined(OS_MACOSX)
1885 if (parameters().autorelease_pool) 1689 if (parameters().autorelease_pool)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 profile_->GetPrefs()); 1745 profile_->GetPrefs());
1942 } 1746 }
1943 #endif 1747 #endif
1944 1748
1945 run_message_loop_ = true; 1749 run_message_loop_ = true;
1946 } else { 1750 } else {
1947 run_message_loop_ = false; 1751 run_message_loop_ = false;
1948 } 1752 }
1949 } 1753 }
1950 browser_init_.reset(); 1754 browser_init_.reset();
1755
1756 PostBrowserStart();
1757
1951 return result_code_; 1758 return result_code_;
1952 } 1759 }
1953 1760
1954 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { 1761 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
1955 // Set the result code set in PreMainMessageLoopRun or set above. 1762 // Set the result code set in PreMainMessageLoopRun or set above.
1956 *result_code = result_code_; 1763 *result_code = result_code_;
1957 1764
1958 if (!run_message_loop_) 1765 if (!run_message_loop_)
1959 return true; // Don't run the default message loop. 1766 return true; // Don't run the default message loop.
1960 1767
1961 // This should be invoked as close to the start of the browser's 1768 // This should be invoked as close to the start of the browser's
1962 // UI thread message loop as possible to get a stable measurement 1769 // UI thread message loop as possible to get a stable measurement
1963 // across versions. 1770 // across versions.
1964 RecordBrowserStartupTime(); 1771 RecordBrowserStartupTime();
1965 1772
1966 #if defined(USE_AURA) 1773 #if defined(USE_AURA)
1967 aura::Desktop::GetInstance()->Run(); 1774 aura::Desktop::GetInstance()->Run();
1968 #elif defined(TOOLKIT_VIEWS) 1775 #elif defined(TOOLKIT_VIEWS)
1969 views::AcceleratorHandler accelerator_handler; 1776 views::AcceleratorHandler accelerator_handler;
1970 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); 1777 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler);
1971 #elif defined(USE_X11) 1778 #elif defined(USE_X11)
1972 MessageLoopForUI::current()->RunWithDispatcher(NULL); 1779 MessageLoopForUI::current()->RunWithDispatcher(NULL);
1973 #elif defined(OS_POSIX) 1780 #elif defined(OS_POSIX)
1974 MessageLoopForUI::current()->Run(); 1781 MessageLoopForUI::current()->Run();
1975 #endif 1782 #endif
1976 #if defined(OS_CHROMEOS)
1977 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("UIMessageLoopEnded",
1978 true);
1979 #endif
1980 1783
1981 return true; 1784 return true;
1982 } 1785 }
1983 1786
1984 void ChromeBrowserMainParts::PostMainMessageLoopRun() { 1787 void ChromeBrowserMainParts::PostMainMessageLoopRun() {
1985 // Start watching for jank during shutdown. It gets disarmed when 1788 // Start watching for jank during shutdown. It gets disarmed when
1986 // |shutdown_watcher_| object is destructed. 1789 // |shutdown_watcher_| object is destructed.
1987 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(90)); 1790 shutdown_watcher_->Arm(base::TimeDelta::FromSeconds(90));
1988 1791
1989 // Disarm the startup hang detector time bomb if it is still Arm'ed. 1792 // 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
2027 } 1830 }
2028 } else { 1831 } else {
2029 UMA_HISTOGRAM_ENUMERATION( 1832 UMA_HISTOGRAM_ENUMERATION(
2030 "Chrome.SearchSelectExempt", 1833 "Chrome.SearchSelectExempt",
2031 search_engine_type, 1834 search_engine_type,
2032 SEARCH_ENGINE_MAX); 1835 SEARCH_ENGINE_MAX);
2033 } 1836 }
2034 } 1837 }
2035 #endif 1838 #endif
2036 1839
2037 #if defined(OS_CHROMEOS)
2038 g_browser_process->oom_priority_manager()->Stop();
2039 #endif
2040
2041 // Some tests don't set parameters.ui_task, so they started translate 1840 // Some tests don't set parameters.ui_task, so they started translate
2042 // language fetch that was never completed so we need to cleanup here 1841 // language fetch that was never completed so we need to cleanup here
2043 // otherwise it will be done by the destructor in a wrong thread. 1842 // otherwise it will be done by the destructor in a wrong thread.
2044 if (parameters().ui_task == NULL && translate_manager_ != NULL) 1843 if (parameters().ui_task == NULL && translate_manager_ != NULL)
2045 translate_manager_->CleanupPendingUlrFetcher(); 1844 translate_manager_->CleanupPendingUlrFetcher();
2046 1845
2047 if (notify_result_ == ProcessSingleton::PROCESS_NONE) 1846 if (notify_result_ == ProcessSingleton::PROCESS_NONE)
2048 process_singleton_->Cleanup(); 1847 process_singleton_->Cleanup();
2049 1848
2050 // Stop all tasks that might run on WatchDogThread. 1849 // Stop all tasks that might run on WatchDogThread.
2051 ThreadWatcherList::StopWatchingAll(); 1850 ThreadWatcherList::StopWatchingAll();
2052 1851
2053 g_browser_process->metrics_service()->Stop(); 1852 g_browser_process->metrics_service()->Stop();
2054 1853
2055 #if defined(OS_CHROMEOS)
2056 // The XInput2 event listener needs to be shut down earlier than when
2057 // Singletons are finally destroyed in AtExitManager.
2058 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop();
2059
2060 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call,
2061 // even if Initialize() wasn't called.
2062 chromeos::SystemKeyEventListener::Shutdown();
2063 chromeos::AudioHandler::Shutdown();
2064 #endif
2065
2066 // browser_shutdown takes care of deleting browser_process, so we need to 1854 // browser_shutdown takes care of deleting browser_process, so we need to
2067 // release it. 1855 // release it.
2068 ignore_result(browser_process_.release()); 1856 ignore_result(browser_process_.release());
2069 browser_shutdown::Shutdown(); 1857 browser_shutdown::Shutdown();
2070 master_prefs_.reset(); 1858 master_prefs_.reset();
2071 process_singleton_.reset(); 1859 process_singleton_.reset();
2072 1860
2073 // We need to do this check as late as possible, but due to modularity, this 1861 // We need to do this check as late as possible, but due to modularity, this
2074 // may be the last point in Chrome. This would be more effective if done at 1862 // may be the last point in Chrome. This would be more effective if done at
2075 // a higher level on the stack, so that it is impossible for an early return 1863 // a higher level on the stack, so that it is impossible for an early return
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && 1897 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) &&
2110 (pre_read == "0" || pre_read == "1")) { 1898 (pre_read == "0" || pre_read == "1")) {
2111 std::string uma_name(name); 1899 std::string uma_name(name);
2112 uma_name += "_PreRead"; 1900 uma_name += "_PreRead";
2113 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 1901 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
2114 AddPreReadHistogramTime(uma_name.c_str(), time); 1902 AddPreReadHistogramTime(uma_name.c_str(), time);
2115 } 1903 }
2116 #endif 1904 #endif
2117 #endif 1905 #endif
2118 } 1906 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698