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

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

Issue 8539038: Add ChromeBrowserMainExtraParts for non main parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again + explicit reset of parts_ Created 9 years, 1 month 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 14 matching lines...) Expand all
25 #include "base/sys_string_conversions.h" 25 #include "base/sys_string_conversions.h"
26 #include "base/threading/platform_thread.h" 26 #include "base/threading/platform_thread.h"
27 #include "base/time.h" 27 #include "base/time.h"
28 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
29 #include "base/values.h" 29 #include "base/values.h"
30 #include "build/build_config.h" 30 #include "build/build_config.h"
31 #include "chrome/browser/about_flags.h" 31 #include "chrome/browser/about_flags.h"
32 #include "chrome/browser/background/background_mode_manager.h" 32 #include "chrome/browser/background/background_mode_manager.h"
33 #include "chrome/browser/browser_process_impl.h" 33 #include "chrome/browser/browser_process_impl.h"
34 #include "chrome/browser/browser_shutdown.h" 34 #include "chrome/browser/browser_shutdown.h"
35 #include "chrome/browser/chrome_browser_main_extra_parts.h"
35 #include "chrome/browser/defaults.h" 36 #include "chrome/browser/defaults.h"
36 #include "chrome/browser/extensions/default_apps_trial.h" 37 #include "chrome/browser/extensions/default_apps_trial.h"
37 #include "chrome/browser/extensions/extension_protocols.h" 38 #include "chrome/browser/extensions/extension_protocols.h"
38 #include "chrome/browser/extensions/extension_service.h" 39 #include "chrome/browser/extensions/extension_service.h"
39 #include "chrome/browser/extensions/extensions_startup.h" 40 #include "chrome/browser/extensions/extensions_startup.h"
40 #include "chrome/browser/first_run/first_run_browser_process.h" 41 #include "chrome/browser/first_run/first_run_browser_process.h"
41 #include "chrome/browser/first_run/upgrade_util.h" 42 #include "chrome/browser/first_run/upgrade_util.h"
42 #include "chrome/browser/google/google_url_tracker.h" 43 #include "chrome/browser/google/google_url_tracker.h"
43 #include "chrome/browser/google/google_util.h" 44 #include "chrome/browser/google/google_util.h"
44 #include "chrome/browser/instant/instant_field_trial.h" 45 #include "chrome/browser/instant/instant_field_trial.h"
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } else { 552 } else {
552 if (!parsed_command_line.HasSwitch(switches::kTestName)) { 553 if (!parsed_command_line.HasSwitch(switches::kTestName)) {
553 // We did not log in (we crashed or are debugging), so we need to 554 // We did not log in (we crashed or are debugging), so we need to
554 // set the user name for sync. 555 // set the user name for sync.
555 chromeos::LoginUtils::Get()->RestoreAuthenticationSession( 556 chromeos::LoginUtils::Get()->RestoreAuthenticationSession(
556 chromeos::UserManager::Get()->logged_in_user().email(), profile); 557 chromeos::UserManager::Get()->logged_in_user().email(), profile);
557 } 558 }
558 } 559 }
559 } 560 }
560 561
561 #else
562
563 void OptionallyRunChromeOSLoginManager(const CommandLine& parsed_command_line,
564 Profile* profile) {
565 // Dummy empty function for non-ChromeOS builds to avoid extra ifdefs below.
566 }
567
568 #endif // defined(OS_CHROMEOS) 562 #endif // defined(OS_CHROMEOS)
569 563
570 #if defined(OS_MACOSX) 564 #if defined(OS_MACOSX)
571 OSStatus KeychainCallback(SecKeychainEvent keychain_event, 565 OSStatus KeychainCallback(SecKeychainEvent keychain_event,
572 SecKeychainCallbackInfo *info, void *context) { 566 SecKeychainCallbackInfo *info, void *context) {
573 return noErr; 567 return noErr;
574 } 568 }
575 #endif 569 #endif
576 570
577 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) 571 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK)
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1153
1160 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { 1154 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
1161 // Need an instance of AtExitManager to handle singleton creations and 1155 // Need an instance of AtExitManager to handle singleton creations and
1162 // deletions. We need this new instance because, the old instance created 1156 // deletions. We need this new instance because, the old instance created
1163 // in ChromeMain() got destructed when the function returned. 1157 // in ChromeMain() got destructed when the function returned.
1164 base::AtExitManager exit_manager; 1158 base::AtExitManager exit_manager;
1165 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 1159 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
1166 } 1160 }
1167 #endif 1161 #endif
1168 1162
1163 // content::BrowserMainParts implementation ------------------------------------
1164
1169 void ChromeBrowserMainParts::PreEarlyInitialization() { 1165 void ChromeBrowserMainParts::PreEarlyInitialization() {
1166 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1167 chrome_extra_parts_[i]->PreEarlyInitialization();
1170 } 1168 }
1171 1169
1172 void ChromeBrowserMainParts::PostEarlyInitialization() { 1170 void ChromeBrowserMainParts::PostEarlyInitialization() {
1171 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1172 chrome_extra_parts_[i]->PostEarlyInitialization();
1173 } 1173 }
1174 1174
1175 void ChromeBrowserMainParts::ToolkitInitialized() { 1175 void ChromeBrowserMainParts::ToolkitInitialized() {
1176 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1177 chrome_extra_parts_[i]->ToolkitInitialized();
1176 } 1178 }
1177 1179
1178 void ChromeBrowserMainParts::PreMainMessageLoopStart() { 1180 void ChromeBrowserMainParts::PreMainMessageLoopStart() {
1181 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1182 chrome_extra_parts_[i]->PreMainMessageLoopStart();
1179 } 1183 }
1180 1184
1181 void ChromeBrowserMainParts::PostMainMessageLoopStart() { 1185 void ChromeBrowserMainParts::PostMainMessageLoopStart() {
1186 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1187 chrome_extra_parts_[i]->PostMainMessageLoopStart();
1182 } 1188 }
1183 1189
1184 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1190 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1185 result_code_ = PreMainMessageLoopRunImpl(); 1191 result_code_ = PreMainMessageLoopRunImpl();
1192
1193 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1194 chrome_extra_parts_[i]->PreMainMessageLoopRun();
1186 } 1195 }
1187 1196
1188 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1197 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1189 run_message_loop_ = false; 1198 run_message_loop_ = false;
1190 FilePath user_data_dir; 1199 FilePath user_data_dir;
1191 #if defined(OS_WIN) 1200 #if defined(OS_WIN)
1192 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1201 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
1193 #else 1202 #else
1194 // Getting the user data dir can fail if the directory isn't 1203 // Getting the user data dir can fail if the directory isn't
1195 // creatable, for example; on Windows in code below we bring up a 1204 // creatable, for example; on Windows in code below we bring up a
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 NOTREACHED(); 1507 NOTREACHED();
1499 } 1508 }
1500 #if !defined(OS_MACOSX) // closing brace for if 1509 #if !defined(OS_MACOSX) // closing brace for if
1501 } 1510 }
1502 #endif 1511 #endif
1503 1512
1504 #if defined(USE_X11) 1513 #if defined(USE_X11)
1505 SetBrowserX11ErrorHandlers(); 1514 SetBrowserX11ErrorHandlers();
1506 #endif 1515 #endif
1507 1516
1517 // Desktop construction occurs here, (required before profile creation).
1518 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1519 chrome_extra_parts_[i]->PostBrowserProcessInit();
1520
1508 // Profile creation ---------------------------------------------------------- 1521 // Profile creation ----------------------------------------------------------
1509 1522
1510 #if defined(OS_CHROMEOS) 1523 #if defined(OS_CHROMEOS)
1511 // Initialize the screen locker now so that it can receive 1524 // Initialize the screen locker now so that it can receive
1512 // LOGIN_USER_CHANGED notification from UserManager. 1525 // LOGIN_USER_CHANGED notification from UserManager.
1513 chromeos::ScreenLocker::InitClass(); 1526 chromeos::ScreenLocker::InitClass();
1514 1527
1515 // This forces the ProfileManager to be created and register for the 1528 // This forces the ProfileManager to be created and register for the
1516 // notification it needs to track the logged in user. 1529 // notification it needs to track the logged in user.
1517 g_browser_process->profile_manager(); 1530 g_browser_process->profile_manager();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 1576
1564 #if defined(OS_CHROMEOS) 1577 #if defined(OS_CHROMEOS)
1565 // Pass the TokenService pointer to the policy connector so user policy can 1578 // Pass the TokenService pointer to the policy connector so user policy can
1566 // grab a token and register with the policy server. 1579 // grab a token and register with the policy server.
1567 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. 1580 // TODO(mnissler): Remove once OAuth is the only authentication mechanism.
1568 if (parsed_command_line().HasSwitch(switches::kLoginUser) && 1581 if (parsed_command_line().HasSwitch(switches::kLoginUser) &&
1569 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { 1582 !parsed_command_line().HasSwitch(switches::kLoginPassword)) {
1570 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( 1583 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService(
1571 profile_->GetTokenService()); 1584 profile_->GetTokenService());
1572 } 1585 }
1586
1587 // Tests should be able to tune login manager before showing it.
1588 // Thus only show login manager in normal (non-testing) mode.
1589 if (!parameters().ui_task)
1590 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_);
1573 #endif 1591 #endif
1574 1592
1575 #if !defined(OS_MACOSX) 1593 #if !defined(OS_MACOSX)
1576 // Importing other browser settings is done in a browser-like process 1594 // Importing other browser settings is done in a browser-like process
1577 // that exits when this task has finished. 1595 // that exits when this task has finished.
1578 // TODO(port): Port the Mac's IPC-based implementation to other platforms to 1596 // TODO(port): Port the Mac's IPC-based implementation to other platforms to
1579 // replace this implementation. http://crbug.com/22142 1597 // replace this implementation. http://crbug.com/22142
1580 if (parsed_command_line().HasSwitch(switches::kImport) || 1598 if (parsed_command_line().HasSwitch(switches::kImport) ||
1581 parsed_command_line().HasSwitch(switches::kImportFromFile)) { 1599 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1582 return FirstRun::ImportNow(profile_, parsed_command_line()); 1600 return FirstRun::ImportNow(profile_, parsed_command_line());
(...skipping 28 matching lines...) Expand all
1611 // Disk image installation is sort of a first-run task, so it shares the 1629 // Disk image installation is sort of a first-run task, so it shares the
1612 // kNoFirstRun switch. 1630 // kNoFirstRun switch.
1613 if (MaybeInstallFromDiskImage()) { 1631 if (MaybeInstallFromDiskImage()) {
1614 // The application was installed and the installed copy has been 1632 // The application was installed and the installed copy has been
1615 // launched. This process is now obsolete. Exit. 1633 // launched. This process is now obsolete. Exit.
1616 return content::RESULT_CODE_NORMAL_EXIT; 1634 return content::RESULT_CODE_NORMAL_EXIT;
1617 } 1635 }
1618 } 1636 }
1619 #endif 1637 #endif
1620 1638
1639 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized().
1640 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts).
1641 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1642 chrome_extra_parts_[i]->PostProfileInitialized();
1643
1621 // Show the First Run UI if this is the first time Chrome has been run on 1644 // Show the First Run UI if this is the first time Chrome has been run on
1622 // this computer, or we're being compelled to do so by a command line flag. 1645 // this computer, or we're being compelled to do so by a command line flag.
1623 // Note that this be done _after_ the PrefService is initialized and all 1646 // Note that this be done _after_ the PrefService is initialized and all
1624 // preferences are registered, since some of the code that the importer 1647 // preferences are registered, since some of the code that the importer
1625 // touches reads preferences. 1648 // touches reads preferences.
1626 if (is_first_run) { 1649 if (is_first_run) {
1627 if (!first_run_ui_bypass) { 1650 if (!first_run_ui_bypass) {
1628 FirstRun::AutoImport(profile_, 1651 FirstRun::AutoImport(profile_,
1629 master_prefs_->homepage_defined, 1652 master_prefs_->homepage_defined,
1630 master_prefs_->do_import_items, 1653 master_prefs_->do_import_items,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 BrowserThread::FILE, FROM_HERE, 1859 BrowserThread::FILE, FROM_HERE,
1837 base::Bind(&GpuBlacklistUpdater::SetupOnFileThread)); 1860 base::Bind(&GpuBlacklistUpdater::SetupOnFileThread));
1838 1861
1839 // Start watching all browser threads for responsiveness. 1862 // Start watching all browser threads for responsiveness.
1840 ThreadWatcherList::StartWatchingAll(parsed_command_line()); 1863 ThreadWatcherList::StartWatchingAll(parsed_command_line());
1841 1864
1842 #if !defined(DISABLE_NACL) 1865 #if !defined(DISABLE_NACL)
1843 NaClProcessHost::EarlyStartup(); 1866 NaClProcessHost::EarlyStartup();
1844 #endif 1867 #endif
1845 1868
1846 run_message_loop_ = true;
1847 return content::RESULT_CODE_NORMAL_EXIT;
1848 }
1849
1850 // Called from MainMessageLoopRun().
1851 void ChromeBrowserMainParts::StartBrowserOrUITask() {
1852 // Still initializing, so need to allow IO.
1853 base::ThreadRestrictions::ScopedAllowIO allow_io;
1854
1855 // Set the notification UI manager after any desktop initialization in
1856 // PreMainMessageLoopRun() is complete, and before starting the browser.
1857 DesktopNotificationServiceFactory::GetForProfile(profile_)->SetUIManager(
1858 g_browser_process->notification_ui_manager());
1859
1860 // Tests should be able to tune login manager before showing it.
1861 // Thus only show login manager in normal (non-testing) mode.
1862 if (!parameters().ui_task)
1863 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_);
1864
1865 if (parameters().ui_task) { 1869 if (parameters().ui_task) {
1866 // We are in test mode. Run one task and enter the main message loop. 1870 // We are in test mode. Run one task and enter the main message loop.
1867 #if defined(OS_MACOSX) 1871 #if defined(OS_MACOSX)
1868 if (parameters().autorelease_pool) 1872 if (parameters().autorelease_pool)
1869 parameters().autorelease_pool->Recycle(); 1873 parameters().autorelease_pool->Recycle();
1870 #endif 1874 #endif
1871 parameters().ui_task->Run(); 1875 parameters().ui_task->Run();
1872 delete parameters().ui_task; 1876 delete parameters().ui_task;
1873 run_message_loop_ = false; 1877 run_message_loop_ = false;
1874 } else { 1878 } else {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 profile_->GetPrefs()); 1928 profile_->GetPrefs());
1925 } 1929 }
1926 #endif 1930 #endif
1927 1931
1928 run_message_loop_ = true; 1932 run_message_loop_ = true;
1929 } else { 1933 } else {
1930 run_message_loop_ = false; 1934 run_message_loop_ = false;
1931 } 1935 }
1932 } 1936 }
1933 browser_init_.reset(); 1937 browser_init_.reset();
1938 return result_code_;
1934 } 1939 }
1935 1940
1936 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { 1941 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) {
1937 // Set the result code set in PreMainMessageLoopRun or set above. 1942 // Set the result code set in PreMainMessageLoopRun or set above.
1938 *result_code = result_code_; 1943 *result_code = result_code_;
1939 1944
1940 // TODO(stevenjb): Move this to another phase, and/or clean up
1941 // PreMainMessageLoopRun() so that this can happen after desktop
1942 // initilaization and before running the main loop.
1943 if (run_message_loop_)
1944 StartBrowserOrUITask();
1945
1946 if (!run_message_loop_) 1945 if (!run_message_loop_)
1947 return true; // Don't run the default message loop. 1946 return true; // Don't run the default message loop.
1948 1947
1949 // This should be invoked as close to the start of the browser's 1948 // This should be invoked as close to the start of the browser's
1950 // UI thread message loop as possible to get a stable measurement 1949 // UI thread message loop as possible to get a stable measurement
1951 // across versions. 1950 // across versions.
1952 RecordBrowserStartupTime(); 1951 RecordBrowserStartupTime();
1953 1952
1954 #if defined(USE_AURA) 1953 #if defined(USE_AURA)
1955 aura::Desktop::GetInstance()->Run(); 1954 aura::Desktop::GetInstance()->Run();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 browser_shutdown::Shutdown(); 2056 browser_shutdown::Shutdown();
2058 master_prefs_.reset(); 2057 master_prefs_.reset();
2059 process_singleton_.reset(); 2058 process_singleton_.reset();
2060 2059
2061 // We need to do this check as late as possible, but due to modularity, this 2060 // We need to do this check as late as possible, but due to modularity, this
2062 // may be the last point in Chrome. This would be more effective if done at 2061 // may be the last point in Chrome. This would be more effective if done at
2063 // a higher level on the stack, so that it is impossible for an early return 2062 // a higher level on the stack, so that it is impossible for an early return
2064 // to bypass this code. Perhaps we need a *final* hook that is called on all 2063 // to bypass this code. Perhaps we need a *final* hook that is called on all
2065 // paths from content/browser/browser_main. 2064 // paths from content/browser/browser_main.
2066 CHECK(MetricsService::UmaMetricsProperlyShutdown()); 2065 CHECK(MetricsService::UmaMetricsProperlyShutdown());
2066
2067 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
2068 chrome_extra_parts_[i]->PostMainMessageLoopRun();
2067 } 2069 }
2068 2070
2071 // Public members:
2072
2073 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
2074 chrome_extra_parts_.push_back(parts);
2075 }
2076
2077 // Misc ------------------------------------------------------------------------
2078
2069 // This code is specific to the Windows-only PreReadExperiment field-trial. 2079 // This code is specific to the Windows-only PreReadExperiment field-trial.
2070 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { 2080 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) {
2071 DCHECK(name != NULL); 2081 DCHECK(name != NULL);
2072 2082
2073 // This gets called with different histogram names, so we don't want to use 2083 // This gets called with different histogram names, so we don't want to use
2074 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the 2084 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the
2075 // first call wins. 2085 // first call wins.
2076 AddPreReadHistogramTime(name, time); 2086 AddPreReadHistogramTime(name, time);
2077 2087
2078 #if defined(OS_WIN) 2088 #if defined(OS_WIN)
2079 #if defined(GOOGLE_CHROME_BUILD) 2089 #if defined(GOOGLE_CHROME_BUILD)
2080 // The pre-read experiment is Windows and Google Chrome specific. 2090 // The pre-read experiment is Windows and Google Chrome specific.
2081 scoped_ptr<base::Environment> env(base::Environment::Create()); 2091 scoped_ptr<base::Environment> env(base::Environment::Create());
2082 2092
2083 // Only record the sub-histogram result if the experiment is running 2093 // Only record the sub-histogram result if the experiment is running
2084 // (environment variable is set, and valid). 2094 // (environment variable is set, and valid).
2085 std::string pre_read; 2095 std::string pre_read;
2086 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && 2096 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) &&
2087 (pre_read == "0" || pre_read == "1")) { 2097 (pre_read == "0" || pre_read == "1")) {
2088 std::string uma_name(name); 2098 std::string uma_name(name);
2089 uma_name += "_PreRead"; 2099 uma_name += "_PreRead";
2090 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 2100 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
2091 AddPreReadHistogramTime(uma_name.c_str(), time); 2101 AddPreReadHistogramTime(uma_name.c_str(), time);
2092 } 2102 }
2093 #endif 2103 #endif
2094 #endif 2104 #endif
2095 } 2105 }
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