OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_BROWSER_MAIN_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_MAIN_H_ |
6 #define CONTENT_BROWSER_BROWSER_MAIN_H_ | 6 #define CONTENT_BROWSER_BROWSER_MAIN_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | |
jam
2011/10/24 19:36:00
nit: not needed, also most of the forward declares
stevenjb
2011/10/25 02:51:04
Done.
| |
10 | |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 | 13 |
13 class BrowserThread; | 14 class BrowserThread; |
14 class CommandLine; | 15 class CommandLine; |
15 class HighResolutionTimerManager; | 16 class HighResolutionTimerManager; |
16 class MessageLoop; | 17 class MessageLoop; |
17 struct MainFunctionParams; | 18 struct MainFunctionParams; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class SystemMonitor; | 21 class SystemMonitor; |
21 } | 22 } |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 class NetworkChangeNotifier; | 25 class NetworkChangeNotifier; |
25 } | 26 } |
26 | 27 |
27 namespace content { | 28 namespace content { |
28 | 29 |
29 // BrowserMainParts: | |
30 // This class contains different "stages" to be executed in |BrowserMain()|, | |
jam
2011/10/24 19:36:00
this is a lot of nice comments, why remove it all?
stevenjb
2011/10/25 02:51:04
This got moved into browser_main.cc, but should ha
| |
31 // mostly initialization. This is made into a class rather than just functions | |
32 // so each stage can create and maintain state. Each part is represented by a | |
33 // single method (e.g., "EarlyInitialization()"), which does the following: | |
34 // - calls a method (e.g., "PreEarlyInitialization()") which individual | |
35 // platforms can override to provide platform-specific code which is to be | |
36 // executed before the common code; | |
37 // - calls various methods for things common to all platforms (for that given | |
38 // stage); and | |
39 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific | |
40 // code to be called after the common code. | |
41 // As indicated above, platforms should override the default "Pre...()" and | |
42 // "Post...()" methods when necessary; they need not call the superclass's | |
43 // implementation (which is empty). | |
44 // | |
45 // Parts: | |
46 // - EarlyInitialization: things which should be done as soon as possible on | |
47 // program start (such as setting up signal handlers) and things to be done | |
48 // at some generic time before the start of the main message loop. | |
49 // - MainMessageLoopStart: things beginning with the start of the main message | |
50 // loop and ending with initialization of the main thread; platform-specific | |
51 // things which should be done immediately before the start of the main | |
52 // message loop should go in |PreMainMessageLoopStart()|. | |
53 // - (more to come) | |
54 // | |
55 // How to add stuff (to existing parts): | |
56 // - Figure out when your new code should be executed. What must happen | |
57 // before/after your code is executed? Are there performance reasons for | |
58 // running your code at a particular time? Document these things! | |
59 // - Split out any platform-specific bits. Please avoid #ifdefs it at all | |
60 // possible. You have two choices for platform-specific code: (1) Execute it | |
61 // from one of the platform-specific |Pre/Post...()| methods; do this if the | |
62 // code is unique to a platform type. Or (2) execute it from one of the | |
63 // "parts" (e.g., |EarlyInitialization()|) and provide platform-specific | |
64 // implementations of your code (in a virtual method); do this if you need to | |
65 // provide different implementations across most/all platforms. | |
66 // - Unless your new code is just one or two lines, put it into a separate | |
67 // method with a well-defined purpose. (Likewise, if you're adding to an | |
68 // existing chunk which makes it longer than one or two lines, please move | |
69 // the code out into a separate method.) | |
70 class CONTENT_EXPORT BrowserMainParts { | |
71 public: | |
72 explicit BrowserMainParts(const MainFunctionParams& parameters); | |
73 virtual ~BrowserMainParts(); | |
74 | |
75 // Parts to be called by |BrowserMain()|. | |
76 void EarlyInitialization(); | |
77 void InitializeToolkit(); | |
78 void MainMessageLoopStart(); | |
79 void RunMainMessageLoopParts(); | |
80 | |
81 int result_code() const { return result_code_; } | |
82 | |
83 protected: | |
84 // Methods to be overridden to provide platform-specific code; these | |
85 // correspond to the "parts" above. | |
86 virtual void PreEarlyInitialization(); | |
87 virtual void PostEarlyInitialization(); | |
88 virtual void PreMainMessageLoopStart(); | |
89 virtual void PostMainMessageLoopStart(); | |
90 virtual void PreMainMessageLoopRun(); | |
91 virtual void MainMessageLoopRun(); | |
92 virtual void PostMainMessageLoopRun(); | |
93 | |
94 // Allows an embedder to do any extra toolkit initialization. | |
95 virtual void ToolkitInitialized(); | |
96 | |
97 // Accessors for data members (below) ---------------------------------------- | |
98 const MainFunctionParams& parameters() const { | |
99 return parameters_; | |
100 } | |
101 const CommandLine& parsed_command_line() const { | |
102 return parsed_command_line_; | |
103 } | |
104 MessageLoop& main_message_loop() const { | |
105 return *main_message_loop_; | |
106 } | |
107 void set_result_code(int result_code) { result_code_ = result_code; } | |
108 | |
109 private: | |
110 void InitializeMainThread(); | |
111 | |
112 // Members initialized on construction --------------------------------------- | |
113 | |
114 const MainFunctionParams& parameters_; | |
115 const CommandLine& parsed_command_line_; | |
116 int result_code_; | |
117 | |
118 // Members initialized in |MainMessageLoopStart()| --------------------------- | |
119 scoped_ptr<MessageLoop> main_message_loop_; | |
120 scoped_ptr<base::SystemMonitor> system_monitor_; | |
121 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_; | |
122 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | |
123 scoped_ptr<BrowserThread> main_thread_; | |
124 | |
125 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); | |
126 }; | |
127 | |
128 bool ExitedMainMessageLoop(); | 30 bool ExitedMainMessageLoop(); |
129 | 31 |
130 } // namespace content | 32 } // namespace content |
131 | 33 |
132 CONTENT_EXPORT int BrowserMain(const MainFunctionParams& parameters); | 34 CONTENT_EXPORT int BrowserMain(const MainFunctionParams& parameters); |
133 | 35 |
134 #endif // CONTENT_BROWSER_BROWSER_MAIN_H_ | 36 #endif // CONTENT_BROWSER_BROWSER_MAIN_H_ |
37 | |
38 // LocalWords: BrowserMain BrowserMainLoop BrowserParts MainMessageLoopRun | |
jam
2011/10/24 19:36:00
?
stevenjb
2011/10/25 02:51:04
wtf? maybe got added when I spellchecked the comme
| |
39 // LocalWords: AddParts EarlyInitialization PreEarlyInitialization Pre Gtk | |
40 // LocalWords: PostEarlyInitialization superclass's MainMessageLoopStart | |
41 // LocalWords: PreMainMessageLoopStart RunMainMessageLoopParts ifdefs | |
OLD | NEW |