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