[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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 8 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 9 | #include "base/basictypes.h" |
[email protected] | 5e6efa5 | 2011-06-27 17:26:41 | [diff] [blame] | 10 | #include "base/gtest_prod_util.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 12 | #include "base/memory/scoped_vector.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 13 | #include "base/metrics/field_trial.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 14 | #include "base/tracked_objects.h" |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 15 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 16 | #include "chrome/browser/process_singleton.h" |
[email protected] | 61b53f97 | 2012-02-10 20:39:23 | [diff] [blame] | 17 | #include "chrome/browser/task_profiler/auto_tracking.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 18 | #include "chrome/browser/ui/browser_init.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 19 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 20 | #include "content/public/browser/browser_thread.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 21 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 22 | class BrowserInit; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 23 | class BrowserProcessImpl; |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 24 | class ChromeBrowserMainExtraParts; |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 25 | class FieldTrialSynchronizer; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 26 | class HistogramSynchronizer; |
[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; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 29 | class Profile; |
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 30 | class StartupTimeBomb; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 31 | class ShutdownWatcherHelper; |
[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] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 48 | class ChromeBrowserMainParts : public content::BrowserMainParts { |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 49 | public: |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 50 | virtual ~ChromeBrowserMainParts(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 51 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 52 | // Add additional ChromeBrowserMainExtraParts. |
53 | virtual void AddParts(ChromeBrowserMainExtraParts* parts); | ||||
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 54 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 55 | protected: |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 56 | explicit ChromeBrowserMainParts( |
57 | const content::MainFunctionParams& parameters); | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 58 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 59 | // content::BrowserMainParts overrides. |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 60 | // These are called in-order by content::BrowserMainLoop. |
61 | // Each stage calls the same stages in any ChromeBrowserMainExtraParts added | ||||
62 | // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts. | ||||
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 63 | virtual void PreEarlyInitialization() OVERRIDE; |
64 | virtual void PostEarlyInitialization() OVERRIDE; | ||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 65 | virtual void ToolkitInitialized() OVERRIDE; |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 66 | virtual void PreMainMessageLoopStart() OVERRIDE; |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 67 | virtual void PostMainMessageLoopStart() OVERRIDE; |
[email protected] | 69479b92 | 2012-02-02 09:56:20 | [diff] [blame] | 68 | virtual int PreCreateThreads() OVERRIDE; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 69 | virtual void PreMainMessageLoopRun() OVERRIDE; |
70 | virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; | ||||
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 71 | virtual void PostMainMessageLoopRun() OVERRIDE; |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 72 | virtual void PostDestroyThreads() OVERRIDE; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 73 | |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 74 | // Additional stages for ChromeBrowserMainExtraParts. These stages are called |
[email protected] | a36773d | 2012-01-19 20:54:14 | [diff] [blame] | 75 | // in order from PreMainMessageLoopStart(). See implementation for details. |
[email protected] | 97ef83f | 2011-12-19 19:26:36 | [diff] [blame] | 76 | virtual void PreProfileInit(); |
77 | virtual void PostProfileInit(); | ||||
78 | virtual void PreBrowserStart(); | ||||
79 | virtual void PostBrowserStart(); | ||||
80 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 81 | // Displays a warning message that we can't find any locale data files. |
82 | virtual void ShowMissingLocaleMessageBox() = 0; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 83 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 84 | const content::MainFunctionParams& parameters() const { |
85 | return parameters_; | ||||
86 | } | ||||
87 | const CommandLine& parsed_command_line() const { | ||||
88 | return parsed_command_line_; | ||||
89 | } | ||||
90 | |||||
91 | Profile* profile() { return profile_; } | ||||
92 | |||||
[email protected] | a5e8c6d | 2012-04-09 20:22:01 | [diff] [blame] | 93 | const PrefService* local_state() const { return local_state_; } |
94 | |||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 95 | private: |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 96 | // Methods for |EarlyInitialization()| --------------------------------------- |
97 | |||||
98 | // A/B test for the maximum number of persistent connections per host. | ||||
99 | void ConnectionFieldTrial(); | ||||
100 | |||||
101 | // A/B test for determining a value for unused socket timeout. | ||||
102 | void SocketTimeoutFieldTrial(); | ||||
103 | |||||
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 104 | // A/B test for the maximum number of connections per proxy server. |
105 | void ProxyConnectionsFieldTrial(); | ||||
106 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 107 | // A/B test for spdy when --use-spdy not set. |
108 | void SpdyFieldTrial(); | ||||
109 | |||||
[email protected] | 6930c52 | 2011-07-28 22:15:19 | [diff] [blame] | 110 | // A/B test for warmest socket vs. most recently used socket. |
111 | void WarmConnectionFieldTrial(); | ||||
112 | |||||
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 113 | // A/B test for automatically establishing a backup TCP connection when a |
114 | // specified timeout value is reached. | ||||
115 | void ConnectBackupJobsFieldTrial(); | ||||
116 | |||||
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 117 | // Field trial to see what disabling DNS pre-resolution does to |
118 | // latency of page loads. | ||||
119 | void PredictorFieldTrial(); | ||||
120 | |||||
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 121 | // Field trial to see what effect installing defaults in the NTP apps pane |
122 | // has on retention and general apps/webstore usage. | ||||
123 | void DefaultAppsFieldTrial(); | ||||
124 | |||||
[email protected] | 0cba296 | 2011-12-15 10:45:32 | [diff] [blame] | 125 | // A field trial to see what effects launching Chrome automatically on |
126 | // computer startup has on retention and usage of Chrome. | ||||
127 | void AutoLaunchChromeFieldTrial(); | ||||
128 | |||||
[email protected] | 1759333 | 2012-04-20 06:05:02 | [diff] [blame^] | 129 | // Field trial for testing domain bound certs. |
130 | void DomainBoundCertsFieldTrial(); | ||||
131 | |||||
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 132 | // Methods for |SetupMetricsAndFieldTrials()| -------------------------------- |
133 | |||||
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 134 | // Constructs metrics service and does related initialization, including |
135 | // creation of field trials. Call only after labs have been converted to | ||||
136 | // switches. | ||||
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 137 | void SetupMetricsAndFieldTrials(); |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 138 | |
139 | // Add an invocation of your field trial init function to this method. | ||||
[email protected] | 12c84e2 | 2011-07-11 09:35:45 | [diff] [blame] | 140 | void SetupFieldTrials(bool metrics_recording_enabled, |
141 | bool proxy_policy_is_set); | ||||
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 142 | |
[email protected] | 5281db1d | 2012-01-11 22:51:54 | [diff] [blame] | 143 | // Starts recording of metrics. This can only be called after we have a file |
144 | // thread. | ||||
145 | void StartMetricsRecording(); | ||||
146 | |||||
[email protected] | 5cbeeef7 | 2012-02-08 02:05:18 | [diff] [blame] | 147 | // Returns true if the user opted in to sending metric reports. |
148 | bool IsMetricsReportingEnabled(); | ||||
149 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 150 | // Methods for Main Message Loop ------------------------------------------- |
151 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 152 | int PreCreateThreadsImpl(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 153 | int PreMainMessageLoopRunImpl(); |
154 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 155 | // Members initialized on construction --------------------------------------- |
156 | |||||
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 157 | const content::MainFunctionParams& parameters_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 158 | const CommandLine& parsed_command_line_; |
159 | int result_code_; | ||||
160 | |||||
[email protected] | 08f1c5e | 2011-12-01 01:54:34 | [diff] [blame] | 161 | // Create StartupTimeBomb object for watching jank during startup. |
162 | scoped_ptr<StartupTimeBomb> startup_watcher_; | ||||
163 | |||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 164 | // Create ShutdownWatcherHelper object for watching jank during shutdown. |
165 | // Please keep |shutdown_watcher| as the first object constructed, and hence | ||||
166 | // it is destroyed last. | ||||
167 | scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 168 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 169 | // Creating this object starts tracking the creation and deletion of Task |
170 | // instance. This MUST be done before main_message_loop, so that it is | ||||
171 | // destroyed after the main_message_loop. | ||||
[email protected] | 61b53f97 | 2012-02-10 20:39:23 | [diff] [blame] | 172 | task_profiler::AutoTracking tracking_objects_; |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 173 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 174 | // Statistical testing infrastructure for the entire browser. NULL until |
175 | // SetupMetricsAndFieldTrials is called. | ||||
176 | scoped_ptr<base::FieldTrialList> field_trial_list_; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 177 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 178 | // Vector of additional ChromeBrowserMainExtraParts. |
179 | // Parts are deleted in the inverse order they are added. | ||||
180 | std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_; | ||||
181 | |||||
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 182 | // Members initialized after / released before main_message_loop_ ------------ |
183 | |||||
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 184 | scoped_ptr<BrowserInit> browser_init_; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 185 | scoped_ptr<BrowserProcessImpl> browser_process_; |
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 186 | scoped_refptr<HistogramSynchronizer> histogram_synchronizer_; |
[email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 187 | scoped_refptr<chrome_browser_metrics::TrackingSynchronizer> |
188 | tracking_synchronizer_; | ||||
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 189 | scoped_ptr<ProcessSingleton> process_singleton_; |
[email protected] | baacb23 | 2012-01-28 02:30:18 | [diff] [blame] | 190 | scoped_ptr<first_run::MasterPrefs> master_prefs_; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 191 | bool record_search_engine_; |
192 | TranslateManager* translate_manager_; | ||||
193 | Profile* profile_; | ||||
194 | bool run_message_loop_; | ||||
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 195 | ProcessSingleton::NotifyResult notify_result_; |
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 196 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 197 | // Initialized in SetupMetricsAndFieldTrials. |
198 | scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; | ||||
199 | |||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 200 | // Members initialized in PreMainMessageLoopRun, needed in |
201 | // PreMainMessageLoopRunThreadsCreated. | ||||
202 | bool is_first_run_; | ||||
203 | bool first_run_ui_bypass_; | ||||
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 204 | PrefService* local_state_; |
205 | FilePath user_data_dir_; | ||||
206 | |||||
207 | // Members needed across shutdown methods. | ||||
208 | bool restart_last_session_; | ||||
209 | |||||
[email protected] | 3438fa8 | 2011-11-24 00:49:36 | [diff] [blame] | 210 | FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, |
211 | WarmConnectionFieldTrial_WarmestSocket); | ||||
212 | FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random); | ||||
213 | FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid); | ||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 214 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 215 | }; |
216 | |||||
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 217 | // Records the conditions that can prevent Breakpad from generating and |
218 | // sending crash reports. The presence of a Breakpad handler (after | ||||
219 | // attempting to initialize crash reporting) and the presence of a debugger | ||||
220 | // are registered with the UMA metrics service. | ||||
221 | void RecordBreakpadStatusUMA(MetricsService* metrics); | ||||
222 | |||||
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 223 | // Displays a warning message if some minimum level of OS support is not |
224 | // present on the current platform. | ||||
225 | void WarnAboutMinimumSystemRequirements(); | ||||
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 226 | |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 227 | // Records the time from our process' startup to the present time in |
228 | // the UMA histogram |metric_name|. | ||||
229 | void RecordBrowserStartupTime(); | ||||
230 | |||||
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 231 | // Records a time value to an UMA histogram in the context of the |
232 | // PreReadExperiment field-trial. This also reports to the appropriate | ||||
233 | // sub-histogram (_PreRead(Enabled|Disabled)). | ||||
234 | void RecordPreReadExperimentTime(const char* name, base::TimeDelta time); | ||||
235 | |||||
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 236 | #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_ |