[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_ |
| 7 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame^] | 8 | #include "base/basictypes.h" |
| 9 | #include "base/field_trial.h" |
| 10 | #include "base/tracked_objects.h" |
| 11 | |
| 12 | class CommandLine; |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 13 | struct MainFunctionParams; |
| 14 | class MetricsService; |
| 15 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame^] | 16 | // BrowserMainParts: |
| 17 | // This class contains different "stages" to be executed in |BrowserMain()|, |
| 18 | // mostly initialization. This is made into a class rather than just functions |
| 19 | // so each stage can create and maintain state. Each part is represented by a |
| 20 | // single method (e.g., "EarlyInitialization()"), which does the following: |
| 21 | // - calls a method (e.g., "PreEarlyInitialization()") which individual |
| 22 | // platforms can override to provide platform-specific code which is to be |
| 23 | // executed before the common code; |
| 24 | // - calls various methods for things common to all platforms (for that given |
| 25 | // stage); and |
| 26 | // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific |
| 27 | // code to be called after the common code. |
| 28 | // As indicated above, platforms should override the default "Pre...()" and |
| 29 | // "Post...()" methods when necessary; they need not call the superclass's |
| 30 | // implementation (which is empty). |
| 31 | // |
| 32 | // Parts: |
| 33 | // - EarlyInitialization: things which should be done as soon as possible on |
| 34 | // program start (such as setting up signal handlers) and things to be done |
| 35 | // at some generic time before the start of the main message loop. |
| 36 | // - (more to come) |
| 37 | class BrowserMainParts { |
| 38 | public: |
| 39 | // This static method is to be implemented by each platform and should |
| 40 | // instantiate the appropriate subclass. |
| 41 | static BrowserMainParts* CreateBrowserMainParts( |
| 42 | const MainFunctionParams& parameters); |
| 43 | |
| 44 | // Parts to be called by |BrowserMain()|. |
| 45 | void EarlyInitialization(); |
| 46 | |
| 47 | // TODO(viettrungluu): This currently contains (POSIX) initialization done |
| 48 | // later than "EarlyInitialization()" but dependent on it. Once the |
| 49 | // refactoring includes that later stage, this should be put in some more |
| 50 | // generic platform-dependent method. |
| 51 | void TemporaryPosix_1() {} |
| 52 | |
| 53 | protected: |
| 54 | explicit BrowserMainParts(const MainFunctionParams& parameters); |
| 55 | |
| 56 | // Methods to be overridden to provide platform-specific code; these |
| 57 | // correspond to the "parts" above. |
| 58 | virtual void PreEarlyInitialization() {} |
| 59 | virtual void PostEarlyInitialization() {} |
| 60 | |
| 61 | // Accessors for data members (below) ---------------------------------------- |
| 62 | const MainFunctionParams& parameters() const { |
| 63 | return parameters_; |
| 64 | } |
| 65 | const CommandLine& parsed_command_line() const { |
| 66 | return parsed_command_line_; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | // Methods for |EarlyInitialization()| --------------------------------------- |
| 71 | |
| 72 | // A/B test for the maximum number of persistent connections per host. |
| 73 | void ConnectionFieldTrial(); |
| 74 | |
| 75 | // A/B test for determining a value for unused socket timeout. |
| 76 | void SocketTimeoutFieldTrial(); |
| 77 | |
| 78 | // A/B test for spdy when --use-spdy not set. |
| 79 | void SpdyFieldTrial(); |
| 80 | |
| 81 | // Used to initialize NSPR where appropriate. |
| 82 | void InitializeSSL(); |
| 83 | |
| 84 | // Members initialized on construction --------------------------------------- |
| 85 | |
| 86 | const MainFunctionParams& parameters_; |
| 87 | const CommandLine& parsed_command_line_; |
| 88 | |
| 89 | #if defined(TRACK_ALL_TASK_OBJECTS) |
| 90 | // Creating this object starts tracking the creation and deletion of Task |
| 91 | // instance. This MUST be done before main_message_loop, so that it is |
| 92 | // destroyed after the main_message_loop. |
| 93 | tracked_objects::AutoTracking tracking_objects_; |
| 94 | #endif |
| 95 | |
| 96 | // Statistical testing infrastructure for the entire browser. |
| 97 | FieldTrialList field_trial_; |
| 98 | |
| 99 | DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); |
| 100 | }; |
| 101 | |
| 102 | |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 103 | // Perform platform-specific work that needs to be done before the main |
| 104 | // message loop is created, initialized, and entered. |
| 105 | void WillInitializeMainMessageLoop(const MainFunctionParams& parameters); |
| 106 | |
| 107 | // Perform platform-specific work that needs to be done after the main event |
| 108 | // loop has ended. |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 109 | void DidEndMainMessageLoop(); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 110 | |
| 111 | // Records the conditions that can prevent Breakpad from generating and |
| 112 | // sending crash reports. The presence of a Breakpad handler (after |
| 113 | // attempting to initialize crash reporting) and the presence of a debugger |
| 114 | // are registered with the UMA metrics service. |
| 115 | void RecordBreakpadStatusUMA(MetricsService* metrics); |
| 116 | |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 117 | // Displays a warning message if some minimum level of OS support is not |
| 118 | // present on the current platform. |
| 119 | void WarnAboutMinimumSystemRequirements(); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 120 | |
| 121 | #endif // CHROME_BROWSER_BROWSER_MAIN_H_ |