Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/browser_main.h

Issue 2931007: BrowserMain() refactoring, part 2. (Closed)
Patch Set: Updated per brettw and merged ToT. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/browser_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/field_trial.h" 10 #include "base/field_trial.h"
11 #include "base/scoped_ptr.h"
11 #include "base/tracked_objects.h" 12 #include "base/tracked_objects.h"
12 13
14 class ChromeThread;
13 class CommandLine; 15 class CommandLine;
16 class HighResolutionTimerManager;
14 struct MainFunctionParams; 17 struct MainFunctionParams;
18 class MessageLoop;
15 class MetricsService; 19 class MetricsService;
20 class SystemMonitor;
21
22 namespace net {
23 class NetworkChangeNotifier;
24 }
16 25
17 // BrowserMainParts: 26 // BrowserMainParts:
18 // This class contains different "stages" to be executed in |BrowserMain()|, 27 // This class contains different "stages" to be executed in |BrowserMain()|,
19 // mostly initialization. This is made into a class rather than just functions 28 // mostly initialization. This is made into a class rather than just functions
20 // so each stage can create and maintain state. Each part is represented by a 29 // so each stage can create and maintain state. Each part is represented by a
21 // single method (e.g., "EarlyInitialization()"), which does the following: 30 // single method (e.g., "EarlyInitialization()"), which does the following:
22 // - calls a method (e.g., "PreEarlyInitialization()") which individual 31 // - calls a method (e.g., "PreEarlyInitialization()") which individual
23 // platforms can override to provide platform-specific code which is to be 32 // platforms can override to provide platform-specific code which is to be
24 // executed before the common code; 33 // executed before the common code;
25 // - calls various methods for things common to all platforms (for that given 34 // - calls various methods for things common to all platforms (for that given
26 // stage); and 35 // stage); and
27 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific 36 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
28 // code to be called after the common code. 37 // code to be called after the common code.
29 // As indicated above, platforms should override the default "Pre...()" and 38 // As indicated above, platforms should override the default "Pre...()" and
30 // "Post...()" methods when necessary; they need not call the superclass's 39 // "Post...()" methods when necessary; they need not call the superclass's
31 // implementation (which is empty). 40 // implementation (which is empty).
32 // 41 //
33 // Parts: 42 // Parts:
34 // - EarlyInitialization: things which should be done as soon as possible on 43 // - EarlyInitialization: things which should be done as soon as possible on
35 // program start (such as setting up signal handlers) and things to be done 44 // program start (such as setting up signal handlers) and things to be done
36 // at some generic time before the start of the main message loop. 45 // at some generic time before the start of the main message loop.
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()|.
37 // - (more to come) 50 // - (more to come)
38 class BrowserMainParts { 51 class BrowserMainParts {
39 public: 52 public:
40 // This static method is to be implemented by each platform and should 53 // This static method is to be implemented by each platform and should
41 // instantiate the appropriate subclass. 54 // instantiate the appropriate subclass.
42 static BrowserMainParts* CreateBrowserMainParts( 55 static BrowserMainParts* CreateBrowserMainParts(
43 const MainFunctionParams& parameters); 56 const MainFunctionParams& parameters);
44 57
58 virtual ~BrowserMainParts();
59
45 // Parts to be called by |BrowserMain()|. 60 // Parts to be called by |BrowserMain()|.
46 void EarlyInitialization(); 61 void EarlyInitialization();
47 62 void MainMessageLoopStart();
48 // TODO(viettrungluu): This currently contains (POSIX) initialization done
49 // later than "EarlyInitialization()" but dependent on it. Once the
50 // refactoring includes that later stage, this should be put in some more
51 // generic platform-dependent method.
52 virtual void TemporaryPosix_1() {}
53 63
54 protected: 64 protected:
55 explicit BrowserMainParts(const MainFunctionParams& parameters); 65 explicit BrowserMainParts(const MainFunctionParams& parameters);
56 66
57 // Accessors for data members (below) ---------------------------------------- 67 // Accessors for data members (below) ----------------------------------------
58 const MainFunctionParams& parameters() const { 68 const MainFunctionParams& parameters() const {
59 return parameters_; 69 return parameters_;
60 } 70 }
61 const CommandLine& parsed_command_line() const { 71 const CommandLine& parsed_command_line() const {
62 return parsed_command_line_; 72 return parsed_command_line_;
63 } 73 }
74 MessageLoop& main_message_loop() const {
75 return *main_message_loop_;
76 }
64 77
65 private:
66 // Methods to be overridden to provide platform-specific code; these 78 // Methods to be overridden to provide platform-specific code; these
67 // correspond to the "parts" above. 79 // correspond to the "parts" above.
68 virtual void PreEarlyInitialization() {} 80 virtual void PreEarlyInitialization() {}
69 virtual void PostEarlyInitialization() {} 81 virtual void PostEarlyInitialization() {}
82 virtual void PreMainMessageLoopStart() {}
83 virtual void PostMainMessageLoopStart() {}
70 84
85 private:
71 // Methods for |EarlyInitialization()| --------------------------------------- 86 // Methods for |EarlyInitialization()| ---------------------------------------
72 87
73 // A/B test for the maximum number of persistent connections per host. 88 // A/B test for the maximum number of persistent connections per host.
74 void ConnectionFieldTrial(); 89 void ConnectionFieldTrial();
75 90
76 // A/B test for determining a value for unused socket timeout. 91 // A/B test for determining a value for unused socket timeout.
77 void SocketTimeoutFieldTrial(); 92 void SocketTimeoutFieldTrial();
78 93
79 // A/B test for spdy when --use-spdy not set. 94 // A/B test for spdy when --use-spdy not set.
80 void SpdyFieldTrial(); 95 void SpdyFieldTrial();
81 96
82 // Used to initialize NSPR where appropriate. 97 // Used to initialize NSPR where appropriate.
83 void InitializeSSL(); 98 void InitializeSSL();
84 99
100 // Methods for |MainMessageLoopStart()| --------------------------------------
101
102 void InitializeMainThread();
103
85 // Members initialized on construction --------------------------------------- 104 // Members initialized on construction ---------------------------------------
86 105
87 const MainFunctionParams& parameters_; 106 const MainFunctionParams& parameters_;
88 const CommandLine& parsed_command_line_; 107 const CommandLine& parsed_command_line_;
89 108
90 #if defined(TRACK_ALL_TASK_OBJECTS) 109 #if defined(TRACK_ALL_TASK_OBJECTS)
91 // Creating this object starts tracking the creation and deletion of Task 110 // Creating this object starts tracking the creation and deletion of Task
92 // instance. This MUST be done before main_message_loop, so that it is 111 // instance. This MUST be done before main_message_loop, so that it is
93 // destroyed after the main_message_loop. 112 // destroyed after the main_message_loop.
94 tracked_objects::AutoTracking tracking_objects_; 113 tracked_objects::AutoTracking tracking_objects_;
95 #endif 114 #endif
96 115
97 // Statistical testing infrastructure for the entire browser. 116 // Statistical testing infrastructure for the entire browser.
98 FieldTrialList field_trial_; 117 FieldTrialList field_trial_;
99 118
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
100 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); 126 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
101 }; 127 };
102 128
103 129
104 // Perform platform-specific work that needs to be done before the main
105 // message loop is created, initialized, and entered.
106 void WillInitializeMainMessageLoop(const MainFunctionParams& parameters);
107
108 // Perform platform-specific work that needs to be done after the main event 130 // Perform platform-specific work that needs to be done after the main event
109 // loop has ended. 131 // loop has ended.
110 void DidEndMainMessageLoop(); 132 void DidEndMainMessageLoop();
111 133
112 // Records the conditions that can prevent Breakpad from generating and 134 // Records the conditions that can prevent Breakpad from generating and
113 // sending crash reports. The presence of a Breakpad handler (after 135 // sending crash reports. The presence of a Breakpad handler (after
114 // attempting to initialize crash reporting) and the presence of a debugger 136 // attempting to initialize crash reporting) and the presence of a debugger
115 // are registered with the UMA metrics service. 137 // are registered with the UMA metrics service.
116 void RecordBreakpadStatusUMA(MetricsService* metrics); 138 void RecordBreakpadStatusUMA(MetricsService* metrics);
117 139
118 // Displays a warning message if some minimum level of OS support is not 140 // Displays a warning message if some minimum level of OS support is not
119 // present on the current platform. 141 // present on the current platform.
120 void WarnAboutMinimumSystemRequirements(); 142 void WarnAboutMinimumSystemRequirements();
121 143
122 #endif // CHROME_BROWSER_BROWSER_MAIN_H_ 144 #endif // CHROME_BROWSER_BROWSER_MAIN_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698