blob: fb67705eb5541696ad4446e74ff517b399d924ba [file] [log] [blame]
[email protected]d15b7ca2012-01-04 01:42:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1152b7e2009-09-14 03:26:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e6b5bc22011-09-08 22:01:565#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
6#define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]1152b7e2009-09-14 03:26:038
[email protected]f8abf722010-07-07 19:46:249#include "base/basictypes.h"
[email protected]5e6efa52011-06-27 17:26:4110#include "base/gtest_prod_util.h"
[email protected]b48c9182011-10-26 18:03:3011#include "base/memory/scoped_ptr.h"
[email protected]50462bf02011-11-21 19:13:3112#include "base/memory/scoped_vector.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/field_trial.h"
[email protected]f8abf722010-07-07 19:46:2414#include "base/tracked_objects.h"
[email protected]c1702d712011-09-08 19:41:4315#include "chrome/browser/first_run/first_run.h"
[email protected]66013922011-09-13 18:53:4216#include "chrome/browser/process_singleton.h"
[email protected]61b53f972012-02-10 20:39:2317#include "chrome/browser/task_profiler/auto_tracking.h"
[email protected]2e5b60a22011-11-28 15:56:4118#include "chrome/browser/ui/browser_init.h"
[email protected]b48c9182011-10-26 18:03:3019#include "content/public/browser/browser_main_parts.h"
[email protected]2e5b60a22011-11-28 15:56:4120#include "content/public/browser/browser_thread.h"
[email protected]f8abf722010-07-07 19:46:2421
[email protected]c7480942011-11-08 19:18:2722class BrowserInit;
[email protected]c1702d712011-09-08 19:41:4323class BrowserProcessImpl;
[email protected]50462bf02011-11-21 19:13:3124class ChromeBrowserMainExtraParts;
[email protected]edafd4c2011-05-10 17:18:5325class FieldTrialSynchronizer;
[email protected]f967b722011-09-07 00:58:0426class HistogramSynchronizer;
[email protected]1152b7e2009-09-14 03:26:0327class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5328class PrefService;
[email protected]c1702d712011-09-08 19:41:4329class Profile;
[email protected]08f1c5e2011-12-01 01:54:3430class StartupTimeBomb;
[email protected]f967b722011-09-07 00:58:0431class ShutdownWatcherHelper;
[email protected]c1702d712011-09-08 19:41:4332class TranslateManager;
[email protected]5f988b92011-05-18 07:14:0833
[email protected]cbce47242011-08-12 21:40:5934namespace chrome_browser {
35// For use by ShowMissingLocaleMessageBox.
36extern const char kMissingLocaleDataTitle[];
37extern const char kMissingLocaleDataMessage[];
38}
39
[email protected]10fe40c2011-11-05 03:27:4640namespace chrome_browser_metrics {
41class TrackingSynchronizer;
42}
43
[email protected]4573fbd2011-10-31 20:25:1844namespace content {
45struct MainFunctionParams;
46}
47
[email protected]f967b722011-09-07 00:58:0448class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2449 public:
[email protected]f967b722011-09-07 00:58:0450 virtual ~ChromeBrowserMainParts();
[email protected]f8abf722010-07-07 19:46:2451
[email protected]50462bf02011-11-21 19:13:3152 // Add additional ChromeBrowserMainExtraParts.
53 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4554
[email protected]f8abf722010-07-07 19:46:2455 protected:
[email protected]4573fbd2011-10-31 20:25:1856 explicit ChromeBrowserMainParts(
57 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2458
[email protected]50462bf02011-11-21 19:13:3159 // content::BrowserMainParts overrides.
[email protected]97ef83f2011-12-19 19:26:3660 // 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]c7480942011-11-08 19:18:2763 virtual void PreEarlyInitialization() OVERRIDE;
64 virtual void PostEarlyInitialization() OVERRIDE;
[email protected]f967b722011-09-07 00:58:0465 virtual void ToolkitInitialized() OVERRIDE;
[email protected]c7480942011-11-08 19:18:2766 virtual void PreMainMessageLoopStart() OVERRIDE;
[email protected]c7480942011-11-08 19:18:2767 virtual void PostMainMessageLoopStart() OVERRIDE;
[email protected]69479b922012-02-02 09:56:2068 virtual int PreCreateThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3069 virtual void PreMainMessageLoopRun() OVERRIDE;
70 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
[email protected]c7480942011-11-08 19:18:2771 virtual void PostMainMessageLoopRun() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4172 virtual void PostDestroyThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3073
[email protected]97ef83f2011-12-19 19:26:3674 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
[email protected]a36773d2012-01-19 20:54:1475 // in order from PreMainMessageLoopStart(). See implementation for details.
[email protected]97ef83f2011-12-19 19:26:3676 virtual void PreProfileInit();
77 virtual void PostProfileInit();
78 virtual void PreBrowserStart();
79 virtual void PostBrowserStart();
80
[email protected]b48c9182011-10-26 18:03:3081 // Displays a warning message that we can't find any locale data files.
82 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2483
[email protected]50462bf02011-11-21 19:13:3184 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]a5e8c6d2012-04-09 20:22:0193 const PrefService* local_state() const { return local_state_; }
94
[email protected]1fec64352010-07-27 13:55:2195 private:
[email protected]f8abf722010-07-07 19:46:2496 // 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]78a258a2010-08-02 16:34:26104 // A/B test for the maximum number of connections per proxy server.
105 void ProxyConnectionsFieldTrial();
106
[email protected]f8abf722010-07-07 19:46:24107 // A/B test for spdy when --use-spdy not set.
108 void SpdyFieldTrial();
109
[email protected]6930c522011-07-28 22:15:19110 // A/B test for warmest socket vs. most recently used socket.
111 void WarmConnectionFieldTrial();
112
[email protected]06d94042010-08-25 01:45:22113 // A/B test for automatically establishing a backup TCP connection when a
114 // specified timeout value is reached.
115 void ConnectBackupJobsFieldTrial();
116
[email protected]67372ecf2011-09-10 01:30:46117 // Field trial to see what disabling DNS pre-resolution does to
118 // latency of page loads.
119 void PredictorFieldTrial();
120
[email protected]51a7a9d2011-09-27 17:21:41121 // 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]0cba2962011-12-15 10:45:32125 // 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]17593332012-04-20 06:05:02129 // Field trial for testing domain bound certs.
130 void DomainBoundCertsFieldTrial();
131
[email protected]c737d482012-04-26 15:48:26132 // A collection of field trials intended to test the uniformity and
133 // correctness of the field trial control, bucketing and reporting systems.
134 void SetupUniformityFieldTrials();
135
[email protected]069cd9952011-10-01 16:34:45136 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
137
[email protected]50462bf02011-11-21 19:13:31138 // Constructs metrics service and does related initialization, including
139 // creation of field trials. Call only after labs have been converted to
140 // switches.
[email protected]5281db1d2012-01-11 22:51:54141 void SetupMetricsAndFieldTrials();
[email protected]edafd4c2011-05-10 17:18:53142
143 // Add an invocation of your field trial init function to this method.
[email protected]12c84e22011-07-11 09:35:45144 void SetupFieldTrials(bool metrics_recording_enabled,
145 bool proxy_policy_is_set);
[email protected]edafd4c2011-05-10 17:18:53146
[email protected]5281db1d2012-01-11 22:51:54147 // Starts recording of metrics. This can only be called after we have a file
148 // thread.
149 void StartMetricsRecording();
150
[email protected]5cbeeef72012-02-08 02:05:18151 // Returns true if the user opted in to sending metric reports.
152 bool IsMetricsReportingEnabled();
153
[email protected]b48c9182011-10-26 18:03:30154 // Methods for Main Message Loop -------------------------------------------
155
[email protected]2e5b60a22011-11-28 15:56:41156 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30157 int PreMainMessageLoopRunImpl();
158
[email protected]f8abf722010-07-07 19:46:24159 // Members initialized on construction ---------------------------------------
160
[email protected]4573fbd2011-10-31 20:25:18161 const content::MainFunctionParams& parameters_;
[email protected]b48c9182011-10-26 18:03:30162 const CommandLine& parsed_command_line_;
163 int result_code_;
164
[email protected]08f1c5e2011-12-01 01:54:34165 // Create StartupTimeBomb object for watching jank during startup.
166 scoped_ptr<StartupTimeBomb> startup_watcher_;
167
[email protected]f967b722011-09-07 00:58:04168 // Create ShutdownWatcherHelper object for watching jank during shutdown.
169 // Please keep |shutdown_watcher| as the first object constructed, and hence
170 // it is destroyed last.
171 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24172
[email protected]f8abf722010-07-07 19:46:24173 // Creating this object starts tracking the creation and deletion of Task
174 // instance. This MUST be done before main_message_loop, so that it is
175 // destroyed after the main_message_loop.
[email protected]61b53f972012-02-10 20:39:23176 task_profiler::AutoTracking tracking_objects_;
[email protected]f8abf722010-07-07 19:46:24177
[email protected]edafd4c2011-05-10 17:18:53178 // Statistical testing infrastructure for the entire browser. NULL until
179 // SetupMetricsAndFieldTrials is called.
180 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24181
[email protected]50462bf02011-11-21 19:13:31182 // Vector of additional ChromeBrowserMainExtraParts.
183 // Parts are deleted in the inverse order they are added.
184 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
185
[email protected]0f247aea82011-09-03 03:05:51186 // Members initialized after / released before main_message_loop_ ------------
187
[email protected]c7480942011-11-08 19:18:27188 scoped_ptr<BrowserInit> browser_init_;
[email protected]c1702d712011-09-08 19:41:43189 scoped_ptr<BrowserProcessImpl> browser_process_;
[email protected]0f247aea82011-09-03 03:05:51190 scoped_refptr<HistogramSynchronizer> histogram_synchronizer_;
[email protected]10fe40c2011-11-05 03:27:46191 scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
192 tracking_synchronizer_;
[email protected]c1702d712011-09-08 19:41:43193 scoped_ptr<ProcessSingleton> process_singleton_;
[email protected]baacb232012-01-28 02:30:18194 scoped_ptr<first_run::MasterPrefs> master_prefs_;
[email protected]c1702d712011-09-08 19:41:43195 bool record_search_engine_;
196 TranslateManager* translate_manager_;
197 Profile* profile_;
198 bool run_message_loop_;
[email protected]66013922011-09-13 18:53:42199 ProcessSingleton::NotifyResult notify_result_;
[email protected]0f247aea82011-09-03 03:05:51200
[email protected]edafd4c2011-05-10 17:18:53201 // Initialized in SetupMetricsAndFieldTrials.
202 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
203
[email protected]2e5b60a22011-11-28 15:56:41204 // Members initialized in PreMainMessageLoopRun, needed in
205 // PreMainMessageLoopRunThreadsCreated.
206 bool is_first_run_;
207 bool first_run_ui_bypass_;
[email protected]2e5b60a22011-11-28 15:56:41208 PrefService* local_state_;
209 FilePath user_data_dir_;
210
211 // Members needed across shutdown methods.
212 bool restart_last_session_;
213
[email protected]1948a4782012-04-30 13:45:44214 // Tests can set this to true to disable restricting cookie access in the
215 // network stack, as this can only be done once.
216 static bool disable_enforcing_cookie_policies_for_tests_;
217
218 friend class BrowserMainTest;
[email protected]3438fa82011-11-24 00:49:36219 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest,
220 WarmConnectionFieldTrial_WarmestSocket);
221 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random);
222 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
[email protected]f967b722011-09-07 00:58:04223 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24224};
225
[email protected]1152b7e2009-09-14 03:26:03226// Records the conditions that can prevent Breakpad from generating and
227// sending crash reports. The presence of a Breakpad handler (after
228// attempting to initialize crash reporting) and the presence of a debugger
229// are registered with the UMA metrics service.
230void RecordBreakpadStatusUMA(MetricsService* metrics);
231
[email protected]34f73fb2010-03-24 20:50:34232// Displays a warning message if some minimum level of OS support is not
233// present on the current platform.
234void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03235
[email protected]45d72762011-04-15 18:58:20236// Records the time from our process' startup to the present time in
237// the UMA histogram |metric_name|.
238void RecordBrowserStartupTime();
239
[email protected]28f576f2011-08-26 20:46:55240// Records a time value to an UMA histogram in the context of the
241// PreReadExperiment field-trial. This also reports to the appropriate
242// sub-histogram (_PreRead(Enabled|Disabled)).
243void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
244
[email protected]e6b5bc22011-09-08 22:01:56245#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_