blob: 7fd714276fafa8e39a5e15b468d9d7886821aebe [file] [log] [blame]
[email protected]34f73fb2010-03-24 20:50:341// Copyright (c) 2010 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]835d7c82010-10-14 04:38:3810#include "base/metrics/field_trial.h"
[email protected]1fec64352010-07-27 13:55:2111#include "base/scoped_ptr.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]1fec64352010-07-27 13:55:2116class HighResolutionTimerManager;
[email protected]1152b7e2009-09-14 03:26:0317struct MainFunctionParams;
[email protected]1fec64352010-07-27 13:55:2118class MessageLoop;
[email protected]1152b7e2009-09-14 03:26:0319class MetricsService;
[email protected]1fec64352010-07-27 13:55:2120
21namespace net {
22class NetworkChangeNotifier;
23}
[email protected]1152b7e2009-09-14 03:26:0324
[email protected]4ae61df2011-01-19 15:29:4725namespace ui {
26class SystemMonitor;
27}
28
[email protected]f8abf722010-07-07 19:46:2429// BrowserMainParts:
30// This class contains different "stages" to be executed in |BrowserMain()|,
31// mostly initialization. This is made into a class rather than just functions
32// so each stage can create and maintain state. Each part is represented by a
33// single method (e.g., "EarlyInitialization()"), which does the following:
34// - calls a method (e.g., "PreEarlyInitialization()") which individual
35// platforms can override to provide platform-specific code which is to be
36// executed before the common code;
37// - calls various methods for things common to all platforms (for that given
38// stage); and
39// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
40// code to be called after the common code.
41// As indicated above, platforms should override the default "Pre...()" and
42// "Post...()" methods when necessary; they need not call the superclass's
43// implementation (which is empty).
44//
45// Parts:
46// - EarlyInitialization: things which should be done as soon as possible on
47// program start (such as setting up signal handlers) and things to be done
48// at some generic time before the start of the main message loop.
[email protected]1fec64352010-07-27 13:55:2149// - MainMessageLoopStart: things beginning with the start of the main message
50// loop and ending with initialization of the main thread; platform-specific
51// things which should be done immediately before the start of the main
52// message loop should go in |PreMainMessageLoopStart()|.
[email protected]f8abf722010-07-07 19:46:2453// - (more to come)
[email protected]d7dbe28c2010-07-29 04:33:4754//
55// How to add stuff (to existing parts):
56// - Figure out when your new code should be executed. What must happen
57// before/after your code is executed? Are there performance reasons for
58// running your code at a particular time? Document these things!
59// - Split out any platform-specific bits. Please avoid #ifdefs it at all
60// possible. You have two choices for platform-specific code: (1) Execute it
61// from one of the platform-specific |Pre/Post...()| methods; do this if the
62// code is unique to a platform type. Or (2) execute it from one of the
63// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
64// implementations of your code (in a virtual method); do this if you need to
65// provide different implementations across most/all platforms.
66// - Unless your new code is just one or two lines, put it into a separate
67// method with a well-defined purpose. (Likewise, if you're adding to an
68// existing chunk which makes it longer than one or two lines, please move
69// the code out into a separate method.)
[email protected]f8abf722010-07-07 19:46:2470class BrowserMainParts {
71 public:
72 // This static method is to be implemented by each platform and should
73 // instantiate the appropriate subclass.
74 static BrowserMainParts* CreateBrowserMainParts(
75 const MainFunctionParams& parameters);
76
[email protected]1fec64352010-07-27 13:55:2177 virtual ~BrowserMainParts();
78
[email protected]f8abf722010-07-07 19:46:2479 // Parts to be called by |BrowserMain()|.
80 void EarlyInitialization();
[email protected]1fec64352010-07-27 13:55:2181 void MainMessageLoopStart();
[email protected]f8abf722010-07-07 19:46:2482
83 protected:
84 explicit BrowserMainParts(const MainFunctionParams& parameters);
85
[email protected]f8abf722010-07-07 19:46:2486 // Accessors for data members (below) ----------------------------------------
87 const MainFunctionParams& parameters() const {
88 return parameters_;
89 }
90 const CommandLine& parsed_command_line() const {
91 return parsed_command_line_;
92 }
[email protected]1fec64352010-07-27 13:55:2193 MessageLoop& main_message_loop() const {
94 return *main_message_loop_;
95 }
[email protected]f8abf722010-07-07 19:46:2496
[email protected]c1275ae2010-07-12 17:40:4997 // Methods to be overridden to provide platform-specific code; these
98 // correspond to the "parts" above.
99 virtual void PreEarlyInitialization() {}
100 virtual void PostEarlyInitialization() {}
[email protected]1fec64352010-07-27 13:55:21101 virtual void PreMainMessageLoopStart() {}
102 virtual void PostMainMessageLoopStart() {}
[email protected]c1275ae2010-07-12 17:40:49103
[email protected]1fec64352010-07-27 13:55:21104 private:
[email protected]f8abf722010-07-07 19:46:24105 // Methods for |EarlyInitialization()| ---------------------------------------
106
107 // A/B test for the maximum number of persistent connections per host.
108 void ConnectionFieldTrial();
109
110 // A/B test for determining a value for unused socket timeout.
111 void SocketTimeoutFieldTrial();
112
[email protected]78a258a2010-08-02 16:34:26113 // A/B test for the maximum number of connections per proxy server.
114 void ProxyConnectionsFieldTrial();
115
[email protected]f8abf722010-07-07 19:46:24116 // A/B test for spdy when --use-spdy not set.
117 void SpdyFieldTrial();
118
[email protected]8a3125a712010-08-09 18:58:51119 // A/B test for prefetching with --(enable|disable)-prefetch not set.
120 void PrefetchFieldTrial();
121
[email protected]06d94042010-08-25 01:45:22122 // A/B test for automatically establishing a backup TCP connection when a
123 // specified timeout value is reached.
124 void ConnectBackupJobsFieldTrial();
125
[email protected]f8abf722010-07-07 19:46:24126 // Used to initialize NSPR where appropriate.
[email protected]d7dbe28c2010-07-29 04:33:47127 virtual void InitializeSSL() = 0;
[email protected]f8abf722010-07-07 19:46:24128
[email protected]1fec64352010-07-27 13:55:21129 // Methods for |MainMessageLoopStart()| --------------------------------------
130
131 void InitializeMainThread();
132
[email protected]f8abf722010-07-07 19:46:24133 // Members initialized on construction ---------------------------------------
134
135 const MainFunctionParams& parameters_;
136 const CommandLine& parsed_command_line_;
137
138#if defined(TRACK_ALL_TASK_OBJECTS)
139 // Creating this object starts tracking the creation and deletion of Task
140 // instance. This MUST be done before main_message_loop, so that it is
141 // destroyed after the main_message_loop.
142 tracked_objects::AutoTracking tracking_objects_;
143#endif
144
145 // Statistical testing infrastructure for the entire browser.
[email protected]835d7c82010-10-14 04:38:38146 base::FieldTrialList field_trial_;
[email protected]f8abf722010-07-07 19:46:24147
[email protected]1fec64352010-07-27 13:55:21148 // Members initialized in |MainMessageLoopStart()| ---------------------------
149 scoped_ptr<MessageLoop> main_message_loop_;
[email protected]4ae61df2011-01-19 15:29:47150 scoped_ptr<ui::SystemMonitor> system_monitor_;
[email protected]1fec64352010-07-27 13:55:21151 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
152 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
[email protected]092b04e2010-10-12 23:23:44153 scoped_ptr<BrowserThread> main_thread_;
[email protected]1fec64352010-07-27 13:55:21154
[email protected]f8abf722010-07-07 19:46:24155 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
156};
157
158
[email protected]1152b7e2009-09-14 03:26:03159// Perform platform-specific work that needs to be done after the main event
160// loop has ended.
[email protected]3b6aa8b62009-09-15 21:36:11161void DidEndMainMessageLoop();
[email protected]1152b7e2009-09-14 03:26:03162
163// Records the conditions that can prevent Breakpad from generating and
164// sending crash reports. The presence of a Breakpad handler (after
165// attempting to initialize crash reporting) and the presence of a debugger
166// are registered with the UMA metrics service.
167void RecordBreakpadStatusUMA(MetricsService* metrics);
168
[email protected]34f73fb2010-03-24 20:50:34169// Displays a warning message if some minimum level of OS support is not
170// present on the current platform.
171void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03172
173#endif // CHROME_BROWSER_BROWSER_MAIN_H_