blob: 85dce6f94000f2ae99a8bdc35b832843c5e47951 [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]f8abf722010-07-07 19:46:2413#include "base/tracked_objects.h"
14
[email protected]092b04e2010-10-12 23:23:4415class BrowserThread;
[email protected]f8abf722010-07-07 19:46:2416class CommandLine;
[email protected]edafd4c2011-05-10 17:18:5317class FieldTrialSynchronizer;
[email protected]1fec64352010-07-27 13:55:2118class HighResolutionTimerManager;
[email protected]1152b7e2009-09-14 03:26:0319struct MainFunctionParams;
[email protected]1fec64352010-07-27 13:55:2120class MessageLoop;
[email protected]1152b7e2009-09-14 03:26:0321class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5322class PrefService;
[email protected]1fec64352010-07-27 13:55:2123
[email protected]e41d7dd2011-05-18 07:29:5624namespace base {
25class SystemMonitor;
[email protected]4ae61df2011-01-19 15:29:4726}
27
[email protected]e41d7dd2011-05-18 07:29:5628namespace net {
29class NetworkChangeNotifier;
[email protected]5f988b92011-05-18 07:14:0830}
31
[email protected]f8abf722010-07-07 19:46:2432// BrowserMainParts:
33// This class contains different "stages" to be executed in |BrowserMain()|,
34// mostly initialization. This is made into a class rather than just functions
35// so each stage can create and maintain state. Each part is represented by a
36// single method (e.g., "EarlyInitialization()"), which does the following:
37// - calls a method (e.g., "PreEarlyInitialization()") which individual
38// platforms can override to provide platform-specific code which is to be
39// executed before the common code;
40// - calls various methods for things common to all platforms (for that given
41// stage); and
42// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
43// code to be called after the common code.
44// As indicated above, platforms should override the default "Pre...()" and
45// "Post...()" methods when necessary; they need not call the superclass's
46// implementation (which is empty).
47//
48// Parts:
49// - EarlyInitialization: things which should be done as soon as possible on
50// program start (such as setting up signal handlers) and things to be done
51// at some generic time before the start of the main message loop.
[email protected]1fec64352010-07-27 13:55:2152// - MainMessageLoopStart: things beginning with the start of the main message
53// loop and ending with initialization of the main thread; platform-specific
54// things which should be done immediately before the start of the main
55// message loop should go in |PreMainMessageLoopStart()|.
[email protected]f8abf722010-07-07 19:46:2456// - (more to come)
[email protected]d7dbe28c2010-07-29 04:33:4757//
58// How to add stuff (to existing parts):
59// - Figure out when your new code should be executed. What must happen
60// before/after your code is executed? Are there performance reasons for
61// running your code at a particular time? Document these things!
62// - Split out any platform-specific bits. Please avoid #ifdefs it at all
63// possible. You have two choices for platform-specific code: (1) Execute it
64// from one of the platform-specific |Pre/Post...()| methods; do this if the
65// code is unique to a platform type. Or (2) execute it from one of the
66// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
67// implementations of your code (in a virtual method); do this if you need to
68// provide different implementations across most/all platforms.
69// - Unless your new code is just one or two lines, put it into a separate
70// method with a well-defined purpose. (Likewise, if you're adding to an
71// existing chunk which makes it longer than one or two lines, please move
72// the code out into a separate method.)
[email protected]f8abf722010-07-07 19:46:2473class BrowserMainParts {
74 public:
75 // This static method is to be implemented by each platform and should
76 // instantiate the appropriate subclass.
77 static BrowserMainParts* CreateBrowserMainParts(
78 const MainFunctionParams& parameters);
79
[email protected]1fec64352010-07-27 13:55:2180 virtual ~BrowserMainParts();
81
[email protected]f8abf722010-07-07 19:46:2482 // Parts to be called by |BrowserMain()|.
83 void EarlyInitialization();
[email protected]1fec64352010-07-27 13:55:2184 void MainMessageLoopStart();
[email protected]f8abf722010-07-07 19:46:2485
[email protected]edafd4c2011-05-10 17:18:5386 // Constructs metrics service and does related initialization, including
87 // creation of field trials. Call only after labs have been converted to
88 // switches.
89 MetricsService* SetupMetricsAndFieldTrials(
90 const CommandLine& parsed_command_line,
91 PrefService* local_state);
[email protected]68adccab2011-01-26 21:18:1392
[email protected]f8abf722010-07-07 19:46:2493 protected:
94 explicit BrowserMainParts(const MainFunctionParams& parameters);
95
[email protected]f8abf722010-07-07 19:46:2496 // Accessors for data members (below) ----------------------------------------
97 const MainFunctionParams& parameters() const {
98 return parameters_;
99 }
100 const CommandLine& parsed_command_line() const {
101 return parsed_command_line_;
102 }
[email protected]1fec64352010-07-27 13:55:21103 MessageLoop& main_message_loop() const {
104 return *main_message_loop_;
105 }
[email protected]f8abf722010-07-07 19:46:24106
[email protected]c1275ae2010-07-12 17:40:49107 // Methods to be overridden to provide platform-specific code; these
108 // correspond to the "parts" above.
109 virtual void PreEarlyInitialization() {}
110 virtual void PostEarlyInitialization() {}
[email protected]1fec64352010-07-27 13:55:21111 virtual void PreMainMessageLoopStart() {}
112 virtual void PostMainMessageLoopStart() {}
[email protected]c1275ae2010-07-12 17:40:49113
[email protected]1fec64352010-07-27 13:55:21114 private:
[email protected]f8abf722010-07-07 19:46:24115 // Methods for |EarlyInitialization()| ---------------------------------------
116
117 // A/B test for the maximum number of persistent connections per host.
118 void ConnectionFieldTrial();
119
120 // A/B test for determining a value for unused socket timeout.
121 void SocketTimeoutFieldTrial();
122
[email protected]78a258a2010-08-02 16:34:26123 // A/B test for the maximum number of connections per proxy server.
124 void ProxyConnectionsFieldTrial();
125
[email protected]f8abf722010-07-07 19:46:24126 // A/B test for spdy when --use-spdy not set.
127 void SpdyFieldTrial();
128
[email protected]06d94042010-08-25 01:45:22129 // A/B test for automatically establishing a backup TCP connection when a
130 // specified timeout value is reached.
131 void ConnectBackupJobsFieldTrial();
132
[email protected]5e6efa52011-06-27 17:26:41133 // A/B test for warmest socket vs. most recently used socket.
134 void WarmConnectionFieldTrial();
135
[email protected]f8abf722010-07-07 19:46:24136 // Used to initialize NSPR where appropriate.
[email protected]d7dbe28c2010-07-29 04:33:47137 virtual void InitializeSSL() = 0;
[email protected]f8abf722010-07-07 19:46:24138
[email protected]1fec64352010-07-27 13:55:21139 // Methods for |MainMessageLoopStart()| --------------------------------------
140
141 void InitializeMainThread();
142
[email protected]edafd4c2011-05-10 17:18:53143 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
144
145 static MetricsService* InitializeMetrics(
146 const CommandLine& parsed_command_line,
147 const PrefService* local_state);
148
149 // Add an invocation of your field trial init function to this method.
[email protected]12c84e22011-07-11 09:35:45150 void SetupFieldTrials(bool metrics_recording_enabled,
151 bool proxy_policy_is_set);
[email protected]edafd4c2011-05-10 17:18:53152
[email protected]f8abf722010-07-07 19:46:24153 // Members initialized on construction ---------------------------------------
154
155 const MainFunctionParams& parameters_;
156 const CommandLine& parsed_command_line_;
157
158#if defined(TRACK_ALL_TASK_OBJECTS)
159 // Creating this object starts tracking the creation and deletion of Task
160 // instance. This MUST be done before main_message_loop, so that it is
161 // destroyed after the main_message_loop.
162 tracked_objects::AutoTracking tracking_objects_;
163#endif
164
[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]1fec64352010-07-27 13:55:21169 // Members initialized in |MainMessageLoopStart()| ---------------------------
170 scoped_ptr<MessageLoop> main_message_loop_;
[email protected]e41d7dd2011-05-18 07:29:56171 scoped_ptr<base::SystemMonitor> system_monitor_;
[email protected]1fec64352010-07-27 13:55:21172 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
173 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
[email protected]092b04e2010-10-12 23:23:44174 scoped_ptr<BrowserThread> main_thread_;
[email protected]1fec64352010-07-27 13:55:21175
[email protected]edafd4c2011-05-10 17:18:53176 // Initialized in SetupMetricsAndFieldTrials.
177 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
178
[email protected]5e6efa52011-06-27 17:26:41179 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket);
180 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Random);
181 FRIEND_TEST(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
[email protected]f8abf722010-07-07 19:46:24182 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
183};
184
185
[email protected]1152b7e2009-09-14 03:26:03186// Perform platform-specific work that needs to be done after the main event
187// loop has ended.
[email protected]3b6aa8b62009-09-15 21:36:11188void DidEndMainMessageLoop();
[email protected]1152b7e2009-09-14 03:26:03189
190// Records the conditions that can prevent Breakpad from generating and
191// sending crash reports. The presence of a Breakpad handler (after
192// attempting to initialize crash reporting) and the presence of a debugger
193// are registered with the UMA metrics service.
194void RecordBreakpadStatusUMA(MetricsService* metrics);
195
[email protected]34f73fb2010-03-24 20:50:34196// Displays a warning message if some minimum level of OS support is not
197// present on the current platform.
198void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03199
[email protected]45d72762011-04-15 18:58:20200// Records the time from our process' startup to the present time in
201// the UMA histogram |metric_name|.
202void RecordBrowserStartupTime();
203
[email protected]1152b7e2009-09-14 03:26:03204#endif // CHROME_BROWSER_BROWSER_MAIN_H_