| [email protected] | d15b7ca | 2012-01-04 01:42:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| [email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. | ||||
| 4 | |||||
| [email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_H_ |
| 6 | #define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_ | ||||
| [email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 7 | |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 8 | #include "base/basictypes.h" |
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
| [email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 10 | #include "base/metrics/field_trial.h" |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 11 | #include "base/tracked_objects.h" |
| [email protected] | ae9e12a | 2012-07-31 17:48:12 | [diff] [blame] | 12 | #include "chrome/browser/chrome_browser_field_trials.h" |
| [email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 13 | #include "chrome/browser/chrome_process_singleton.h" |
| [email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 14 | #include "chrome/browser/first_run/first_run.h" |
| [email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 15 | #include "chrome/browser/process_singleton.h" |
| [email protected] | 61b53f97 | 2012-02-10 20:39:23 | [diff] [blame] | 16 | #include "chrome/browser/task_profiler/auto_tracking.h" |
| [email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 17 | #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 18 | #include "content/public/browser/browser_main_parts.h" |
| [email protected] | af7ba1e | 2013-04-12 17:09:45 | [diff] [blame] | 19 | #include "content/public/browser/render_view_host.h" |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 20 | |
| [email protected] | 2f2f72b | 2013-03-08 22:37:31 | [diff] [blame] | 21 | class ActiveTabTracker; |
| [email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 22 | class BrowserProcessImpl; |
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 23 | class ChromeBrowserMainExtraParts; |
| [email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 24 | class FieldTrialSynchronizer; |
| [email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 25 | class MetricsService; |
| [email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 26 | class PrefService; |
| [email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 27 | class Profile; |
| [email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 28 | class StartupBrowserCreator; |
| [email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 29 | class StartupTimeBomb; |
| [email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 30 | class ShutdownWatcherHelper; |
| [email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 31 | class ThreeDAPIObserver; |
| [email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 32 | class TranslateManager; |
| [email protected] | 5f988b9 | 2011-05-18 07:14:08 | [diff] [blame] | 33 | |
| [email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 34 | namespace chrome_browser { |
| 35 | // For use by ShowMissingLocaleMessageBox. | ||||
| 36 | extern const char kMissingLocaleDataTitle[]; | ||||
| 37 | extern const char kMissingLocaleDataMessage[]; | ||||
| 38 | } | ||||
| 39 | |||||
| [email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 40 | namespace chrome_browser_metrics { |
| 41 | class TrackingSynchronizer; | ||||
| 42 | } | ||||
| 43 | |||||
| [email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 44 | namespace content { |
| 45 | struct MainFunctionParams; | ||||
| 46 | } | ||||
| 47 | |||||
| [email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 48 | namespace performance_monitor { |
| 49 | class StartupTimer; | ||||
| 50 | } | ||||
| 51 | |||||
| [email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 52 | class ChromeBrowserMainParts : public content::BrowserMainParts { |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 53 | public: |
| [email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 54 | virtual ~ChromeBrowserMainParts(); |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 55 | |
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 56 | // Add additional ChromeBrowserMainExtraParts. |
| 57 | virtual void AddParts(ChromeBrowserMainExtraParts* parts); | ||||
| [email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 58 | |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 59 | protected: |
| [email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 60 | explicit ChromeBrowserMainParts( |
| 61 | const content::MainFunctionParams& parameters); | ||||
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 62 | |
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 63 | // content::BrowserMainParts overrides. |
| [email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 64 | // These are called in-order by content::BrowserMainLoop. |
| 65 | // Each stage calls the same stages in any ChromeBrowserMainExtraParts added | ||||
| 66 | // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts. | ||||
| [email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 67 | virtual void PreEarlyInitialization() OVERRIDE; |
| 68 | virtual void PostEarlyInitialization() OVERRIDE; | ||||
| [email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 69 | virtual void ToolkitInitialized() OVERRIDE; |
| [email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 70 | virtual void PreMainMessageLoopStart() OVERRIDE; |
| 71 | virtual void PostMainMessageLoopStart() OVERRIDE; | ||||
| [email protected] | 69479b92 | 2012-02-02 09:56:20 | [diff] [blame] | 72 | virtual int PreCreateThreads() OVERRIDE; |
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 73 | virtual void PreMainMessageLoopRun() OVERRIDE; |
| 74 | virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; | ||||
| [email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 75 | virtual void PostMainMessageLoopRun() OVERRIDE; |
| [email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 76 | virtual void PostDestroyThreads() OVERRIDE; |
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 77 | |
| [email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 78 | // Additional stages for ChromeBrowserMainExtraParts. These stages are called |
| [email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 79 | // in order from PreMainMessageLoopRun(). See implementation for details. |
| [email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 80 | virtual void PreProfileInit(); |
| 81 | virtual void PostProfileInit(); | ||||
| 82 | virtual void PreBrowserStart(); | ||||
| 83 | virtual void PostBrowserStart(); | ||||
| 84 | |||||
| [email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 85 | #if !defined(OS_ANDROID) |
| [email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 86 | // Runs the PageCycler; called if the switch kVisitURLs is present. |
| 87 | virtual void RunPageCycler(); | ||||
| [email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 88 | #endif |
| [email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 89 | |
| [email protected] | b98def8 | 2012-06-28 23:42:45 | [diff] [blame] | 90 | // Override this in subclasses to initialize platform specific field trials. |
| 91 | virtual void SetupPlatformFieldTrials(); | ||||
| 92 | |||||
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 93 | // Displays a warning message that we can't find any locale data files. |
| 94 | virtual void ShowMissingLocaleMessageBox() = 0; | ||||
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 95 | |
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 96 | const content::MainFunctionParams& parameters() const { |
| 97 | return parameters_; | ||||
| 98 | } | ||||
| 99 | const CommandLine& parsed_command_line() const { | ||||
| 100 | return parsed_command_line_; | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | Profile* profile() { return profile_; } | ||||
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 104 | |
| [email protected] | a5e8c6d4 | 2012-04-09 20:22:01 | [diff] [blame] | 105 | const PrefService* local_state() const { return local_state_; } |
| 106 | |||||
| [email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 107 | private: |
| [email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 108 | // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- |
| 109 | |||||
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 110 | // Constructs metrics service and does related initialization, including |
| 111 | // creation of field trials. Call only after labs have been converted to | ||||
| 112 | // switches. | ||||
| [email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 113 | void SetupMetricsAndFieldTrials(); |
| [email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 114 | |
| [email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 115 | // Starts recording of metrics. This can only be called after we have a file |
| 116 | // thread. | ||||
| 117 | void StartMetricsRecording(); | ||||
| 118 | |||||
| [email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 119 | // Returns true if the user opted in to sending metric reports. |
| 120 | bool IsMetricsReportingEnabled(); | ||||
| 121 | |||||
| [email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 122 | // Record time from process startup to present time in an UMA histogram. |
| [email protected] | 69e9069 | 2013-07-31 02:13:29 | [diff] [blame^] | 123 | void RecordBrowserStartupTime(); |
| [email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 124 | |
| 125 | // Records a time value to an UMA histogram in the context of the | ||||
| 126 | // PreReadExperiment field-trial. This also reports to the appropriate | ||||
| 127 | // sub-histogram (_PreRead(Enabled|Disabled)). | ||||
| 128 | void RecordPreReadExperimentTime(const char* name, base::TimeDelta time); | ||||
| 129 | |||||
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 130 | // Methods for Main Message Loop ------------------------------------------- |
| 131 | |||||
| [email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 132 | int PreCreateThreadsImpl(); |
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 133 | int PreMainMessageLoopRunImpl(); |
| 134 | |||||
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 135 | // Members initialized on construction --------------------------------------- |
| 136 | |||||
| [email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 137 | const content::MainFunctionParams& parameters_; |
| [email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 138 | const CommandLine& parsed_command_line_; |
| 139 | int result_code_; | ||||
| 140 | |||||
| [email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 141 | // Create StartupTimeBomb object for watching jank during startup. |
| 142 | scoped_ptr<StartupTimeBomb> startup_watcher_; | ||||
| 143 | |||||
| [email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 144 | // Create ShutdownWatcherHelper object for watching jank during shutdown. |
| 145 | // Please keep |shutdown_watcher| as the first object constructed, and hence | ||||
| 146 | // it is destroyed last. | ||||
| 147 | scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_; | ||||
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 148 | |
| [email protected] | 0c1c475 | 2012-08-09 20:30:24 | [diff] [blame] | 149 | // A timer to hold data regarding startup and session restore times for |
| 150 | // PerformanceMonitor so that we don't have to start the entire | ||||
| 151 | // PerformanceMonitor at browser startup. | ||||
| 152 | scoped_ptr<performance_monitor::StartupTimer> startup_timer_; | ||||
| 153 | |||||
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 154 | // Creating this object starts tracking the creation and deletion of Task |
| 155 | // instance. This MUST be done before main_message_loop, so that it is | ||||
| 156 | // destroyed after the main_message_loop. | ||||
| [email protected] | 61b53f97 | 2012-02-10 20:39:23 | [diff] [blame] | 157 | task_profiler::AutoTracking tracking_objects_; |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 158 | |
| [email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 159 | // Statistical testing infrastructure for the entire browser. NULL until |
| 160 | // SetupMetricsAndFieldTrials is called. | ||||
| 161 | scoped_ptr<base::FieldTrialList> field_trial_list_; | ||||
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 162 | |
| [email protected] | ae9e12a | 2012-07-31 17:48:12 | [diff] [blame] | 163 | ChromeBrowserFieldTrials browser_field_trials_; |
| 164 | |||||
| [email protected] | af7ba1e | 2013-04-12 17:09:45 | [diff] [blame] | 165 | content::RenderViewHost::CreatedCallback rvh_callback_; |
| 166 | |||||
| [email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 167 | // Vector of additional ChromeBrowserMainExtraParts. |
| 168 | // Parts are deleted in the inverse order they are added. | ||||
| 169 | std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_; | ||||
| 170 | |||||
| [email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 171 | // Members initialized after / released before main_message_loop_ ------------ |
| 172 | |||||
| [email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 173 | scoped_ptr<BrowserProcessImpl> browser_process_; |
| [email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 174 | scoped_refptr<chrome_browser_metrics::TrackingSynchronizer> |
| 175 | tracking_synchronizer_; | ||||
| [email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 176 | #if !defined(OS_ANDROID) |
| 177 | // Browser creation happens on the Java side in Android. | ||||
| 178 | scoped_ptr<StartupBrowserCreator> browser_creator_; | ||||
| 179 | |||||
| 180 | // Android doesn't support multiple browser processes, so it doesn't implement | ||||
| 181 | // ProcessSingleton. | ||||
| [email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 182 | scoped_ptr<ChromeProcessSingleton> process_singleton_; |
| [email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 183 | #endif |
| [email protected] | baacb23 | 2012-01-28 02:30:18 | [diff] [blame] | 184 | scoped_ptr<first_run::MasterPrefs> master_prefs_; |
| [email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 185 | TranslateManager* translate_manager_; |
| 186 | Profile* profile_; | ||||
| 187 | bool run_message_loop_; | ||||
| [email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 188 | ProcessSingleton::NotifyResult notify_result_; |
| [email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 189 | scoped_ptr<ThreeDAPIObserver> three_d_observer_; |
| [email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 190 | |
| [email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 191 | // Initialized in SetupMetricsAndFieldTrials. |
| 192 | scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; | ||||
| 193 | |||||
| [email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 194 | // Members initialized in PreMainMessageLoopRun, needed in |
| 195 | // PreMainMessageLoopRunThreadsCreated. | ||||
| [email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 196 | PrefService* local_state_; |
| [email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 197 | base::FilePath user_data_dir_; |
| [email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 198 | |
| [email protected] | 2f2f72b | 2013-03-08 22:37:31 | [diff] [blame] | 199 | #if !defined(OS_ANDROID) |
| 200 | scoped_ptr<ActiveTabTracker> active_tab_tracker_; | ||||
| 201 | #endif | ||||
| 202 | |||||
| [email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 203 | // Members needed across shutdown methods. |
| 204 | bool restart_last_session_; | ||||
| 205 | |||||
| [email protected] | 1948a478 | 2012-04-30 13:45:44 | [diff] [blame] | 206 | // Tests can set this to true to disable restricting cookie access in the |
| 207 | // network stack, as this can only be done once. | ||||
| 208 | static bool disable_enforcing_cookie_policies_for_tests_; | ||||
| 209 | |||||
| [email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 210 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts); |
| [email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 211 | }; |
| 212 | |||||
| [email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 213 | #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_ |