[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 1 | // Copyright (c) 2010 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" |
| 10 | #include "base/field_trial.h" |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 11 | #include "base/scoped_ptr.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 12 | #include "base/tracked_objects.h" |
| 13 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 14 | class ChromeThread; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 15 | class CommandLine; |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 16 | class HighResolutionTimerManager; |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 17 | struct MainFunctionParams; |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 18 | class MessageLoop; |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 19 | class MetricsService; |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 20 | class SystemMonitor; |
| 21 | |
| 22 | namespace net { |
| 23 | class NetworkChangeNotifier; |
| 24 | } |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 25 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 26 | // BrowserMainParts: |
| 27 | // This class contains different "stages" to be executed in |BrowserMain()|, |
| 28 | // mostly initialization. This is made into a class rather than just functions |
| 29 | // so each stage can create and maintain state. Each part is represented by a |
| 30 | // single method (e.g., "EarlyInitialization()"), which does the following: |
| 31 | // - calls a method (e.g., "PreEarlyInitialization()") which individual |
| 32 | // platforms can override to provide platform-specific code which is to be |
| 33 | // executed before the common code; |
| 34 | // - calls various methods for things common to all platforms (for that given |
| 35 | // stage); and |
| 36 | // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific |
| 37 | // code to be called after the common code. |
| 38 | // As indicated above, platforms should override the default "Pre...()" and |
| 39 | // "Post...()" methods when necessary; they need not call the superclass's |
| 40 | // implementation (which is empty). |
| 41 | // |
| 42 | // Parts: |
| 43 | // - EarlyInitialization: things which should be done as soon as possible on |
| 44 | // program start (such as setting up signal handlers) and things to be done |
| 45 | // at some generic time before the start of the main message loop. |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 46 | // - MainMessageLoopStart: things beginning with the start of the main message |
| 47 | // loop and ending with initialization of the main thread; platform-specific |
| 48 | // things which should be done immediately before the start of the main |
| 49 | // message loop should go in |PreMainMessageLoopStart()|. |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 50 | // - (more to come) |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 51 | // |
| 52 | // How to add stuff (to existing parts): |
| 53 | // - Figure out when your new code should be executed. What must happen |
| 54 | // before/after your code is executed? Are there performance reasons for |
| 55 | // running your code at a particular time? Document these things! |
| 56 | // - Split out any platform-specific bits. Please avoid #ifdefs it at all |
| 57 | // possible. You have two choices for platform-specific code: (1) Execute it |
| 58 | // from one of the platform-specific |Pre/Post...()| methods; do this if the |
| 59 | // code is unique to a platform type. Or (2) execute it from one of the |
| 60 | // "parts" (e.g., |EarlyInitialization()|) and provide platform-specific |
| 61 | // implementations of your code (in a virtual method); do this if you need to |
| 62 | // provide different implementations across most/all platforms. |
| 63 | // - Unless your new code is just one or two lines, put it into a separate |
| 64 | // method with a well-defined purpose. (Likewise, if you're adding to an |
| 65 | // existing chunk which makes it longer than one or two lines, please move |
| 66 | // the code out into a separate method.) |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 67 | class BrowserMainParts { |
| 68 | public: |
| 69 | // This static method is to be implemented by each platform and should |
| 70 | // instantiate the appropriate subclass. |
| 71 | static BrowserMainParts* CreateBrowserMainParts( |
| 72 | const MainFunctionParams& parameters); |
| 73 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 74 | virtual ~BrowserMainParts(); |
| 75 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 76 | // Parts to be called by |BrowserMain()|. |
| 77 | void EarlyInitialization(); |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 78 | void MainMessageLoopStart(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 79 | |
| 80 | protected: |
| 81 | explicit BrowserMainParts(const MainFunctionParams& parameters); |
| 82 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 83 | // Accessors for data members (below) ---------------------------------------- |
| 84 | const MainFunctionParams& parameters() const { |
| 85 | return parameters_; |
| 86 | } |
| 87 | const CommandLine& parsed_command_line() const { |
| 88 | return parsed_command_line_; |
| 89 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 90 | MessageLoop& main_message_loop() const { |
| 91 | return *main_message_loop_; |
| 92 | } |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 93 | |
[email protected] | c1275ae | 2010-07-12 17:40:49 | [diff] [blame] | 94 | // Methods to be overridden to provide platform-specific code; these |
| 95 | // correspond to the "parts" above. |
| 96 | virtual void PreEarlyInitialization() {} |
| 97 | virtual void PostEarlyInitialization() {} |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 98 | virtual void PreMainMessageLoopStart() {} |
| 99 | virtual void PostMainMessageLoopStart() {} |
[email protected] | c1275ae | 2010-07-12 17:40:49 | [diff] [blame] | 100 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 101 | private: |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 102 | // Methods for |EarlyInitialization()| --------------------------------------- |
| 103 | |
| 104 | // A/B test for the maximum number of persistent connections per host. |
| 105 | void ConnectionFieldTrial(); |
| 106 | |
| 107 | // A/B test for determining a value for unused socket timeout. |
| 108 | void SocketTimeoutFieldTrial(); |
| 109 | |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 110 | // A/B test for the maximum number of connections per proxy server. |
| 111 | void ProxyConnectionsFieldTrial(); |
| 112 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 113 | // A/B test for spdy when --use-spdy not set. |
| 114 | void SpdyFieldTrial(); |
| 115 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 116 | // A/B test for prefetching with --(enable|disable)-prefetch not set. |
| 117 | void PrefetchFieldTrial(); |
| 118 | |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame^] | 119 | // A/B test for automatically establishing a backup TCP connection when a |
| 120 | // specified timeout value is reached. |
| 121 | void ConnectBackupJobsFieldTrial(); |
| 122 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 123 | // Used to initialize NSPR where appropriate. |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 124 | virtual void InitializeSSL() = 0; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 125 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 126 | // Methods for |MainMessageLoopStart()| -------------------------------------- |
| 127 | |
| 128 | void InitializeMainThread(); |
| 129 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 130 | // Members initialized on construction --------------------------------------- |
| 131 | |
| 132 | const MainFunctionParams& parameters_; |
| 133 | const CommandLine& parsed_command_line_; |
| 134 | |
| 135 | #if defined(TRACK_ALL_TASK_OBJECTS) |
| 136 | // Creating this object starts tracking the creation and deletion of Task |
| 137 | // instance. This MUST be done before main_message_loop, so that it is |
| 138 | // destroyed after the main_message_loop. |
| 139 | tracked_objects::AutoTracking tracking_objects_; |
| 140 | #endif |
| 141 | |
| 142 | // Statistical testing infrastructure for the entire browser. |
| 143 | FieldTrialList field_trial_; |
| 144 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 145 | // Members initialized in |MainMessageLoopStart()| --------------------------- |
| 146 | scoped_ptr<MessageLoop> main_message_loop_; |
| 147 | scoped_ptr<SystemMonitor> system_monitor_; |
| 148 | scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_; |
| 149 | scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 150 | scoped_ptr<ChromeThread> main_thread_; |
| 151 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 152 | DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); |
| 153 | }; |
| 154 | |
| 155 | |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 156 | // Perform platform-specific work that needs to be done after the main event |
| 157 | // loop has ended. |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 158 | void DidEndMainMessageLoop(); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 159 | |
| 160 | // Records the conditions that can prevent Breakpad from generating and |
| 161 | // sending crash reports. The presence of a Breakpad handler (after |
| 162 | // attempting to initialize crash reporting) and the presence of a debugger |
| 163 | // are registered with the UMA metrics service. |
| 164 | void RecordBreakpadStatusUMA(MetricsService* metrics); |
| 165 | |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 166 | // Displays a warning message if some minimum level of OS support is not |
| 167 | // present on the current platform. |
| 168 | void WarnAboutMinimumSystemRequirements(); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 169 | |
| 170 | #endif // CHROME_BROWSER_BROWSER_MAIN_H_ |