blob: a867e20984c5d47e57804ccc7a5ad780f61792e4 [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]3b63f8f42011-03-28 01:54:1510#include "base/memory/scoped_ptr.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/field_trial.h"
[email protected]f8abf722010-07-07 19:46:2412#include "base/tracked_objects.h"
13
[email protected]092b04e2010-10-12 23:23:4414class BrowserThread;
[email protected]f8abf722010-07-07 19:46:2415class CommandLine;
[email protected]edafd4c2011-05-10 17:18:5316class FieldTrialSynchronizer;
[email protected]1fec64352010-07-27 13:55:2117class HighResolutionTimerManager;
[email protected]1152b7e2009-09-14 03:26:0318struct MainFunctionParams;
[email protected]1fec64352010-07-27 13:55:2119class MessageLoop;
[email protected]1152b7e2009-09-14 03:26:0320class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5321class PrefService;
[email protected]1fec64352010-07-27 13:55:2122
[email protected]69803a42011-05-18 07:04:0623namespace net {
24class NetworkChangeNotifier;
[email protected]4ae61df2011-01-19 15:29:4725}
26
[email protected]5f988b92011-05-18 07:14:0827namespace ui {
28class SystemMonitor;
29}
30
[email protected]f8abf722010-07-07 19:46:2431// BrowserMainParts:
32// This class contains different "stages" to be executed in |BrowserMain()|,
33// mostly initialization. This is made into a class rather than just functions
34// so each stage can create and maintain state. Each part is represented by a
35// single method (e.g., "EarlyInitialization()"), which does the following:
36// - calls a method (e.g., "PreEarlyInitialization()") which individual
37// platforms can override to provide platform-specific code which is to be
38// executed before the common code;
39// - calls various methods for things common to all platforms (for that given
40// stage); and
41// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
42// code to be called after the common code.
43// As indicated above, platforms should override the default "Pre...()" and
44// "Post...()" methods when necessary; they need not call the superclass's
45// implementation (which is empty).
46//
47// Parts:
48// - EarlyInitialization: things which should be done as soon as possible on
49// program start (such as setting up signal handlers) and things to be done
50// at some generic time before the start of the main message loop.
[email protected]1fec64352010-07-27 13:55:2151// - MainMessageLoopStart: things beginning with the start of the main message
52// loop and ending with initialization of the main thread; platform-specific
53// things which should be done immediately before the start of the main
54// message loop should go in |PreMainMessageLoopStart()|.
[email protected]f8abf722010-07-07 19:46:2455// - (more to come)
[email protected]d7dbe28c2010-07-29 04:33:4756//
57// How to add stuff (to existing parts):
58// - Figure out when your new code should be executed. What must happen
59// before/after your code is executed? Are there performance reasons for
60// running your code at a particular time? Document these things!
61// - Split out any platform-specific bits. Please avoid #ifdefs it at all
62// possible. You have two choices for platform-specific code: (1) Execute it
63// from one of the platform-specific |Pre/Post...()| methods; do this if the
64// code is unique to a platform type. Or (2) execute it from one of the
65// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
66// implementations of your code (in a virtual method); do this if you need to
67// provide different implementations across most/all platforms.
68// - Unless your new code is just one or two lines, put it into a separate
69// method with a well-defined purpose. (Likewise, if you're adding to an
70// existing chunk which makes it longer than one or two lines, please move
71// the code out into a separate method.)
[email protected]f8abf722010-07-07 19:46:2472class BrowserMainParts {
73 public:
74 // This static method is to be implemented by each platform and should
75 // instantiate the appropriate subclass.
76 static BrowserMainParts* CreateBrowserMainParts(
77 const MainFunctionParams& parameters);
78
[email protected]1fec64352010-07-27 13:55:2179 virtual ~BrowserMainParts();
80
[email protected]f8abf722010-07-07 19:46:2481 // Parts to be called by |BrowserMain()|.
82 void EarlyInitialization();
[email protected]1fec64352010-07-27 13:55:2183 void MainMessageLoopStart();
[email protected]f8abf722010-07-07 19:46:2484
[email protected]edafd4c2011-05-10 17:18:5385 // Constructs metrics service and does related initialization, including
86 // creation of field trials. Call only after labs have been converted to
87 // switches.
88 MetricsService* SetupMetricsAndFieldTrials(
89 const CommandLine& parsed_command_line,
90 PrefService* local_state);
[email protected]68adccab2011-01-26 21:18:1391
[email protected]f8abf722010-07-07 19:46:2492 protected:
93 explicit BrowserMainParts(const MainFunctionParams& parameters);
94
[email protected]f8abf722010-07-07 19:46:2495 // Accessors for data members (below) ----------------------------------------
96 const MainFunctionParams& parameters() const {
97 return parameters_;
98 }
99 const CommandLine& parsed_command_line() const {
100 return parsed_command_line_;
101 }
[email protected]1fec64352010-07-27 13:55:21102 MessageLoop& main_message_loop() const {
103 return *main_message_loop_;
104 }
[email protected]f8abf722010-07-07 19:46:24105
[email protected]c1275ae2010-07-12 17:40:49106 // Methods to be overridden to provide platform-specific code; these
107 // correspond to the "parts" above.
108 virtual void PreEarlyInitialization() {}
109 virtual void PostEarlyInitialization() {}
[email protected]1fec64352010-07-27 13:55:21110 virtual void PreMainMessageLoopStart() {}
111 virtual void PostMainMessageLoopStart() {}
[email protected]c1275ae2010-07-12 17:40:49112
[email protected]1fec64352010-07-27 13:55:21113 private:
[email protected]f8abf722010-07-07 19:46:24114 // Methods for |EarlyInitialization()| ---------------------------------------
115
116 // A/B test for the maximum number of persistent connections per host.
117 void ConnectionFieldTrial();
118
119 // A/B test for determining a value for unused socket timeout.
120 void SocketTimeoutFieldTrial();
121
[email protected]78a258a2010-08-02 16:34:26122 // A/B test for the maximum number of connections per proxy server.
123 void ProxyConnectionsFieldTrial();
124
[email protected]f8abf722010-07-07 19:46:24125 // A/B test for spdy when --use-spdy not set.
126 void SpdyFieldTrial();
127
[email protected]06d94042010-08-25 01:45:22128 // A/B test for automatically establishing a backup TCP connection when a
129 // specified timeout value is reached.
130 void ConnectBackupJobsFieldTrial();
131
[email protected]c63248d42011-02-18 17:54:39132 // A/B test for SSL False Start.
133 void SSLFalseStartFieldTrial();
134
[email protected]f8abf722010-07-07 19:46:24135 // Used to initialize NSPR where appropriate.
[email protected]d7dbe28c2010-07-29 04:33:47136 virtual void InitializeSSL() = 0;
[email protected]f8abf722010-07-07 19:46:24137
[email protected]1fec64352010-07-27 13:55:21138 // Methods for |MainMessageLoopStart()| --------------------------------------
139
140 void InitializeMainThread();
141
[email protected]edafd4c2011-05-10 17:18:53142 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
143
144 static MetricsService* InitializeMetrics(
145 const CommandLine& parsed_command_line,
146 const PrefService* local_state);
147
148 // Add an invocation of your field trial init function to this method.
149 void SetupFieldTrials(bool metrics_recording_enabled);
150
[email protected]f8abf722010-07-07 19:46:24151 // Members initialized on construction ---------------------------------------
152
153 const MainFunctionParams& parameters_;
154 const CommandLine& parsed_command_line_;
155
156#if defined(TRACK_ALL_TASK_OBJECTS)
157 // Creating this object starts tracking the creation and deletion of Task
158 // instance. This MUST be done before main_message_loop, so that it is
159 // destroyed after the main_message_loop.
160 tracked_objects::AutoTracking tracking_objects_;
161#endif
162
[email protected]edafd4c2011-05-10 17:18:53163 // Statistical testing infrastructure for the entire browser. NULL until
164 // SetupMetricsAndFieldTrials is called.
165 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24166
[email protected]1fec64352010-07-27 13:55:21167 // Members initialized in |MainMessageLoopStart()| ---------------------------
168 scoped_ptr<MessageLoop> main_message_loop_;
[email protected]5f988b92011-05-18 07:14:08169 scoped_ptr<ui::SystemMonitor> system_monitor_;
[email protected]1fec64352010-07-27 13:55:21170 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
171 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
[email protected]092b04e2010-10-12 23:23:44172 scoped_ptr<BrowserThread> main_thread_;
[email protected]1fec64352010-07-27 13:55:21173
[email protected]edafd4c2011-05-10 17:18:53174 // Initialized in SetupMetricsAndFieldTrials.
175 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
176
[email protected]f8abf722010-07-07 19:46:24177 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
178};
179
180
[email protected]1152b7e2009-09-14 03:26:03181// Perform platform-specific work that needs to be done after the main event
182// loop has ended.
[email protected]3b6aa8b62009-09-15 21:36:11183void DidEndMainMessageLoop();
[email protected]1152b7e2009-09-14 03:26:03184
185// Records the conditions that can prevent Breakpad from generating and
186// sending crash reports. The presence of a Breakpad handler (after
187// attempting to initialize crash reporting) and the presence of a debugger
188// are registered with the UMA metrics service.
189void RecordBreakpadStatusUMA(MetricsService* metrics);
190
[email protected]34f73fb2010-03-24 20:50:34191// Displays a warning message if some minimum level of OS support is not
192// present on the current platform.
193void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03194
[email protected]45d72762011-04-15 18:58:20195// Records the time from our process' startup to the present time in
196// the UMA histogram |metric_name|.
197void RecordBrowserStartupTime();
198
[email protected]1152b7e2009-09-14 03:26:03199#endif // CHROME_BROWSER_BROWSER_MAIN_H_