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