| 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 #ifndef CHROME_BROWSER_BROWSER_MAIN_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_MAIN_H_ |
| 6 #define CHROME_BROWSER_BROWSER_MAIN_H_ | 6 #define CHROME_BROWSER_BROWSER_MAIN_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 13 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
| 13 #include "content/browser/browser_main.h" |
| 14 | 14 |
| 15 class BrowserThread; | 15 class FieldTrialSynchronizer; |
| 16 class CommandLine; | |
| 17 class HistogramSynchronizer; | 16 class HistogramSynchronizer; |
| 18 class FieldTrialSynchronizer; | |
| 19 class HighResolutionTimerManager; | |
| 20 struct MainFunctionParams; | |
| 21 class MessageLoop; | |
| 22 class MetricsService; | 17 class MetricsService; |
| 23 class PrefService; | 18 class PrefService; |
| 24 | 19 class ShutdownWatcherHelper; |
| 25 namespace base { | |
| 26 class SystemMonitor; | |
| 27 } | |
| 28 | |
| 29 namespace net { | |
| 30 class NetworkChangeNotifier; | |
| 31 } | |
| 32 | 20 |
| 33 namespace chrome_browser { | 21 namespace chrome_browser { |
| 34 // For use by ShowMissingLocaleMessageBox. | 22 // For use by ShowMissingLocaleMessageBox. |
| 35 extern const char kMissingLocaleDataTitle[]; | 23 extern const char kMissingLocaleDataTitle[]; |
| 36 extern const char kMissingLocaleDataMessage[]; | 24 extern const char kMissingLocaleDataMessage[]; |
| 37 } | 25 } |
| 38 | 26 |
| 39 // BrowserMainParts: | 27 class ChromeBrowserMainParts : public content::BrowserMainParts { |
| 40 // This class contains different "stages" to be executed in |BrowserMain()|, | |
| 41 // mostly initialization. This is made into a class rather than just functions | |
| 42 // so each stage can create and maintain state. Each part is represented by a | |
| 43 // single method (e.g., "EarlyInitialization()"), which does the following: | |
| 44 // - calls a method (e.g., "PreEarlyInitialization()") which individual | |
| 45 // platforms can override to provide platform-specific code which is to be | |
| 46 // executed before the common code; | |
| 47 // - calls various methods for things common to all platforms (for that given | |
| 48 // stage); and | |
| 49 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific | |
| 50 // code to be called after the common code. | |
| 51 // As indicated above, platforms should override the default "Pre...()" and | |
| 52 // "Post...()" methods when necessary; they need not call the superclass's | |
| 53 // implementation (which is empty). | |
| 54 // | |
| 55 // Parts: | |
| 56 // - EarlyInitialization: things which should be done as soon as possible on | |
| 57 // program start (such as setting up signal handlers) and things to be done | |
| 58 // at some generic time before the start of the main message loop. | |
| 59 // - MainMessageLoopStart: things beginning with the start of the main message | |
| 60 // loop and ending with initialization of the main thread; platform-specific | |
| 61 // things which should be done immediately before the start of the main | |
| 62 // message loop should go in |PreMainMessageLoopStart()|. | |
| 63 // - (more to come) | |
| 64 // | |
| 65 // How to add stuff (to existing parts): | |
| 66 // - Figure out when your new code should be executed. What must happen | |
| 67 // before/after your code is executed? Are there performance reasons for | |
| 68 // running your code at a particular time? Document these things! | |
| 69 // - Split out any platform-specific bits. Please avoid #ifdefs it at all | |
| 70 // possible. You have two choices for platform-specific code: (1) Execute it | |
| 71 // from one of the platform-specific |Pre/Post...()| methods; do this if the | |
| 72 // code is unique to a platform type. Or (2) execute it from one of the | |
| 73 // "parts" (e.g., |EarlyInitialization()|) and provide platform-specific | |
| 74 // implementations of your code (in a virtual method); do this if you need to | |
| 75 // provide different implementations across most/all platforms. | |
| 76 // - Unless your new code is just one or two lines, put it into a separate | |
| 77 // method with a well-defined purpose. (Likewise, if you're adding to an | |
| 78 // existing chunk which makes it longer than one or two lines, please move | |
| 79 // the code out into a separate method.) | |
| 80 class BrowserMainParts { | |
| 81 public: | 28 public: |
| 82 // This static method is to be implemented by each platform and should | 29 virtual ~ChromeBrowserMainParts(); |
| 83 // instantiate the appropriate subclass. | |
| 84 static BrowserMainParts* CreateBrowserMainParts( | |
| 85 const MainFunctionParams& parameters); | |
| 86 | |
| 87 virtual ~BrowserMainParts(); | |
| 88 | |
| 89 // Parts to be called by |BrowserMain()|. | |
| 90 void EarlyInitialization(); | |
| 91 void MainMessageLoopStart(); | |
| 92 | 30 |
| 93 // Constructs HistogramSynchronizer which gets released early (before | 31 // Constructs HistogramSynchronizer which gets released early (before |
| 94 // main_message_loop_). | 32 // main_message_loop_). |
| 95 void SetupHistogramSynchronizer(); | 33 void SetupHistogramSynchronizer(); |
| 96 | 34 |
| 97 // Constructs metrics service and does related initialization, including | 35 // Constructs metrics service and does related initialization, including |
| 98 // creation of field trials. Call only after labs have been converted to | 36 // creation of field trials. Call only after labs have been converted to |
| 99 // switches. | 37 // switches. |
| 100 MetricsService* SetupMetricsAndFieldTrials( | 38 MetricsService* SetupMetricsAndFieldTrials( |
| 101 const CommandLine& parsed_command_line, | 39 const CommandLine& parsed_command_line, |
| 102 PrefService* local_state); | 40 PrefService* local_state); |
| 103 | 41 |
| 104 protected: | 42 protected: |
| 105 explicit BrowserMainParts(const MainFunctionParams& parameters); | 43 explicit ChromeBrowserMainParts(const MainFunctionParams& parameters); |
| 106 | 44 |
| 107 // Accessors for data members (below) ---------------------------------------- | 45 virtual void PostMainMessageLoopStart() OVERRIDE; |
| 108 const MainFunctionParams& parameters() const { | 46 virtual void ToolkitInitialized() OVERRIDE; |
| 109 return parameters_; | |
| 110 } | |
| 111 const CommandLine& parsed_command_line() const { | |
| 112 return parsed_command_line_; | |
| 113 } | |
| 114 MessageLoop& main_message_loop() const { | |
| 115 return *main_message_loop_; | |
| 116 } | |
| 117 | 47 |
| 118 // Methods to be overridden to provide platform-specific code; these | 48 virtual int TemporaryContinue() OVERRIDE; |
| 119 // correspond to the "parts" above. | |
| 120 virtual void PreEarlyInitialization() {} | |
| 121 virtual void PostEarlyInitialization() {} | |
| 122 virtual void PreMainMessageLoopStart() {} | |
| 123 virtual void PostMainMessageLoopStart() {} | |
| 124 | 49 |
| 125 private: | 50 private: |
| 126 // Methods for |EarlyInitialization()| --------------------------------------- | 51 // Methods for |EarlyInitialization()| --------------------------------------- |
| 127 | 52 |
| 128 // A/B test for the maximum number of persistent connections per host. | 53 // A/B test for the maximum number of persistent connections per host. |
| 129 void ConnectionFieldTrial(); | 54 void ConnectionFieldTrial(); |
| 130 | 55 |
| 131 // A/B test for determining a value for unused socket timeout. | 56 // A/B test for determining a value for unused socket timeout. |
| 132 void SocketTimeoutFieldTrial(); | 57 void SocketTimeoutFieldTrial(); |
| 133 | 58 |
| 134 // A/B test for the maximum number of connections per proxy server. | 59 // A/B test for the maximum number of connections per proxy server. |
| 135 void ProxyConnectionsFieldTrial(); | 60 void ProxyConnectionsFieldTrial(); |
| 136 | 61 |
| 137 // A/B test for spdy when --use-spdy not set. | 62 // A/B test for spdy when --use-spdy not set. |
| 138 void SpdyFieldTrial(); | 63 void SpdyFieldTrial(); |
| 139 | 64 |
| 140 // A/B test for warmest socket vs. most recently used socket. | 65 // A/B test for warmest socket vs. most recently used socket. |
| 141 void WarmConnectionFieldTrial(); | 66 void WarmConnectionFieldTrial(); |
| 142 | 67 |
| 143 // A/B test for automatically establishing a backup TCP connection when a | 68 // A/B test for automatically establishing a backup TCP connection when a |
| 144 // specified timeout value is reached. | 69 // specified timeout value is reached. |
| 145 void ConnectBackupJobsFieldTrial(); | 70 void ConnectBackupJobsFieldTrial(); |
| 146 | 71 |
| 147 // A/B test for using a different host prefix in Google search suggest. | 72 // A/B test for using a different host prefix in Google search suggest. |
| 148 void SuggestPrefixFieldTrial(); | 73 void SuggestPrefixFieldTrial(); |
| 149 | 74 |
| 150 // Used to initialize NSPR where appropriate. | |
| 151 virtual void InitializeSSL() = 0; | |
| 152 | |
| 153 // Methods for |MainMessageLoopStart()| -------------------------------------- | |
| 154 | |
| 155 void InitializeMainThread(); | |
| 156 | |
| 157 // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- | 75 // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- |
| 158 | 76 |
| 159 static MetricsService* InitializeMetrics( | 77 static MetricsService* InitializeMetrics( |
| 160 const CommandLine& parsed_command_line, | 78 const CommandLine& parsed_command_line, |
| 161 const PrefService* local_state); | 79 const PrefService* local_state); |
| 162 | 80 |
| 163 // Add an invocation of your field trial init function to this method. | 81 // Add an invocation of your field trial init function to this method. |
| 164 void SetupFieldTrials(bool metrics_recording_enabled, | 82 void SetupFieldTrials(bool metrics_recording_enabled, |
| 165 bool proxy_policy_is_set); | 83 bool proxy_policy_is_set); |
| 166 | 84 |
| 167 // Members initialized on construction --------------------------------------- | 85 // Members initialized on construction --------------------------------------- |
| 168 | 86 |
| 169 const MainFunctionParams& parameters_; | 87 // Create ShutdownWatcherHelper object for watching jank during shutdown. |
| 170 const CommandLine& parsed_command_line_; | 88 // Please keep |shutdown_watcher| as the first object constructed, and hence |
| 89 // it is destroyed last. |
| 90 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_; |
| 171 | 91 |
| 172 #if defined(TRACK_ALL_TASK_OBJECTS) | 92 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 173 // Creating this object starts tracking the creation and deletion of Task | 93 // Creating this object starts tracking the creation and deletion of Task |
| 174 // instance. This MUST be done before main_message_loop, so that it is | 94 // instance. This MUST be done before main_message_loop, so that it is |
| 175 // destroyed after the main_message_loop. | 95 // destroyed after the main_message_loop. |
| 176 tracked_objects::AutoTracking tracking_objects_; | 96 tracked_objects::AutoTracking tracking_objects_; |
| 177 #endif | 97 #endif |
| 178 | 98 |
| 179 // Statistical testing infrastructure for the entire browser. NULL until | 99 // Statistical testing infrastructure for the entire browser. NULL until |
| 180 // SetupMetricsAndFieldTrials is called. | 100 // SetupMetricsAndFieldTrials is called. |
| 181 scoped_ptr<base::FieldTrialList> field_trial_list_; | 101 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 182 | 102 |
| 183 // Members initialized in |MainMessageLoopStart()| --------------------------- | |
| 184 scoped_ptr<MessageLoop> main_message_loop_; | |
| 185 scoped_ptr<base::SystemMonitor> system_monitor_; | |
| 186 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_; | |
| 187 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
| 188 scoped_ptr<BrowserThread> main_thread_; | |
| 189 | |
| 190 // Members initialized after / released before main_message_loop_ ------------ | 103 // Members initialized after / released before main_message_loop_ ------------ |
| 191 | 104 |
| 192 // Initialized in SetupHistogramSynchronizer. | 105 // Initialized in SetupHistogramSynchronizer. |
| 193 scoped_refptr<HistogramSynchronizer> histogram_synchronizer_; | 106 scoped_refptr<HistogramSynchronizer> histogram_synchronizer_; |
| 194 | 107 |
| 195 // Initialized in SetupMetricsAndFieldTrials. | 108 // Initialized in SetupMetricsAndFieldTrials. |
| 196 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; | 109 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; |
| 197 | 110 |
| 198 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket); | 111 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket); |
| 199 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random); | 112 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random); |
| 200 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid); | 113 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid); |
| 201 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); | 114 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts); |
| 202 }; | 115 }; |
| 203 | 116 |
| 204 | |
| 205 // Perform platform-specific work that needs to be done after the main event | |
| 206 // loop has ended. | |
| 207 void DidEndMainMessageLoop(); | |
| 208 | |
| 209 // Records the conditions that can prevent Breakpad from generating and | 117 // Records the conditions that can prevent Breakpad from generating and |
| 210 // sending crash reports. The presence of a Breakpad handler (after | 118 // sending crash reports. The presence of a Breakpad handler (after |
| 211 // attempting to initialize crash reporting) and the presence of a debugger | 119 // attempting to initialize crash reporting) and the presence of a debugger |
| 212 // are registered with the UMA metrics service. | 120 // are registered with the UMA metrics service. |
| 213 void RecordBreakpadStatusUMA(MetricsService* metrics); | 121 void RecordBreakpadStatusUMA(MetricsService* metrics); |
| 214 | 122 |
| 215 // Displays a warning message if some minimum level of OS support is not | 123 // Displays a warning message if some minimum level of OS support is not |
| 216 // present on the current platform. | 124 // present on the current platform. |
| 217 void WarnAboutMinimumSystemRequirements(); | 125 void WarnAboutMinimumSystemRequirements(); |
| 218 | 126 |
| 219 // Displays a warning message that we can't find any locale data files. | 127 // Displays a warning message that we can't find any locale data files. |
| 220 void ShowMissingLocaleMessageBox(); | 128 void ShowMissingLocaleMessageBox(); |
| 221 | 129 |
| 222 // Records the time from our process' startup to the present time in | 130 // Records the time from our process' startup to the present time in |
| 223 // the UMA histogram |metric_name|. | 131 // the UMA histogram |metric_name|. |
| 224 void RecordBrowserStartupTime(); | 132 void RecordBrowserStartupTime(); |
| 225 | 133 |
| 226 // Records a time value to an UMA histogram in the context of the | 134 // Records a time value to an UMA histogram in the context of the |
| 227 // PreReadExperiment field-trial. This also reports to the appropriate | 135 // PreReadExperiment field-trial. This also reports to the appropriate |
| 228 // sub-histogram (_PreRead(Enabled|Disabled)). | 136 // sub-histogram (_PreRead(Enabled|Disabled)). |
| 229 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time); | 137 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time); |
| 230 | 138 |
| 231 #endif // CHROME_BROWSER_BROWSER_MAIN_H_ | 139 #endif // CHROME_BROWSER_BROWSER_MAIN_H_ |
| OLD | NEW |