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