[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 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 8 | #include <memory> |
9 | |||||
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 11 | #include "base/metrics/field_trial.h" |
wittman | 863f841 | 2015-08-24 00:42:51 | [diff] [blame] | 12 | #include "base/profiler/stack_sampling_profiler.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 13 | #include "base/tracked_objects.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | ae9e12a | 2012-07-31 17:48:12 | [diff] [blame] | 15 | #include "chrome/browser/chrome_browser_field_trials.h" |
[email protected] | 9a47c43 | 2013-04-19 20:33:55 | [diff] [blame] | 16 | #include "chrome/browser/chrome_process_singleton.h" |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 17 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 18 | #include "chrome/browser/process_singleton.h" |
wittman | 7b501a1 | 2015-09-14 05:13:07 | [diff] [blame] | 19 | #include "chrome/browser/stack_sampling_configuration.h" |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 20 | #include "chrome/browser/ui/startup/startup_browser_creator.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 21 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 22 | #include "content/public/common/main_function_params.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 23 | |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 24 | class BrowserProcessImpl; |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 25 | class ChromeBrowserMainExtraParts; |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 26 | class FieldTrialSynchronizer; |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 27 | class MetricsService; |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 28 | class PrefService; |
dhnishi | 3cf1d2aa | 2014-08-26 22:25:07 | [diff] [blame] | 29 | class ProcessPowerCollector; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 30 | class Profile; |
[email protected] | fe7c487 | 2012-05-10 20:06:03 | [diff] [blame] | 31 | class StartupBrowserCreator; |
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 32 | class StartupTimeBomb; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 33 | class ShutdownWatcherHelper; |
[email protected] | 4432769 | 2013-02-26 21:21:22 | [diff] [blame] | 34 | class ThreeDAPIObserver; |
[email protected] | 5f988b9 | 2011-05-18 07:14:08 | [diff] [blame] | 35 | |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 36 | namespace chrome_browser { |
37 | // For use by ShowMissingLocaleMessageBox. | ||||
[email protected] | 49aa5a3 | 2014-02-03 10:00:44 | [diff] [blame] | 38 | #if defined(OS_WIN) |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 39 | extern const char kMissingLocaleDataTitle[]; |
[email protected] | 49aa5a3 | 2014-02-03 10:00:44 | [diff] [blame] | 40 | #endif |
41 | |||||
[email protected] | 893124a2 | 2014-04-15 00:45:28 | [diff] [blame] | 42 | #if defined(OS_WIN) |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 43 | extern const char kMissingLocaleDataMessage[]; |
[email protected] | 49aa5a3 | 2014-02-03 10:00:44 | [diff] [blame] | 44 | #endif |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 45 | } |
46 | |||||
gunsch | 840bc41 | 2014-09-18 19:38:06 | [diff] [blame] | 47 | namespace metrics { |
[email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 48 | class TrackingSynchronizer; |
49 | } | ||||
50 | |||||
juncai | 1b115256 | 2015-09-04 02:36:08 | [diff] [blame] | 51 | namespace webusb { |
52 | class WebUsbBrowserClient; | ||||
53 | class WebUsbDetector; | ||||
54 | } | ||||
55 | |||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 56 | class ChromeBrowserMainParts : public content::BrowserMainParts { |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 57 | public: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 58 | ~ChromeBrowserMainParts() override; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 59 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 60 | // Add additional ChromeBrowserMainExtraParts. |
61 | virtual void AddParts(ChromeBrowserMainExtraParts* parts); | ||||
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 62 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 63 | protected: |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 64 | explicit ChromeBrowserMainParts( |
65 | const content::MainFunctionParams& parameters); | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 66 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 67 | // content::BrowserMainParts overrides. |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 68 | // These are called in-order by content::BrowserMainLoop. |
69 | // Each stage calls the same stages in any ChromeBrowserMainExtraParts added | ||||
70 | // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts. | ||||
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 71 | void PreEarlyInitialization() override; |
72 | void PostEarlyInitialization() override; | ||||
73 | void ToolkitInitialized() override; | ||||
74 | void PreMainMessageLoopStart() override; | ||||
75 | void PostMainMessageLoopStart() override; | ||||
76 | int PreCreateThreads() override; | ||||
77 | void PreMainMessageLoopRun() override; | ||||
78 | bool MainMessageLoopRun(int* result_code) override; | ||||
79 | void PostMainMessageLoopRun() override; | ||||
80 | void PostDestroyThreads() override; | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 81 | |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 82 | // Additional stages for ChromeBrowserMainExtraParts. These stages are called |
[email protected] | 278a34d | 2012-06-07 00:34:58 | [diff] [blame] | 83 | // in order from PreMainMessageLoopRun(). See implementation for details. |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 84 | virtual void PreProfileInit(); |
85 | virtual void PostProfileInit(); | ||||
86 | virtual void PreBrowserStart(); | ||||
87 | virtual void PostBrowserStart(); | ||||
88 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 89 | // Displays a warning message that we can't find any locale data files. |
90 | virtual void ShowMissingLocaleMessageBox() = 0; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 91 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 92 | const content::MainFunctionParams& parameters() const { |
93 | return parameters_; | ||||
94 | } | ||||
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 95 | const base::CommandLine& parsed_command_line() const { |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 96 | return parsed_command_line_; |
97 | } | ||||
mlerman | a312cec | 2015-01-28 21:13:33 | [diff] [blame] | 98 | const base::FilePath& user_data_dir() const { |
99 | return user_data_dir_; | ||||
100 | } | ||||
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 101 | |
102 | Profile* profile() { return profile_; } | ||||
103 | |||||
[email protected] | a5e8c6d | 2012-04-09 20:22:01 | [diff] [blame] | 104 | const PrefService* local_state() const { return local_state_; } |
105 | |||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 106 | private: |
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 107 | // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- |
108 | |||||
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 109 | // Constructs metrics service and does related initialization, including |
110 | // creation of field trials. Call only after labs have been converted to | ||||
111 | // switches. | ||||
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 112 | void SetupMetricsAndFieldTrials(); |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 113 | |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 114 | // Starts recording of metrics. This can only be called after we have a file |
115 | // thread. | ||||
116 | void StartMetricsRecording(); | ||||
117 | |||||
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 118 | // Record time from process startup to present time in an UMA histogram. |
[email protected] | 69e9069 | 2013-07-31 02:13:29 | [diff] [blame] | 119 | void RecordBrowserStartupTime(); |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 120 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 121 | // Methods for Main Message Loop ------------------------------------------- |
122 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 123 | int PreCreateThreadsImpl(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 124 | int PreMainMessageLoopRunImpl(); |
125 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 126 | // Members initialized on construction --------------------------------------- |
127 | |||||
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 128 | const content::MainFunctionParams parameters_; |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 129 | const base::CommandLine& parsed_command_line_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 130 | int result_code_; |
131 | |||||
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 132 | // Create StartupTimeBomb object for watching jank during startup. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 133 | std::unique_ptr<StartupTimeBomb> startup_watcher_; |
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 134 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 135 | // Create ShutdownWatcherHelper object for watching jank during shutdown. |
136 | // Please keep |shutdown_watcher| as the first object constructed, and hence | ||||
137 | // it is destroyed last. | ||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 138 | std::unique_ptr<ShutdownWatcherHelper> shutdown_watcher_; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 139 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 140 | // Statistical testing infrastructure for the entire browser. NULL until |
141 | // SetupMetricsAndFieldTrials is called. | ||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 142 | std::unique_ptr<base::FieldTrialList> field_trial_list_; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 143 | |
[email protected] | ae9e12a | 2012-07-31 17:48:12 | [diff] [blame] | 144 | ChromeBrowserFieldTrials browser_field_trials_; |
145 | |||||
dhnishi | 3cf1d2aa | 2014-08-26 22:25:07 | [diff] [blame] | 146 | #if !defined(OS_ANDROID) && !defined(OS_IOS) |
147 | // A monitor for attributing power consumption to origins. | ||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 148 | std::unique_ptr<ProcessPowerCollector> process_power_collector_; |
juncai | 1b115256 | 2015-09-04 02:36:08 | [diff] [blame] | 149 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 150 | std::unique_ptr<webusb::WebUsbBrowserClient> webusb_browser_client_; |
151 | std::unique_ptr<webusb::WebUsbDetector> webusb_detector_; | ||||
dhnishi | 3cf1d2aa | 2014-08-26 22:25:07 | [diff] [blame] | 152 | #endif |
153 | |||||
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 154 | // Vector of additional ChromeBrowserMainExtraParts. |
155 | // Parts are deleted in the inverse order they are added. | ||||
156 | std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_; | ||||
157 | |||||
wittman | 7b501a1 | 2015-09-14 05:13:07 | [diff] [blame] | 158 | // The configuration to use for the stack sampling profiler below. |
159 | StackSamplingConfiguration sampling_profiler_config_; | ||||
160 | |||||
wittman | 863f841 | 2015-08-24 00:42:51 | [diff] [blame] | 161 | // A profiler that periodically samples stack traces. Used to sample startup |
162 | // behavior. | ||||
163 | base::StackSamplingProfiler sampling_profiler_; | ||||
164 | |||||
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 165 | // Members initialized after / released before main_message_loop_ ------------ |
166 | |||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 167 | std::unique_ptr<BrowserProcessImpl> browser_process_; |
gunsch | 840bc41 | 2014-09-18 19:38:06 | [diff] [blame] | 168 | scoped_refptr<metrics::TrackingSynchronizer> tracking_synchronizer_; |
pkasting | 28ae579 | 2016-05-20 21:39:14 | [diff] [blame^] | 169 | |
bshe | 0d94807 | 2016-01-05 19:06:20 | [diff] [blame] | 170 | #if !defined(OS_ANDROID) |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 171 | // Browser creation happens on the Java side in Android. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 172 | std::unique_ptr<StartupBrowserCreator> browser_creator_; |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 173 | |
174 | // Android doesn't support multiple browser processes, so it doesn't implement | ||||
175 | // ProcessSingleton. | ||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 176 | std::unique_ptr<ChromeProcessSingleton> process_singleton_; |
[email protected] | d29f4e31 | 2013-08-07 05:28:31 | [diff] [blame] | 177 | |
178 | // Android's first run is done in Java instead of native. | ||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 179 | std::unique_ptr<first_run::MasterPrefs> master_prefs_; |
pkasting | 28ae579 | 2016-05-20 21:39:14 | [diff] [blame^] | 180 | |
181 | ProcessSingleton::NotifyResult notify_result_ = | ||||
182 | ProcessSingleton::PROCESS_NONE; | ||||
183 | |||||
184 | // Members needed across shutdown methods. | ||||
185 | bool restart_last_session_ = false; | ||||
bshe | 0d94807 | 2016-01-05 19:06:20 | [diff] [blame] | 186 | #endif |
pkasting | 28ae579 | 2016-05-20 21:39:14 | [diff] [blame^] | 187 | |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 188 | Profile* profile_; |
189 | bool run_message_loop_; | ||||
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 190 | std::unique_ptr<ThreeDAPIObserver> three_d_observer_; |
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 191 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 192 | // Initialized in SetupMetricsAndFieldTrials. |
193 | scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; | ||||
194 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 195 | // Members initialized in PreMainMessageLoopRun, needed in |
196 | // PreMainMessageLoopRunThreadsCreated. | ||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 197 | PrefService* local_state_; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 198 | base::FilePath user_data_dir_; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 199 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 200 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 201 | }; |
202 | |||||
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 203 | #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_ |