blob: a663a3947943d3ba7d641b00727af17224a690bb [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
5#ifndef CHROME_BROWSER_BROWSER_MAIN_H_
6#define CHROME_BROWSER_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]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/field_trial.h"
[email protected]6930c522011-07-28 22:15:1913#include "base/scoped_ptr.h"
[email protected]f8abf722010-07-07 19:46:2414#include "base/tracked_objects.h"
15
[email protected]092b04e2010-10-12 23:23:4416class BrowserThread;
[email protected]f8abf722010-07-07 19:46:2417class CommandLine;
[email protected]edafd4c2011-05-10 17:18:5318class FieldTrialSynchronizer;
[email protected]1fec64352010-07-27 13:55:2119class HighResolutionTimerManager;
[email protected]1152b7e2009-09-14 03:26:0320struct MainFunctionParams;
[email protected]1fec64352010-07-27 13:55:2121class MessageLoop;
[email protected]1152b7e2009-09-14 03:26:0322class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5323class PrefService;
[email protected]1fec64352010-07-27 13:55:2124
[email protected]e41d7dd2011-05-18 07:29:5625namespace base {
26class SystemMonitor;
[email protected]4ae61df2011-01-19 15:29:4727}
28
[email protected]e41d7dd2011-05-18 07:29:5629namespace net {
30class NetworkChangeNotifier;
[email protected]5f988b92011-05-18 07:14:0831}
32
[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]f8abf722010-07-07 19:46:2439// BrowserMainParts:
40// This class contains different "stages" to be executed in |BrowserMain()|,
41// mostly initialization. This is made into a class rather than just functions
42// so each stage can create and maintain state. Each part is represented by a
43// single method (e.g., "EarlyInitialization()"), which does the following:
44// - calls a method (e.g., "PreEarlyInitialization()") which individual
45// platforms can override to provide platform-specific code which is to be
46// executed before the common code;
47// - calls various methods for things common to all platforms (for that given
48// stage); and
49// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
50// code to be called after the common code.
51// As indicated above, platforms should override the default "Pre...()" and
52// "Post...()" methods when necessary; they need not call the superclass's
53// implementation (which is empty).
54//
55// Parts:
56// - EarlyInitialization: things which should be done as soon as possible on
57// program start (such as setting up signal handlers) and things to be done
58// at some generic time before the start of the main message loop.
[email protected]1fec64352010-07-27 13:55:2159// - MainMessageLoopStart: things beginning with the start of the main message
60// loop and ending with initialization of the main thread; platform-specific
61// things which should be done immediately before the start of the main
62// message loop should go in |PreMainMessageLoopStart()|.
[email protected]f8abf722010-07-07 19:46:2463// - (more to come)
[email protected]d7dbe28c2010-07-29 04:33:4764//
65// How to add stuff (to existing parts):
66// - Figure out when your new code should be executed. What must happen
67// before/after your code is executed? Are there performance reasons for
68// running your code at a particular time? Document these things!
69// - Split out any platform-specific bits. Please avoid #ifdefs it at all
70// possible. You have two choices for platform-specific code: (1) Execute it
71// from one of the platform-specific |Pre/Post...()| methods; do this if the
72// code is unique to a platform type. Or (2) execute it from one of the
73// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
74// implementations of your code (in a virtual method); do this if you need to
75// provide different implementations across most/all platforms.
76// - Unless your new code is just one or two lines, put it into a separate
77// method with a well-defined purpose. (Likewise, if you're adding to an
78// existing chunk which makes it longer than one or two lines, please move
79// the code out into a separate method.)
[email protected]f8abf722010-07-07 19:46:2480class BrowserMainParts {
81 public:
82 // This static method is to be implemented by each platform and should
83 // instantiate the appropriate subclass.
84 static BrowserMainParts* CreateBrowserMainParts(
85 const MainFunctionParams& parameters);
86
[email protected]1fec64352010-07-27 13:55:2187 virtual ~BrowserMainParts();
88
[email protected]f8abf722010-07-07 19:46:2489 // Parts to be called by |BrowserMain()|.
90 void EarlyInitialization();
[email protected]1fec64352010-07-27 13:55:2191 void MainMessageLoopStart();
[email protected]f8abf722010-07-07 19:46:2492
[email protected]edafd4c2011-05-10 17:18:5393 // Constructs metrics service and does related initialization, including
94 // creation of field trials. Call only after labs have been converted to
95 // switches.
96 MetricsService* SetupMetricsAndFieldTrials(
97 const CommandLine& parsed_command_line,
98 PrefService* local_state);
[email protected]68adccab2011-01-26 21:18:1399
[email protected]f8abf722010-07-07 19:46:24100 protected:
101 explicit BrowserMainParts(const MainFunctionParams& parameters);
102
[email protected]f8abf722010-07-07 19:46:24103 // Accessors for data members (below) ----------------------------------------
104 const MainFunctionParams& parameters() const {
105 return parameters_;
106 }
107 const CommandLine& parsed_command_line() const {
108 return parsed_command_line_;
109 }
[email protected]1fec64352010-07-27 13:55:21110 MessageLoop& main_message_loop() const {
111 return *main_message_loop_;
112 }
[email protected]f8abf722010-07-07 19:46:24113
[email protected]c1275ae2010-07-12 17:40:49114 // Methods to be overridden to provide platform-specific code; these
115 // correspond to the "parts" above.
116 virtual void PreEarlyInitialization() {}
117 virtual void PostEarlyInitialization() {}
[email protected]1fec64352010-07-27 13:55:21118 virtual void PreMainMessageLoopStart() {}
119 virtual void PostMainMessageLoopStart() {}
[email protected]c1275ae2010-07-12 17:40:49120
[email protected]1fec64352010-07-27 13:55:21121 private:
[email protected]f8abf722010-07-07 19:46:24122 // Methods for |EarlyInitialization()| ---------------------------------------
123
124 // A/B test for the maximum number of persistent connections per host.
125 void ConnectionFieldTrial();
126
127 // A/B test for determining a value for unused socket timeout.
128 void SocketTimeoutFieldTrial();
129
[email protected]78a258a2010-08-02 16:34:26130 // A/B test for the maximum number of connections per proxy server.
131 void ProxyConnectionsFieldTrial();
132
[email protected]f8abf722010-07-07 19:46:24133 // A/B test for spdy when --use-spdy not set.
134 void SpdyFieldTrial();
135
[email protected]6930c522011-07-28 22:15:19136 // A/B test for warmest socket vs. most recently used socket.
137 void WarmConnectionFieldTrial();
138
[email protected]06d94042010-08-25 01:45:22139 // A/B test for automatically establishing a backup TCP connection when a
140 // specified timeout value is reached.
141 void ConnectBackupJobsFieldTrial();
142
[email protected]6930c522011-07-28 22:15:19143 // A/B test for using a different host prefix in Google search suggest.
144 void SuggestPrefixFieldTrial();
[email protected]5e6efa52011-06-27 17:26:41145
[email protected]f8abf722010-07-07 19:46:24146 // Used to initialize NSPR where appropriate.
[email protected]d7dbe28c2010-07-29 04:33:47147 virtual void InitializeSSL() = 0;
[email protected]f8abf722010-07-07 19:46:24148
[email protected]1fec64352010-07-27 13:55:21149 // Methods for |MainMessageLoopStart()| --------------------------------------
150
151 void InitializeMainThread();
152
[email protected]edafd4c2011-05-10 17:18:53153 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
154
155 static MetricsService* InitializeMetrics(
156 const CommandLine& parsed_command_line,
157 const PrefService* local_state);
158
159 // Add an invocation of your field trial init function to this method.
[email protected]12c84e22011-07-11 09:35:45160 void SetupFieldTrials(bool metrics_recording_enabled,
161 bool proxy_policy_is_set);
[email protected]edafd4c2011-05-10 17:18:53162
[email protected]f8abf722010-07-07 19:46:24163 // Members initialized on construction ---------------------------------------
164
165 const MainFunctionParams& parameters_;
166 const CommandLine& parsed_command_line_;
167
168#if defined(TRACK_ALL_TASK_OBJECTS)
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.
172 tracked_objects::AutoTracking tracking_objects_;
173#endif
174
[email protected]edafd4c2011-05-10 17:18:53175 // Statistical testing infrastructure for the entire browser. NULL until
176 // SetupMetricsAndFieldTrials is called.
177 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24178
[email protected]1fec64352010-07-27 13:55:21179 // Members initialized in |MainMessageLoopStart()| ---------------------------
180 scoped_ptr<MessageLoop> main_message_loop_;
[email protected]e41d7dd2011-05-18 07:29:56181 scoped_ptr<base::SystemMonitor> system_monitor_;
[email protected]1fec64352010-07-27 13:55:21182 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
183 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
[email protected]092b04e2010-10-12 23:23:44184 scoped_ptr<BrowserThread> main_thread_;
[email protected]1fec64352010-07-27 13:55:21185
[email protected]edafd4c2011-05-10 17:18:53186 // Initialized in SetupMetricsAndFieldTrials.
187 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
188
[email protected]5e6efa52011-06-27 17:26:41189 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket);
190 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random);
191 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
[email protected]f8abf722010-07-07 19:46:24192 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
193};
194
195
[email protected]1152b7e2009-09-14 03:26:03196// Perform platform-specific work that needs to be done after the main event
197// loop has ended.
[email protected]3b6aa8b62009-09-15 21:36:11198void DidEndMainMessageLoop();
[email protected]1152b7e2009-09-14 03:26:03199
200// Records the conditions that can prevent Breakpad from generating and
201// sending crash reports. The presence of a Breakpad handler (after
202// attempting to initialize crash reporting) and the presence of a debugger
203// are registered with the UMA metrics service.
204void RecordBreakpadStatusUMA(MetricsService* metrics);
205
[email protected]34f73fb2010-03-24 20:50:34206// Displays a warning message if some minimum level of OS support is not
207// present on the current platform.
208void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03209
[email protected]cbce47242011-08-12 21:40:59210// Displays a warning message that we can't find any locale data files.
211void ShowMissingLocaleMessageBox();
212
[email protected]45d72762011-04-15 18:58:20213// Records the time from our process' startup to the present time in
214// the UMA histogram |metric_name|.
215void RecordBrowserStartupTime();
216
[email protected]85acecb2011-08-05 05:28:05217// Records a Startup category value to an UMA histogram in the context of the
218// PreReadExperiment field-trial. This will also report to the appropriate
219// Startup.HistogramName_PreRead(Enabled|Disabled) histogram as appropriate.
220// This is only called from OS_WIN specific code, so the implementation is
221// in browser_main_win.cc. This is a Windows specific experiment.
222void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
223
[email protected]1152b7e2009-09-14 03:26:03224#endif // CHROME_BROWSER_BROWSER_MAIN_H_