blob: 4bf3e58dcf40b20a65725b41ca0b6fbcd5e0635f [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]2e5b60a22011-11-28 15:56:4117#include "chrome/browser/ui/browser_init.h"
[email protected]b48c9182011-10-26 18:03:3018#include "content/public/browser/browser_main_parts.h"
[email protected]2e5b60a22011-11-28 15:56:4119#include "content/public/browser/browser_thread.h"
[email protected]f8abf722010-07-07 19:46:2420
[email protected]c7480942011-11-08 19:18:2721class BrowserInit;
[email protected]c1702d712011-09-08 19:41:4322class BrowserProcessImpl;
[email protected]50462bf02011-11-21 19:13:3123class ChromeBrowserMainExtraParts;
[email protected]edafd4c2011-05-10 17:18:5324class FieldTrialSynchronizer;
[email protected]f967b722011-09-07 00:58:0425class HistogramSynchronizer;
[email protected]1152b7e2009-09-14 03:26:0326class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5327class PrefService;
[email protected]c1702d712011-09-08 19:41:4328class Profile;
[email protected]08f1c5e2011-12-01 01:54:3429class StartupTimeBomb;
[email protected]f967b722011-09-07 00:58:0430class ShutdownWatcherHelper;
[email protected]c1702d712011-09-08 19:41:4331class TranslateManager;
[email protected]5f988b92011-05-18 07:14:0832
[email protected]cbce47242011-08-12 21:40:5933namespace chrome_browser {
34// For use by ShowMissingLocaleMessageBox.
35extern const char kMissingLocaleDataTitle[];
36extern const char kMissingLocaleDataMessage[];
37}
38
[email protected]10fe40c2011-11-05 03:27:4639namespace chrome_browser_metrics {
40class TrackingSynchronizer;
41}
42
[email protected]4573fbd2011-10-31 20:25:1843namespace content {
44struct MainFunctionParams;
45}
46
[email protected]f967b722011-09-07 00:58:0447class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2448 public:
[email protected]f967b722011-09-07 00:58:0449 virtual ~ChromeBrowserMainParts();
[email protected]f8abf722010-07-07 19:46:2450
[email protected]50462bf02011-11-21 19:13:3151 // Add additional ChromeBrowserMainExtraParts.
52 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4553
[email protected]f8abf722010-07-07 19:46:2454 protected:
[email protected]4573fbd2011-10-31 20:25:1855 explicit ChromeBrowserMainParts(
56 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2457
[email protected]50462bf02011-11-21 19:13:3158 // content::BrowserMainParts overrides.
[email protected]97ef83f2011-12-19 19:26:3659 // These are called in-order by content::BrowserMainLoop.
60 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
61 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
[email protected]c7480942011-11-08 19:18:2762 virtual void PreEarlyInitialization() OVERRIDE;
63 virtual void PostEarlyInitialization() OVERRIDE;
[email protected]f967b722011-09-07 00:58:0464 virtual void ToolkitInitialized() OVERRIDE;
[email protected]c7480942011-11-08 19:18:2765 virtual void PreMainMessageLoopStart() OVERRIDE;
66 virtual void PostMainMessageLoopStart() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4167 virtual void PreCreateThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3068 virtual void PreMainMessageLoopRun() OVERRIDE;
69 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
[email protected]c7480942011-11-08 19:18:2770 virtual void PostMainMessageLoopRun() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4171 virtual void PostDestroyThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3072
[email protected]97ef83f2011-12-19 19:26:3673 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
[email protected]a36773d2012-01-19 20:54:1474 // in order from PreMainMessageLoopStart(). See implementation for details.
[email protected]97ef83f2011-12-19 19:26:3675 virtual void PreProfileInit();
76 virtual void PostProfileInit();
77 virtual void PreBrowserStart();
78 virtual void PostBrowserStart();
79
[email protected]b48c9182011-10-26 18:03:3080 // Displays a warning message that we can't find any locale data files.
81 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2482
[email protected]50462bf02011-11-21 19:13:3183 const content::MainFunctionParams& parameters() const {
84 return parameters_;
85 }
86 const CommandLine& parsed_command_line() const {
87 return parsed_command_line_;
88 }
89
90 Profile* profile() { return profile_; }
[email protected]50462bf02011-11-21 19:13:3191
[email protected]1fec64352010-07-27 13:55:2192 private:
[email protected]f8abf722010-07-07 19:46:2493 // Methods for |EarlyInitialization()| ---------------------------------------
94
95 // A/B test for the maximum number of persistent connections per host.
96 void ConnectionFieldTrial();
97
98 // A/B test for determining a value for unused socket timeout.
99 void SocketTimeoutFieldTrial();
100
[email protected]78a258a2010-08-02 16:34:26101 // A/B test for the maximum number of connections per proxy server.
102 void ProxyConnectionsFieldTrial();
103
[email protected]f8abf722010-07-07 19:46:24104 // A/B test for spdy when --use-spdy not set.
105 void SpdyFieldTrial();
106
[email protected]6930c522011-07-28 22:15:19107 // A/B test for warmest socket vs. most recently used socket.
108 void WarmConnectionFieldTrial();
109
[email protected]06d94042010-08-25 01:45:22110 // A/B test for automatically establishing a backup TCP connection when a
111 // specified timeout value is reached.
112 void ConnectBackupJobsFieldTrial();
113
[email protected]67372ecf2011-09-10 01:30:46114 // Field trial to see what disabling DNS pre-resolution does to
115 // latency of page loads.
116 void PredictorFieldTrial();
117
[email protected]51a7a9d2011-09-27 17:21:41118 // Field trial to see what effect installing defaults in the NTP apps pane
119 // has on retention and general apps/webstore usage.
120 void DefaultAppsFieldTrial();
121
[email protected]0cba2962011-12-15 10:45:32122 // A field trial to see what effects launching Chrome automatically on
123 // computer startup has on retention and usage of Chrome.
124 void AutoLaunchChromeFieldTrial();
125
[email protected]069cd9952011-10-01 16:34:45126 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
127
[email protected]50462bf02011-11-21 19:13:31128 // Constructs metrics service and does related initialization, including
129 // creation of field trials. Call only after labs have been converted to
130 // switches.
[email protected]5281db1d2012-01-11 22:51:54131 void SetupMetricsAndFieldTrials();
[email protected]edafd4c2011-05-10 17:18:53132
133 // Add an invocation of your field trial init function to this method.
[email protected]12c84e22011-07-11 09:35:45134 void SetupFieldTrials(bool metrics_recording_enabled,
135 bool proxy_policy_is_set);
[email protected]edafd4c2011-05-10 17:18:53136
[email protected]5281db1d2012-01-11 22:51:54137 // Starts recording of metrics. This can only be called after we have a file
138 // thread.
139 void StartMetricsRecording();
140
[email protected]b48c9182011-10-26 18:03:30141 // Methods for Main Message Loop -------------------------------------------
142
[email protected]2e5b60a22011-11-28 15:56:41143 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30144 int PreMainMessageLoopRunImpl();
145
[email protected]f8abf722010-07-07 19:46:24146 // Members initialized on construction ---------------------------------------
147
[email protected]4573fbd2011-10-31 20:25:18148 const content::MainFunctionParams& parameters_;
[email protected]b48c9182011-10-26 18:03:30149 const CommandLine& parsed_command_line_;
150 int result_code_;
151
[email protected]08f1c5e2011-12-01 01:54:34152 // Create StartupTimeBomb object for watching jank during startup.
153 scoped_ptr<StartupTimeBomb> startup_watcher_;
154
[email protected]f967b722011-09-07 00:58:04155 // Create ShutdownWatcherHelper object for watching jank during shutdown.
156 // Please keep |shutdown_watcher| as the first object constructed, and hence
157 // it is destroyed last.
158 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24159
[email protected]f8abf722010-07-07 19:46:24160 // Creating this object starts tracking the creation and deletion of Task
161 // instance. This MUST be done before main_message_loop, so that it is
162 // destroyed after the main_message_loop.
163 tracked_objects::AutoTracking tracking_objects_;
[email protected]f8abf722010-07-07 19:46:24164
[email protected]edafd4c2011-05-10 17:18:53165 // Statistical testing infrastructure for the entire browser. NULL until
166 // SetupMetricsAndFieldTrials is called.
167 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24168
[email protected]50462bf02011-11-21 19:13:31169 // Vector of additional ChromeBrowserMainExtraParts.
170 // Parts are deleted in the inverse order they are added.
171 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
172
[email protected]0f247aea82011-09-03 03:05:51173 // Members initialized after / released before main_message_loop_ ------------
174
[email protected]c7480942011-11-08 19:18:27175 scoped_ptr<BrowserInit> browser_init_;
[email protected]c1702d712011-09-08 19:41:43176 scoped_ptr<BrowserProcessImpl> browser_process_;
[email protected]0f247aea82011-09-03 03:05:51177 scoped_refptr<HistogramSynchronizer> histogram_synchronizer_;
[email protected]10fe40c2011-11-05 03:27:46178 scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
179 tracking_synchronizer_;
[email protected]c1702d712011-09-08 19:41:43180 scoped_ptr<ProcessSingleton> process_singleton_;
[email protected]baacb232012-01-28 02:30:18181 scoped_ptr<first_run::MasterPrefs> master_prefs_;
[email protected]c1702d712011-09-08 19:41:43182 bool record_search_engine_;
183 TranslateManager* translate_manager_;
184 Profile* profile_;
185 bool run_message_loop_;
[email protected]66013922011-09-13 18:53:42186 ProcessSingleton::NotifyResult notify_result_;
[email protected]0f247aea82011-09-03 03:05:51187
[email protected]edafd4c2011-05-10 17:18:53188 // Initialized in SetupMetricsAndFieldTrials.
189 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
190
[email protected]2e5b60a22011-11-28 15:56:41191 // Members initialized in PreMainMessageLoopRun, needed in
192 // PreMainMessageLoopRunThreadsCreated.
193 bool is_first_run_;
194 bool first_run_ui_bypass_;
[email protected]2e5b60a22011-11-28 15:56:41195 PrefService* local_state_;
196 FilePath user_data_dir_;
197
198 // Members needed across shutdown methods.
199 bool restart_last_session_;
200
[email protected]3438fa82011-11-24 00:49:36201 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest,
202 WarmConnectionFieldTrial_WarmestSocket);
203 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random);
204 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
[email protected]f967b722011-09-07 00:58:04205 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24206};
207
[email protected]1152b7e2009-09-14 03:26:03208// Records the conditions that can prevent Breakpad from generating and
209// sending crash reports. The presence of a Breakpad handler (after
210// attempting to initialize crash reporting) and the presence of a debugger
211// are registered with the UMA metrics service.
212void RecordBreakpadStatusUMA(MetricsService* metrics);
213
[email protected]34f73fb2010-03-24 20:50:34214// Displays a warning message if some minimum level of OS support is not
215// present on the current platform.
216void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03217
[email protected]45d72762011-04-15 18:58:20218// Records the time from our process' startup to the present time in
219// the UMA histogram |metric_name|.
220void RecordBrowserStartupTime();
221
[email protected]28f576f2011-08-26 20:46:55222// Records a time value to an UMA histogram in the context of the
223// PreReadExperiment field-trial. This also reports to the appropriate
224// sub-histogram (_PreRead(Enabled|Disabled)).
225void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
226
[email protected]e6b5bc22011-09-08 22:01:56227#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_