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

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

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