blob: 5ef3eb9fa7d751246a042ac2f8506c0e064c27dc [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 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]f967b722011-09-07 00:58:0429class ShutdownWatcherHelper;
[email protected]c1702d712011-09-08 19:41:4330class TranslateManager;
[email protected]5f988b92011-05-18 07:14:0831
[email protected]cbce47242011-08-12 21:40:5932namespace chrome_browser {
33// For use by ShowMissingLocaleMessageBox.
34extern const char kMissingLocaleDataTitle[];
35extern const char kMissingLocaleDataMessage[];
36}
37
[email protected]10fe40c2011-11-05 03:27:4638namespace chrome_browser_metrics {
39class TrackingSynchronizer;
40}
41
[email protected]4573fbd2011-10-31 20:25:1842namespace content {
43struct MainFunctionParams;
44}
45
[email protected]f967b722011-09-07 00:58:0446class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2447 public:
[email protected]f967b722011-09-07 00:58:0448 virtual ~ChromeBrowserMainParts();
[email protected]f8abf722010-07-07 19:46:2449
[email protected]50462bf02011-11-21 19:13:3150 // Add additional ChromeBrowserMainExtraParts.
51 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4552
[email protected]f8abf722010-07-07 19:46:2453 protected:
[email protected]4573fbd2011-10-31 20:25:1854 explicit ChromeBrowserMainParts(
55 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2456
[email protected]50462bf02011-11-21 19:13:3157 // content::BrowserMainParts overrides.
[email protected]c7480942011-11-08 19:18:2758 virtual void PreEarlyInitialization() OVERRIDE;
59 virtual void PostEarlyInitialization() OVERRIDE;
[email protected]f967b722011-09-07 00:58:0460 virtual void ToolkitInitialized() OVERRIDE;
[email protected]c7480942011-11-08 19:18:2761 virtual void PreMainMessageLoopStart() OVERRIDE;
62 virtual void PostMainMessageLoopStart() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4163 virtual void PreCreateThreads() OVERRIDE;
64 virtual void PreStartThread(content::BrowserThread::ID identifier) OVERRIDE;
65 virtual void PostStartThread(content::BrowserThread::ID identifier) OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3066 virtual void PreMainMessageLoopRun() OVERRIDE;
67 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
[email protected]c7480942011-11-08 19:18:2768 virtual void PostMainMessageLoopRun() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4169 virtual void PreStopThread(content::BrowserThread::ID identifier) OVERRIDE;
70 virtual void PostStopThread(content::BrowserThread::ID identifier) OVERRIDE;
71 virtual void PostDestroyThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3072
73 // Displays a warning message that we can't find any locale data files.
74 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2475
[email protected]50462bf02011-11-21 19:13:3176 const content::MainFunctionParams& parameters() const {
77 return parameters_;
78 }
79 const CommandLine& parsed_command_line() const {
80 return parsed_command_line_;
81 }
82
83 Profile* profile() { return profile_; }
84
[email protected]1fec64352010-07-27 13:55:2185 private:
[email protected]f8abf722010-07-07 19:46:2486 // Methods for |EarlyInitialization()| ---------------------------------------
87
88 // A/B test for the maximum number of persistent connections per host.
89 void ConnectionFieldTrial();
90
91 // A/B test for determining a value for unused socket timeout.
92 void SocketTimeoutFieldTrial();
93
[email protected]78a258a2010-08-02 16:34:2694 // A/B test for the maximum number of connections per proxy server.
95 void ProxyConnectionsFieldTrial();
96
[email protected]f8abf722010-07-07 19:46:2497 // A/B test for spdy when --use-spdy not set.
98 void SpdyFieldTrial();
99
[email protected]6930c522011-07-28 22:15:19100 // A/B test for warmest socket vs. most recently used socket.
101 void WarmConnectionFieldTrial();
102
[email protected]06d94042010-08-25 01:45:22103 // A/B test for automatically establishing a backup TCP connection when a
104 // specified timeout value is reached.
105 void ConnectBackupJobsFieldTrial();
106
[email protected]67372ecf2011-09-10 01:30:46107 // Field trial to see what disabling DNS pre-resolution does to
108 // latency of page loads.
109 void PredictorFieldTrial();
110
[email protected]51a7a9d2011-09-27 17:21:41111 // Field trial to see what effect installing defaults in the NTP apps pane
112 // has on retention and general apps/webstore usage.
113 void DefaultAppsFieldTrial();
114
[email protected]069cd9952011-10-01 16:34:45115 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
116
[email protected]50462bf02011-11-21 19:13:31117 // Constructs metrics service and does related initialization, including
118 // creation of field trials. Call only after labs have been converted to
119 // switches.
120 MetricsService* SetupMetricsAndFieldTrials(PrefService* local_state);
121
[email protected]069cd9952011-10-01 16:34:45122 static MetricsService* InitializeMetrics(
[email protected]edafd4c2011-05-10 17:18:53123 const CommandLine& parsed_command_line,
124 const PrefService* local_state);
125
126 // Add an invocation of your field trial init function to this method.
[email protected]12c84e22011-07-11 09:35:45127 void SetupFieldTrials(bool metrics_recording_enabled,
128 bool proxy_policy_is_set);
[email protected]edafd4c2011-05-10 17:18:53129
[email protected]b48c9182011-10-26 18:03:30130 // Methods for Main Message Loop -------------------------------------------
131
[email protected]2e5b60a22011-11-28 15:56:41132 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30133 int PreMainMessageLoopRunImpl();
134
[email protected]f8abf722010-07-07 19:46:24135 // Members initialized on construction ---------------------------------------
136
[email protected]4573fbd2011-10-31 20:25:18137 const content::MainFunctionParams& parameters_;
[email protected]b48c9182011-10-26 18:03:30138 const CommandLine& parsed_command_line_;
139 int result_code_;
140
[email protected]f967b722011-09-07 00:58:04141 // Create ShutdownWatcherHelper object for watching jank during shutdown.
142 // Please keep |shutdown_watcher| as the first object constructed, and hence
143 // it is destroyed last.
144 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24145
[email protected]f8abf722010-07-07 19:46:24146 // Creating this object starts tracking the creation and deletion of Task
147 // instance. This MUST be done before main_message_loop, so that it is
148 // destroyed after the main_message_loop.
149 tracked_objects::AutoTracking tracking_objects_;
[email protected]f8abf722010-07-07 19:46:24150
[email protected]edafd4c2011-05-10 17:18:53151 // Statistical testing infrastructure for the entire browser. NULL until
152 // SetupMetricsAndFieldTrials is called.
153 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24154
[email protected]50462bf02011-11-21 19:13:31155 // Vector of additional ChromeBrowserMainExtraParts.
156 // Parts are deleted in the inverse order they are added.
157 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
158
[email protected]0f247aea82011-09-03 03:05:51159 // Members initialized after / released before main_message_loop_ ------------
160
[email protected]c7480942011-11-08 19:18:27161 scoped_ptr<BrowserInit> browser_init_;
[email protected]c1702d712011-09-08 19:41:43162 scoped_ptr<BrowserProcessImpl> browser_process_;
[email protected]0f247aea82011-09-03 03:05:51163 scoped_refptr<HistogramSynchronizer> histogram_synchronizer_;
[email protected]10fe40c2011-11-05 03:27:46164 scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
165 tracking_synchronizer_;
[email protected]c1702d712011-09-08 19:41:43166 scoped_ptr<ProcessSingleton> process_singleton_;
167 scoped_ptr<FirstRun::MasterPrefs> master_prefs_;
168 bool record_search_engine_;
169 TranslateManager* translate_manager_;
170 Profile* profile_;
171 bool run_message_loop_;
[email protected]66013922011-09-13 18:53:42172 ProcessSingleton::NotifyResult notify_result_;
[email protected]0f247aea82011-09-03 03:05:51173
[email protected]edafd4c2011-05-10 17:18:53174 // Initialized in SetupMetricsAndFieldTrials.
175 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
176
[email protected]2e5b60a22011-11-28 15:56:41177 // Members initialized in PreMainMessageLoopRun, needed in
178 // PreMainMessageLoopRunThreadsCreated.
179 bool is_first_run_;
180 bool first_run_ui_bypass_;
181 MetricsService* metrics_;
182 PrefService* local_state_;
183 FilePath user_data_dir_;
184
185 // Members needed across shutdown methods.
186 bool restart_last_session_;
187
[email protected]3438fa82011-11-24 00:49:36188 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest,
189 WarmConnectionFieldTrial_WarmestSocket);
190 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random);
191 FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
[email protected]f967b722011-09-07 00:58:04192 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24193};
194
[email protected]1152b7e2009-09-14 03:26:03195// Records the conditions that can prevent Breakpad from generating and
196// sending crash reports. The presence of a Breakpad handler (after
197// attempting to initialize crash reporting) and the presence of a debugger
198// are registered with the UMA metrics service.
199void RecordBreakpadStatusUMA(MetricsService* metrics);
200
[email protected]34f73fb2010-03-24 20:50:34201// Displays a warning message if some minimum level of OS support is not
202// present on the current platform.
203void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03204
[email protected]45d72762011-04-15 18:58:20205// Records the time from our process' startup to the present time in
206// the UMA histogram |metric_name|.
207void RecordBrowserStartupTime();
208
[email protected]28f576f2011-08-26 20:46:55209// Records a time value to an UMA histogram in the context of the
210// PreReadExperiment field-trial. This also reports to the appropriate
211// sub-histogram (_PreRead(Enabled|Disabled)).
212void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
213
[email protected]e6b5bc22011-09-08 22:01:56214#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_