[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 17 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 18 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 19 | class BrowserInit; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 20 | class BrowserProcessImpl; |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 21 | class ChromeBrowserMainExtraParts; |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 22 | class FieldTrialSynchronizer; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 23 | class HistogramSynchronizer; |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 24 | class MetricsService; |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 25 | class PrefService; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 26 | class Profile; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 27 | class ShutdownWatcherHelper; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 28 | class TranslateManager; |
[email protected] | 5f988b9 | 2011-05-18 07:14:08 | [diff] [blame] | 29 | |
[email protected] | cbce4724 | 2011-08-12 21:40:59 | [diff] [blame] | 30 | namespace chrome_browser { |
31 | // For use by ShowMissingLocaleMessageBox. | ||||
32 | extern const char kMissingLocaleDataTitle[]; | ||||
33 | extern const char kMissingLocaleDataMessage[]; | ||||
34 | } | ||||
35 | |||||
[email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 36 | namespace chrome_browser_metrics { |
37 | class TrackingSynchronizer; | ||||
38 | } | ||||
39 | |||||
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 40 | namespace content { |
41 | struct MainFunctionParams; | ||||
42 | } | ||||
43 | |||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 44 | class ChromeBrowserMainParts : public content::BrowserMainParts { |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 45 | public: |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 46 | virtual ~ChromeBrowserMainParts(); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 47 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 48 | // Add additional ChromeBrowserMainExtraParts. |
49 | virtual void AddParts(ChromeBrowserMainExtraParts* parts); | ||||
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 50 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 51 | protected: |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 52 | explicit ChromeBrowserMainParts( |
53 | const content::MainFunctionParams& parameters); | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 54 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 55 | // content::BrowserMainParts overrides. |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 56 | virtual void PreEarlyInitialization() OVERRIDE; |
57 | virtual void PostEarlyInitialization() OVERRIDE; | ||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 58 | virtual void ToolkitInitialized() OVERRIDE; |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 59 | virtual void PreMainMessageLoopStart() OVERRIDE; |
60 | virtual void PostMainMessageLoopStart() OVERRIDE; | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 61 | virtual void PreMainMessageLoopRun() OVERRIDE; |
62 | virtual bool MainMessageLoopRun(int* result_code) OVERRIDE; | ||||
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 63 | virtual void PostMainMessageLoopRun() OVERRIDE; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 64 | |
65 | // Displays a warning message that we can't find any locale data files. | ||||
66 | virtual void ShowMissingLocaleMessageBox() = 0; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 67 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 68 | const content::MainFunctionParams& parameters() const { |
69 | return parameters_; | ||||
70 | } | ||||
71 | const CommandLine& parsed_command_line() const { | ||||
72 | return parsed_command_line_; | ||||
73 | } | ||||
74 | |||||
75 | Profile* profile() { return profile_; } | ||||
76 | |||||
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 77 | private: |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 78 | // Methods for |EarlyInitialization()| --------------------------------------- |
79 | |||||
80 | // A/B test for the maximum number of persistent connections per host. | ||||
81 | void ConnectionFieldTrial(); | ||||
82 | |||||
83 | // A/B test for determining a value for unused socket timeout. | ||||
84 | void SocketTimeoutFieldTrial(); | ||||
85 | |||||
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 86 | // A/B test for the maximum number of connections per proxy server. |
87 | void ProxyConnectionsFieldTrial(); | ||||
88 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 89 | // A/B test for spdy when --use-spdy not set. |
90 | void SpdyFieldTrial(); | ||||
91 | |||||
[email protected] | 6930c52 | 2011-07-28 22:15:19 | [diff] [blame] | 92 | // A/B test for warmest socket vs. most recently used socket. |
93 | void WarmConnectionFieldTrial(); | ||||
94 | |||||
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 95 | // A/B test for automatically establishing a backup TCP connection when a |
96 | // specified timeout value is reached. | ||||
97 | void ConnectBackupJobsFieldTrial(); | ||||
98 | |||||
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 99 | // Field trial to see what disabling DNS pre-resolution does to |
100 | // latency of page loads. | ||||
101 | void PredictorFieldTrial(); | ||||
102 | |||||
[email protected] | 51a7a9d | 2011-09-27 17:21:41 | [diff] [blame] | 103 | // Field trial to see what effect installing defaults in the NTP apps pane |
104 | // has on retention and general apps/webstore usage. | ||||
105 | void DefaultAppsFieldTrial(); | ||||
106 | |||||
[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. | ||||
112 | MetricsService* SetupMetricsAndFieldTrials(PrefService* local_state); | ||||
113 | |||||
[email protected] | 069cd995 | 2011-10-01 16:34:45 | [diff] [blame] | 114 | static MetricsService* InitializeMetrics( |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 115 | const CommandLine& parsed_command_line, |
116 | const PrefService* local_state); | ||||
117 | |||||
118 | // Add an invocation of your field trial init function to this method. | ||||
[email protected] | 12c84e2 | 2011-07-11 09:35:45 | [diff] [blame] | 119 | void SetupFieldTrials(bool metrics_recording_enabled, |
120 | bool proxy_policy_is_set); | ||||
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 121 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 122 | // Methods for Main Message Loop ------------------------------------------- |
123 | |||||
124 | int PreMainMessageLoopRunImpl(); | ||||
125 | |||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 126 | // Members initialized on construction --------------------------------------- |
127 | |||||
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 128 | const content::MainFunctionParams& parameters_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 129 | const CommandLine& parsed_command_line_; |
130 | int result_code_; | ||||
131 | |||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 132 | // Create ShutdownWatcherHelper object for watching jank during shutdown. |
133 | // Please keep |shutdown_watcher| as the first object constructed, and hence | ||||
134 | // it is destroyed last. | ||||
135 | scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 136 | |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 137 | // Creating this object starts tracking the creation and deletion of Task |
138 | // instance. This MUST be done before main_message_loop, so that it is | ||||
139 | // destroyed after the main_message_loop. | ||||
140 | tracked_objects::AutoTracking tracking_objects_; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 141 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 142 | // Statistical testing infrastructure for the entire browser. NULL until |
143 | // SetupMetricsAndFieldTrials is called. | ||||
144 | scoped_ptr<base::FieldTrialList> field_trial_list_; | ||||
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 145 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 146 | // Vector of additional ChromeBrowserMainExtraParts. |
147 | // Parts are deleted in the inverse order they are added. | ||||
148 | std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_; | ||||
149 | |||||
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 150 | // Members initialized after / released before main_message_loop_ ------------ |
151 | |||||
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 152 | scoped_ptr<BrowserInit> browser_init_; |
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 153 | scoped_ptr<BrowserProcessImpl> browser_process_; |
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 154 | scoped_refptr<HistogramSynchronizer> histogram_synchronizer_; |
[email protected] | 10fe40c | 2011-11-05 03:27:46 | [diff] [blame] | 155 | scoped_refptr<chrome_browser_metrics::TrackingSynchronizer> |
156 | tracking_synchronizer_; | ||||
[email protected] | c1702d71 | 2011-09-08 19:41:43 | [diff] [blame] | 157 | scoped_ptr<ProcessSingleton> process_singleton_; |
158 | scoped_ptr<FirstRun::MasterPrefs> master_prefs_; | ||||
159 | bool record_search_engine_; | ||||
160 | TranslateManager* translate_manager_; | ||||
161 | Profile* profile_; | ||||
162 | bool run_message_loop_; | ||||
[email protected] | 6601392 | 2011-09-13 18:53:42 | [diff] [blame] | 163 | ProcessSingleton::NotifyResult notify_result_; |
[email protected] | 0f247aea8 | 2011-09-03 03:05:51 | [diff] [blame] | 164 | |
[email protected] | edafd4c | 2011-05-10 17:18:53 | [diff] [blame] | 165 | // Initialized in SetupMetricsAndFieldTrials. |
166 | scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_; | ||||
167 | |||||
[email protected] | 3438fa8 | 2011-11-24 00:49:36 | [diff] [blame^] | 168 | FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, |
169 | WarmConnectionFieldTrial_WarmestSocket); | ||||
170 | FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random); | ||||
171 | FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid); | ||||
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 172 | DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts); |
[email protected] | f8abf72 | 2010-07-07 19:46:24 | [diff] [blame] | 173 | }; |
174 | |||||
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 175 | // Records the conditions that can prevent Breakpad from generating and |
176 | // sending crash reports. The presence of a Breakpad handler (after | ||||
177 | // attempting to initialize crash reporting) and the presence of a debugger | ||||
178 | // are registered with the UMA metrics service. | ||||
179 | void RecordBreakpadStatusUMA(MetricsService* metrics); | ||||
180 | |||||
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 181 | // Displays a warning message if some minimum level of OS support is not |
182 | // present on the current platform. | ||||
183 | void WarnAboutMinimumSystemRequirements(); | ||||
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 184 | |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 185 | // Records the time from our process' startup to the present time in |
186 | // the UMA histogram |metric_name|. | ||||
187 | void RecordBrowserStartupTime(); | ||||
188 | |||||
[email protected] | 28f576f | 2011-08-26 20:46:55 | [diff] [blame] | 189 | // Records a time value to an UMA histogram in the context of the |
190 | // PreReadExperiment field-trial. This also reports to the appropriate | ||||
191 | // sub-histogram (_PreRead(Enabled|Disabled)). | ||||
192 | void RecordPreReadExperimentTime(const char* name, base::TimeDelta time); | ||||
193 | |||||
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 194 | #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_ |