[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) |
51 | class BrowserMainParts { | ||||
52 | public: | ||||
53 | // This static method is to be implemented by each platform and should | ||||
54 | // instantiate the appropriate subclass. | ||||
55 | static BrowserMainParts* CreateBrowserMainParts( | ||||
56 | const MainFunctionParams& parameters); | ||||
57 | |||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 58 | virtual ~BrowserMainParts(); |
59 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 60 | // Parts to be called by |BrowserMain()|. |
61 | void EarlyInitialization(); | ||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 62 | void MainMessageLoopStart(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 63 | |
64 | protected: | ||||
65 | explicit BrowserMainParts(const MainFunctionParams& parameters); | ||||
66 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 67 | // Accessors for data members (below) ---------------------------------------- |
68 | const MainFunctionParams& parameters() const { | ||||
69 | return parameters_; | ||||
70 | } | ||||
71 | const CommandLine& parsed_command_line() const { | ||||
72 | return parsed_command_line_; | ||||
73 | } | ||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 74 | MessageLoop& main_message_loop() const { |
75 | return *main_message_loop_; | ||||
76 | } | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 77 | |
[email protected] | c1275ae | 2010-07-12 17:40:49 | [diff] [blame] | 78 | // Methods to be overridden to provide platform-specific code; these |
79 | // correspond to the "parts" above. | ||||
80 | virtual void PreEarlyInitialization() {} | ||||
81 | virtual void PostEarlyInitialization() {} | ||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 82 | virtual void PreMainMessageLoopStart() {} |
83 | virtual void PostMainMessageLoopStart() {} | ||||
[email protected] | c1275ae | 2010-07-12 17:40:49 | [diff] [blame] | 84 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 85 | private: |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 86 | // Methods for |EarlyInitialization()| --------------------------------------- |
87 | |||||
88 | // A/B test for the maximum number of persistent connections per host. | ||||
89 | void ConnectionFieldTrial(); | ||||
90 | |||||
91 | // A/B test for determining a value for unused socket timeout. | ||||
92 | void SocketTimeoutFieldTrial(); | ||||
93 | |||||
94 | // A/B test for spdy when --use-spdy not set. | ||||
95 | void SpdyFieldTrial(); | ||||
96 | |||||
97 | // Used to initialize NSPR where appropriate. | ||||
98 | void InitializeSSL(); | ||||
99 | |||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 100 | // Methods for |MainMessageLoopStart()| -------------------------------------- |
101 | |||||
102 | void InitializeMainThread(); | ||||
103 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 104 | // Members initialized on construction --------------------------------------- |
105 | |||||
106 | const MainFunctionParams& parameters_; | ||||
107 | const CommandLine& parsed_command_line_; | ||||
108 | |||||
109 | #if defined(TRACK_ALL_TASK_OBJECTS) | ||||
110 | // Creating this object starts tracking the creation and deletion of Task | ||||
111 | // instance. This MUST be done before main_message_loop, so that it is | ||||
112 | // destroyed after the main_message_loop. | ||||
113 | tracked_objects::AutoTracking tracking_objects_; | ||||
114 | #endif | ||||
115 | |||||
116 | // Statistical testing infrastructure for the entire browser. | ||||
117 | FieldTrialList field_trial_; | ||||
118 | |||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame^] | 119 | // Members initialized in |MainMessageLoopStart()| --------------------------- |
120 | scoped_ptr<MessageLoop> main_message_loop_; | ||||
121 | scoped_ptr<SystemMonitor> system_monitor_; | ||||
122 | scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_; | ||||
123 | scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | ||||
124 | scoped_ptr<ChromeThread> main_thread_; | ||||
125 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 126 | DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); |
127 | }; | ||||
128 | |||||
129 | |||||
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 130 | // Perform platform-specific work that needs to be done after the main event |
131 | // loop has ended. | ||||
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 132 | void DidEndMainMessageLoop(); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 133 | |
134 | // Records the conditions that can prevent Breakpad from generating and | ||||
135 | // sending crash reports. The presence of a Breakpad handler (after | ||||
136 | // attempting to initialize crash reporting) and the presence of a debugger | ||||
137 | // are registered with the UMA metrics service. | ||||
138 | void RecordBreakpadStatusUMA(MetricsService* metrics); | ||||
139 | |||||
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 140 | // Displays a warning message if some minimum level of OS support is not |
141 | // present on the current platform. | ||||
142 | void WarnAboutMinimumSystemRequirements(); | ||||
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 143 | |
144 | #endif // CHROME_BROWSER_BROWSER_MAIN_H_ |