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_PUBLIC_BROWSER_BROWSER_MAIN_PARTS_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_BROWSER_MAIN_PARTS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "content/common/content_export.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 // This class contains different "stages" to be executed by |BrowserMain()|, |
| 15 // Each stage is represented by a single BrowserMainParts method, called from |
| 16 // the corresponding method in |BrowserMainLoop| (e.g., EarlyInitialization()) |
| 17 // which does the following: |
| 18 // - calls a method (e.g., "PreEarlyInitialization()") for each member of |
| 19 // |parts_|. Parts will implement platform or tookit specific code for that |
| 20 // stage. |
| 21 // - calls various methods for things common to all platforms (for that stage). |
| 22 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific |
| 23 // code to be called after the common code. |
| 24 // |
| 25 // Stages: |
| 26 // - EarlyInitialization: things which should be done as soon as possible on |
| 27 // program start (such as setting up signal handlers) and things to be done |
| 28 // at some generic time before the start of the main message loop. |
| 29 // - MainMessageLoopStart: things beginning with the start of the main message |
| 30 // loop and ending with initialization of the main thread; platform-specific |
| 31 // things which should be done immediately before the start of the main |
| 32 // message loop should go in |PreMainMessageLoopStart()|. |
| 33 // - RunMainMessageLoopParts: things to be done before and after invoking the |
| 34 // main message loop run method (e.g. MessageLoopForUI::current()->Run()). |
| 35 // |
| 36 // How to add stuff (to existing parts): |
| 37 // - Figure out when your new code should be executed. What must happen |
| 38 // before/after your code is executed? Are there performance reasons for |
| 39 // running your code at a particular time? Document these things! |
| 40 // - Split out any platform-specific bits. Please avoid #ifdefs it at all |
| 41 // possible. You have two choices for platform-specific code: (1) Execute it |
| 42 // from one of the platform-specific |Pre/Post...()| methods; do this if the |
| 43 // code is unique to a platform type. Or (2) execute it from one of the |
| 44 // "parts" (e.g., |EarlyInitialization()|) and provide platform-specific |
| 45 // implementations of your code (in a virtual method); do this if you need to |
| 46 // provide different implementations across most/all platforms. |
| 47 // - Unless your new code is just one or two lines, put it into a separate |
| 48 // method with a well-defined purpose. (Likewise, if you're adding to an |
| 49 // existing chunk which makes it longer than one or two lines, please move |
| 50 // the code out into a separate method.) |
| 51 // |
| 52 // There can be any number of "Parts". These should be constructed in |
| 53 // ContentBrowserClient::CreateBrowserMainParts. Each stage will be called |
| 54 // for each part in the order it was added. Destruction is in the inverse order. |
| 55 class CONTENT_EXPORT BrowserMainParts { |
| 56 public: |
| 57 BrowserMainParts() {} |
| 58 virtual ~BrowserMainParts() {} |
| 59 |
| 60 virtual void PreEarlyInitialization() = 0; |
| 61 |
| 62 virtual void PostEarlyInitialization() = 0; |
| 63 |
| 64 virtual void PreMainMessageLoopStart() = 0; |
| 65 |
| 66 // Allows an embedder to do any extra toolkit initialization. |
| 67 virtual void ToolkitInitialized() = 0; |
| 68 |
| 69 virtual void PostMainMessageLoopStart() = 0; |
| 70 |
| 71 virtual void PreMainMessageLoopRun() = 0; |
| 72 |
| 73 // Returns true if the message loop was run, false otherwise. |
| 74 // May set |result_code|, which will be returned by |BrowserMain()|. |
| 75 // If no BrowserMainParts implementations return true, the default |
| 76 // implementation will be run. |
| 77 virtual bool MainMessageLoopRun(int* result_code) = 0; |
| 78 |
| 79 virtual void PostMainMessageLoopRun() = 0; |
| 80 |
| 81 private: |
| 82 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); |
| 83 }; |
| 84 |
| 85 } // namespace content |
| 86 |
| 87 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_MAIN_PARTS_H_ |
OLD | NEW |