OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PUBLIC_BROWSER_BROWSER_MAIN_PARTS_H_ | 5 #ifndef IOS_WEB_PUBLIC_APP_WEB_MAIN_PARTS_H_ |
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_MAIN_PARTS_H_ | 6 #define IOS_WEB_PUBLIC_APP_WEB_MAIN_PARTS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "content/common/content_export.h" | |
10 | 9 |
11 namespace content { | 10 namespace web { |
12 | 11 |
13 // This class contains different "stages" to be executed by |BrowserMain()|, | 12 // This class contains different "stages" to be executed by |WebMain()|. |
14 // Each stage is represented by a single BrowserMainParts method, called from | 13 // Each stage is represented by a single WebMainParts method, called from |
15 // the corresponding method in |BrowserMainLoop| (e.g., EarlyInitialization()) | 14 // the corresponding method in |WebMainLoop| (e.g., EarlyInitialization()) |
16 // which does the following: | 15 // which does the following: |
17 // - calls a method (e.g., "PreEarlyInitialization()") which implements | 16 // - calls a method (e.g., "PreEarlyInitialization()") which implements |
18 // platform / tookit specific code for that stage. | 17 // platform / tookit specific code for that stage. |
19 // - calls various methods for things common to all platforms (for that stage). | 18 // - calls various methods for things common to all platforms (for that stage). |
20 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific | 19 // - calls a method (e.g., "PostEarlyInitialization()") for platform-specific |
21 // code to be called after the common code. | 20 // code to be called after the common code. |
22 // | 21 // |
23 // Stages: | 22 // Stages: |
24 // - EarlyInitialization: things which should be done as soon as possible on | 23 // - 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 | 24 // 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. | 25 // at some generic time before the start of the main message loop. |
27 // - MainMessageLoopStart: things beginning with the start of the main message | 26 // - MainMessageLoopStart: things beginning with the start of the main message |
28 // loop and ending with initialization of the main thread; platform-specific | 27 // loop and ending with initialization of the main thread; things which |
29 // things which should be done immediately before the start of the main | 28 // should be done immediately before the start of the main message loop |
30 // message loop should go in |PreMainMessageLoopStart()|. | 29 // should go in |PreMainMessageLoopStart()|. |
31 // - RunMainMessageLoopParts: things to be done before and after invoking the | 30 // - RunMainMessageLoopParts: things to be done before and after invoking the |
32 // main message loop run method (e.g. MessageLoopForUI::current()->Run()). | 31 // main message loop run method (e.g. MessageLoopForUI::current()->Run()). |
33 // | 32 // |
34 // How to add stuff (to existing parts): | 33 // How to add stuff (to existing parts): |
35 // - Figure out when your new code should be executed. What must happen | 34 // - Figure out when your new code should be executed. What must happen |
36 // before/after your code is executed? Are there performance reasons for | 35 // before/after your code is executed? Are there performance reasons for |
37 // running your code at a particular time? Document these things! | 36 // 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 | 37 // - 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 | 38 // 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 | 39 // existing chunk which makes it longer than one or two lines, please move |
48 // the code out into a separate method.) | 40 // the code out into a separate method.) |
49 // | 41 // |
50 class CONTENT_EXPORT BrowserMainParts { | 42 class WebMainParts { |
51 public: | 43 public: |
52 BrowserMainParts() {} | 44 WebMainParts() {} |
53 virtual ~BrowserMainParts() {} | 45 virtual ~WebMainParts() {} |
54 | 46 |
55 virtual void PreEarlyInitialization() {} | 47 virtual void PreEarlyInitialization() {} |
56 | 48 |
57 virtual void PostEarlyInitialization() {} | 49 virtual void PostEarlyInitialization() {} |
58 | 50 |
59 virtual void PreMainMessageLoopStart() {} | 51 virtual void PreMainMessageLoopStart() {} |
60 | 52 |
61 virtual void PostMainMessageLoopStart() {} | 53 virtual void PostMainMessageLoopStart() {} |
62 | 54 |
63 // Allows an embedder to do any extra toolkit initialization. | 55 // Called just before any child threads owned by the web |
64 virtual void ToolkitInitialized() {} | |
65 | |
66 // Called just before any child threads owned by the content | |
67 // framework are created. | 56 // framework are created. |
68 // | 57 // |
69 // The main message loop has been started at this point (but has not | 58 // 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 | 59 // been run), and the toolkit has been initialized. Returns the error code |
71 // (or 0 if no error). | 60 // (or 0 if no error). |
72 virtual int PreCreateThreads(); | 61 virtual int PreCreateThreads(); |
73 | 62 |
74 // This is called just before the main message loop is run. The | 63 // This is called just before the main message loop is run. The |
75 // various browser threads have all been created at this point | 64 // various browser threads have all been created at this point |
76 virtual void PreMainMessageLoopRun() {} | 65 virtual void PreMainMessageLoopRun() {} |
77 | 66 |
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 | 67 // This happens after the main message loop has stopped, but before |
84 // threads are stopped. | 68 // threads are stopped. |
85 virtual void PostMainMessageLoopRun() {} | 69 virtual void PostMainMessageLoopRun() {} |
86 | 70 |
87 // Called as the very last part of shutdown, after threads have been | 71 // Called as the very last part of shutdown, after threads have been |
88 // stopped and destroyed. | 72 // stopped and destroyed. |
89 virtual void PostDestroyThreads() {} | 73 virtual void PostDestroyThreads() {} |
90 }; | 74 }; |
91 | 75 |
92 } // namespace content | 76 } // namespace web |
93 | 77 |
94 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_MAIN_PARTS_H_ | 78 #endif // IOS_WEB_PUBLIC_APP_WEB_MAIN_PARTS_H_ |
OLD | NEW |