OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
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 Loading... |
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 translate_manager_(NULL), | 672 translate_manager_(NULL), |
679 profile_(NULL), | 673 profile_(NULL), |
680 run_message_loop_(true), | 674 run_message_loop_(true), |
681 notify_result_(ProcessSingleton::PROCESS_NONE) { | 675 notify_result_(ProcessSingleton::PROCESS_NONE) { |
682 // If we're running tests (ui_task is non-null). | 676 // If we're running tests (ui_task is non-null). |
683 if (parameters.ui_task) | 677 if (parameters.ui_task) |
684 browser_defaults::enable_help_app = false; | 678 browser_defaults::enable_help_app = false; |
685 } | 679 } |
686 | 680 |
687 ChromeBrowserMainParts::~ChromeBrowserMainParts() { | 681 ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
| 682 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) |
| 683 delete chrome_extra_parts_[i]; |
| 684 chrome_extra_parts_.clear(); |
688 } | 685 } |
689 | 686 |
690 // This will be called after the command-line has been mutated by about:flags | 687 // This will be called after the command-line has been mutated by about:flags |
691 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( | 688 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( |
692 PrefService* local_state) { | 689 PrefService* local_state) { |
693 // Must initialize metrics after labs have been converted into switches, | 690 // Must initialize metrics after labs have been converted into switches, |
694 // but before field trials are set up (so that client ID is available for | 691 // but before field trials are set up (so that client ID is available for |
695 // one-time randomized field trials). | 692 // one-time randomized field trials). |
696 MetricsService* metrics = InitializeMetrics( | 693 MetricsService* metrics = InitializeMetrics( |
697 parsed_command_line_, local_state); | 694 parsed_command_line_, local_state); |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 | 1156 |
1160 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { | 1157 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
1161 // Need an instance of AtExitManager to handle singleton creations and | 1158 // Need an instance of AtExitManager to handle singleton creations and |
1162 // deletions. We need this new instance because, the old instance created | 1159 // deletions. We need this new instance because, the old instance created |
1163 // in ChromeMain() got destructed when the function returned. | 1160 // in ChromeMain() got destructed when the function returned. |
1164 base::AtExitManager exit_manager; | 1161 base::AtExitManager exit_manager; |
1165 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 1162 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
1166 } | 1163 } |
1167 #endif | 1164 #endif |
1168 | 1165 |
| 1166 // content::BrowserMainParts implementation ------------------------------------ |
| 1167 |
1169 void ChromeBrowserMainParts::PreEarlyInitialization() { | 1168 void ChromeBrowserMainParts::PreEarlyInitialization() { |
| 1169 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1170 chrome_extra_parts_[i]->PreEarlyInitialization(); |
1170 } | 1171 } |
1171 | 1172 |
1172 void ChromeBrowserMainParts::PostEarlyInitialization() { | 1173 void ChromeBrowserMainParts::PostEarlyInitialization() { |
| 1174 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1175 chrome_extra_parts_[i]->PostEarlyInitialization(); |
1173 } | 1176 } |
1174 | 1177 |
1175 void ChromeBrowserMainParts::ToolkitInitialized() { | 1178 void ChromeBrowserMainParts::ToolkitInitialized() { |
| 1179 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1180 chrome_extra_parts_[i]->ToolkitInitialized(); |
1176 } | 1181 } |
1177 | 1182 |
1178 void ChromeBrowserMainParts::PreMainMessageLoopStart() { | 1183 void ChromeBrowserMainParts::PreMainMessageLoopStart() { |
| 1184 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1185 chrome_extra_parts_[i]->PreMainMessageLoopStart(); |
1179 } | 1186 } |
1180 | 1187 |
1181 void ChromeBrowserMainParts::PostMainMessageLoopStart() { | 1188 void ChromeBrowserMainParts::PostMainMessageLoopStart() { |
| 1189 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1190 chrome_extra_parts_[i]->PostMainMessageLoopStart(); |
1182 } | 1191 } |
1183 | 1192 |
1184 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1193 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
1185 result_code_ = PreMainMessageLoopRunImpl(); | 1194 result_code_ = PreMainMessageLoopRunImpl(); |
| 1195 |
| 1196 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1197 chrome_extra_parts_[i]->PreMainMessageLoopRun(); |
1186 } | 1198 } |
1187 | 1199 |
1188 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1200 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
1189 run_message_loop_ = false; | 1201 run_message_loop_ = false; |
1190 FilePath user_data_dir; | 1202 FilePath user_data_dir; |
1191 #if defined(OS_WIN) | 1203 #if defined(OS_WIN) |
1192 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 1204 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
1193 #else | 1205 #else |
1194 // Getting the user data dir can fail if the directory isn't | 1206 // 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 | 1207 // creatable, for example; on Windows in code below we bring up a |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 NOTREACHED(); | 1510 NOTREACHED(); |
1499 } | 1511 } |
1500 #if !defined(OS_MACOSX) // closing brace for if | 1512 #if !defined(OS_MACOSX) // closing brace for if |
1501 } | 1513 } |
1502 #endif | 1514 #endif |
1503 | 1515 |
1504 #if defined(USE_X11) | 1516 #if defined(USE_X11) |
1505 SetBrowserX11ErrorHandlers(); | 1517 SetBrowserX11ErrorHandlers(); |
1506 #endif | 1518 #endif |
1507 | 1519 |
| 1520 // Desktop construction occurs here, (required before profile creation). |
| 1521 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1522 chrome_extra_parts_[i]->PostBrowserProcessInit(); |
| 1523 |
1508 // Profile creation ---------------------------------------------------------- | 1524 // Profile creation ---------------------------------------------------------- |
1509 | 1525 |
1510 #if defined(OS_CHROMEOS) | 1526 #if defined(OS_CHROMEOS) |
1511 // Initialize the screen locker now so that it can receive | 1527 // Initialize the screen locker now so that it can receive |
1512 // LOGIN_USER_CHANGED notification from UserManager. | 1528 // LOGIN_USER_CHANGED notification from UserManager. |
1513 chromeos::ScreenLocker::InitClass(); | 1529 chromeos::ScreenLocker::InitClass(); |
1514 | 1530 |
1515 // This forces the ProfileManager to be created and register for the | 1531 // This forces the ProfileManager to be created and register for the |
1516 // notification it needs to track the logged in user. | 1532 // notification it needs to track the logged in user. |
1517 g_browser_process->profile_manager(); | 1533 g_browser_process->profile_manager(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 | 1579 |
1564 #if defined(OS_CHROMEOS) | 1580 #if defined(OS_CHROMEOS) |
1565 // Pass the TokenService pointer to the policy connector so user policy can | 1581 // Pass the TokenService pointer to the policy connector so user policy can |
1566 // grab a token and register with the policy server. | 1582 // grab a token and register with the policy server. |
1567 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. | 1583 // TODO(mnissler): Remove once OAuth is the only authentication mechanism. |
1568 if (parsed_command_line().HasSwitch(switches::kLoginUser) && | 1584 if (parsed_command_line().HasSwitch(switches::kLoginUser) && |
1569 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { | 1585 !parsed_command_line().HasSwitch(switches::kLoginPassword)) { |
1570 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( | 1586 g_browser_process->browser_policy_connector()->SetUserPolicyTokenService( |
1571 profile_->GetTokenService()); | 1587 profile_->GetTokenService()); |
1572 } | 1588 } |
| 1589 |
| 1590 // Tests should be able to tune login manager before showing it. |
| 1591 // Thus only show login manager in normal (non-testing) mode. |
| 1592 if (!parameters().ui_task) |
| 1593 OptionallyRunChromeOSLoginManager(parsed_command_line(), profile_); |
1573 #endif | 1594 #endif |
1574 | 1595 |
1575 #if !defined(OS_MACOSX) | 1596 #if !defined(OS_MACOSX) |
1576 // Importing other browser settings is done in a browser-like process | 1597 // Importing other browser settings is done in a browser-like process |
1577 // that exits when this task has finished. | 1598 // that exits when this task has finished. |
1578 // TODO(port): Port the Mac's IPC-based implementation to other platforms to | 1599 // TODO(port): Port the Mac's IPC-based implementation to other platforms to |
1579 // replace this implementation. http://crbug.com/22142 | 1600 // replace this implementation. http://crbug.com/22142 |
1580 if (parsed_command_line().HasSwitch(switches::kImport) || | 1601 if (parsed_command_line().HasSwitch(switches::kImport) || |
1581 parsed_command_line().HasSwitch(switches::kImportFromFile)) { | 1602 parsed_command_line().HasSwitch(switches::kImportFromFile)) { |
1582 return FirstRun::ImportNow(profile_, parsed_command_line()); | 1603 return FirstRun::ImportNow(profile_, parsed_command_line()); |
(...skipping 28 matching lines...) Expand all Loading... |
1611 // Disk image installation is sort of a first-run task, so it shares the | 1632 // Disk image installation is sort of a first-run task, so it shares the |
1612 // kNoFirstRun switch. | 1633 // kNoFirstRun switch. |
1613 if (MaybeInstallFromDiskImage()) { | 1634 if (MaybeInstallFromDiskImage()) { |
1614 // The application was installed and the installed copy has been | 1635 // The application was installed and the installed copy has been |
1615 // launched. This process is now obsolete. Exit. | 1636 // launched. This process is now obsolete. Exit. |
1616 return content::RESULT_CODE_NORMAL_EXIT; | 1637 return content::RESULT_CODE_NORMAL_EXIT; |
1617 } | 1638 } |
1618 } | 1639 } |
1619 #endif | 1640 #endif |
1620 | 1641 |
| 1642 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized(). |
| 1643 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts). |
| 1644 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 1645 chrome_extra_parts_[i]->PostProfileInitialized(); |
| 1646 |
1621 // Show the First Run UI if this is the first time Chrome has been run on | 1647 // 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. | 1648 // 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 | 1649 // Note that this be done _after_ the PrefService is initialized and all |
1624 // preferences are registered, since some of the code that the importer | 1650 // preferences are registered, since some of the code that the importer |
1625 // touches reads preferences. | 1651 // touches reads preferences. |
1626 if (is_first_run) { | 1652 if (is_first_run) { |
1627 if (!first_run_ui_bypass) { | 1653 if (!first_run_ui_bypass) { |
1628 FirstRun::AutoImport(profile_, | 1654 FirstRun::AutoImport(profile_, |
1629 master_prefs_->homepage_defined, | 1655 master_prefs_->homepage_defined, |
1630 master_prefs_->do_import_items, | 1656 master_prefs_->do_import_items, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 BrowserThread::FILE, FROM_HERE, | 1862 BrowserThread::FILE, FROM_HERE, |
1837 base::Bind(&GpuBlacklistUpdater::SetupOnFileThread)); | 1863 base::Bind(&GpuBlacklistUpdater::SetupOnFileThread)); |
1838 | 1864 |
1839 // Start watching all browser threads for responsiveness. | 1865 // Start watching all browser threads for responsiveness. |
1840 ThreadWatcherList::StartWatchingAll(parsed_command_line()); | 1866 ThreadWatcherList::StartWatchingAll(parsed_command_line()); |
1841 | 1867 |
1842 #if !defined(DISABLE_NACL) | 1868 #if !defined(DISABLE_NACL) |
1843 NaClProcessHost::EarlyStartup(); | 1869 NaClProcessHost::EarlyStartup(); |
1844 #endif | 1870 #endif |
1845 | 1871 |
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) { | 1872 if (parameters().ui_task) { |
1866 // We are in test mode. Run one task and enter the main message loop. | 1873 // We are in test mode. Run one task and enter the main message loop. |
1867 #if defined(OS_MACOSX) | 1874 #if defined(OS_MACOSX) |
1868 if (parameters().autorelease_pool) | 1875 if (parameters().autorelease_pool) |
1869 parameters().autorelease_pool->Recycle(); | 1876 parameters().autorelease_pool->Recycle(); |
1870 #endif | 1877 #endif |
1871 parameters().ui_task->Run(); | 1878 parameters().ui_task->Run(); |
1872 delete parameters().ui_task; | 1879 delete parameters().ui_task; |
1873 run_message_loop_ = false; | 1880 run_message_loop_ = false; |
1874 } else { | 1881 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 profile_->GetPrefs()); | 1931 profile_->GetPrefs()); |
1925 } | 1932 } |
1926 #endif | 1933 #endif |
1927 | 1934 |
1928 run_message_loop_ = true; | 1935 run_message_loop_ = true; |
1929 } else { | 1936 } else { |
1930 run_message_loop_ = false; | 1937 run_message_loop_ = false; |
1931 } | 1938 } |
1932 } | 1939 } |
1933 browser_init_.reset(); | 1940 browser_init_.reset(); |
| 1941 return result_code_; |
1934 } | 1942 } |
1935 | 1943 |
1936 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { | 1944 bool ChromeBrowserMainParts::MainMessageLoopRun(int* result_code) { |
1937 // Set the result code set in PreMainMessageLoopRun or set above. | 1945 // Set the result code set in PreMainMessageLoopRun or set above. |
1938 *result_code = result_code_; | 1946 *result_code = result_code_; |
1939 | 1947 |
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_) | 1948 if (!run_message_loop_) |
1947 return true; // Don't run the default message loop. | 1949 return true; // Don't run the default message loop. |
1948 | 1950 |
1949 // This should be invoked as close to the start of the browser's | 1951 // 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 | 1952 // UI thread message loop as possible to get a stable measurement |
1951 // across versions. | 1953 // across versions. |
1952 RecordBrowserStartupTime(); | 1954 RecordBrowserStartupTime(); |
1953 | 1955 |
1954 #if defined(USE_AURA) | 1956 #if defined(USE_AURA) |
1955 aura::Desktop::GetInstance()->Run(); | 1957 aura::Desktop::GetInstance()->Run(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 browser_shutdown::Shutdown(); | 2059 browser_shutdown::Shutdown(); |
2058 master_prefs_.reset(); | 2060 master_prefs_.reset(); |
2059 process_singleton_.reset(); | 2061 process_singleton_.reset(); |
2060 | 2062 |
2061 // We need to do this check as late as possible, but due to modularity, this | 2063 // 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 | 2064 // 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 | 2065 // 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 | 2066 // to bypass this code. Perhaps we need a *final* hook that is called on all |
2065 // paths from content/browser/browser_main. | 2067 // paths from content/browser/browser_main. |
2066 CHECK(MetricsService::UmaMetricsProperlyShutdown()); | 2068 CHECK(MetricsService::UmaMetricsProperlyShutdown()); |
| 2069 |
| 2070 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
| 2071 chrome_extra_parts_[i]->PostMainMessageLoopRun(); |
2067 } | 2072 } |
2068 | 2073 |
| 2074 // Public members: |
| 2075 |
| 2076 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 2077 chrome_extra_parts_.push_back(parts); |
| 2078 } |
| 2079 |
| 2080 // Misc ------------------------------------------------------------------------ |
| 2081 |
2069 // This code is specific to the Windows-only PreReadExperiment field-trial. | 2082 // This code is specific to the Windows-only PreReadExperiment field-trial. |
2070 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { | 2083 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { |
2071 DCHECK(name != NULL); | 2084 DCHECK(name != NULL); |
2072 | 2085 |
2073 // This gets called with different histogram names, so we don't want to use | 2086 // 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 | 2087 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the |
2075 // first call wins. | 2088 // first call wins. |
2076 AddPreReadHistogramTime(name, time); | 2089 AddPreReadHistogramTime(name, time); |
2077 | 2090 |
2078 #if defined(OS_WIN) | 2091 #if defined(OS_WIN) |
2079 #if defined(GOOGLE_CHROME_BUILD) | 2092 #if defined(GOOGLE_CHROME_BUILD) |
2080 // The pre-read experiment is Windows and Google Chrome specific. | 2093 // The pre-read experiment is Windows and Google Chrome specific. |
2081 scoped_ptr<base::Environment> env(base::Environment::Create()); | 2094 scoped_ptr<base::Environment> env(base::Environment::Create()); |
2082 | 2095 |
2083 // Only record the sub-histogram result if the experiment is running | 2096 // Only record the sub-histogram result if the experiment is running |
2084 // (environment variable is set, and valid). | 2097 // (environment variable is set, and valid). |
2085 std::string pre_read; | 2098 std::string pre_read; |
2086 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && | 2099 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && |
2087 (pre_read == "0" || pre_read == "1")) { | 2100 (pre_read == "0" || pre_read == "1")) { |
2088 std::string uma_name(name); | 2101 std::string uma_name(name); |
2089 uma_name += "_PreRead"; | 2102 uma_name += "_PreRead"; |
2090 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | 2103 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
2091 AddPreReadHistogramTime(uma_name.c_str(), time); | 2104 AddPreReadHistogramTime(uma_name.c_str(), time); |
2092 } | 2105 } |
2093 #endif | 2106 #endif |
2094 #endif | 2107 #endif |
2095 } | 2108 } |
OLD | NEW |