blob: 0648e5253091456f7dde2a98ddf675c620f339b8 [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"
10#include "base/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]1fec64352010-07-27 13:55:2114class ChromeThread;
[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:2120class SystemMonitor;
21
22namespace net {
23class NetworkChangeNotifier;
24}
[email protected]1152b7e2009-09-14 03:26:0325
[email protected]f8abf722010-07-07 19:46:2426// BrowserMainParts:
27// This class contains different "stages" to be executed in |BrowserMain()|,
28// mostly initialization. This is made into a class rather than just functions
29// so each stage can create and maintain state. Each part is represented by a
30// single method (e.g., "EarlyInitialization()"), which does the following:
31// - calls a method (e.g., "PreEarlyInitialization()") which individual
32// platforms can override to provide platform-specific code which is to be
33// executed before the common code;
34// - calls various methods for things common to all platforms (for that given
35// stage); and
36// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
37// code to be called after the common code.
38// As indicated above, platforms should override the default "Pre...()" and
39// "Post...()" methods when necessary; they need not call the superclass's
40// implementation (which is empty).
41//
42// Parts:
43// - EarlyInitialization: things which should be done as soon as possible on
44// program start (such as setting up signal handlers) and things to be done
45// at some generic time before the start of the main message loop.
[email protected]1fec64352010-07-27 13:55:2146// - MainMessageLoopStart: things beginning with the start of the main message
47// loop and ending with initialization of the main thread; platform-specific
48// things which should be done immediately before the start of the main
49// message loop should go in |PreMainMessageLoopStart()|.
[email protected]f8abf722010-07-07 19:46:2450// - (more to come)
[email protected]d7dbe28c2010-07-29 04:33:4751//
52// How to add stuff (to existing parts):
53// - Figure out when your new code should be executed. What must happen
54// before/after your code is executed? Are there performance reasons for
55// running your code at a particular time? Document these things!
56// - Split out any platform-specific bits. Please avoid #ifdefs it at all
57// possible. You have two choices for platform-specific code: (1) Execute it
58// from one of the platform-specific |Pre/Post...()| methods; do this if the
59// code is unique to a platform type. Or (2) execute it from one of the
60// "parts" (e.g., |EarlyInitialization()|) and provide platform-specific
61// implementations of your code (in a virtual method); do this if you need to
62// provide different implementations across most/all platforms.
63// - Unless your new code is just one or two lines, put it into a separate
64// method with a well-defined purpose. (Likewise, if you're adding to an
65// existing chunk which makes it longer than one or two lines, please move
66// the code out into a separate method.)
[email protected]f8abf722010-07-07 19:46:2467class BrowserMainParts {
68 public:
69 // This static method is to be implemented by each platform and should
70 // instantiate the appropriate subclass.
71 static BrowserMainParts* CreateBrowserMainParts(
72 const MainFunctionParams& parameters);
73
[email protected]1fec64352010-07-27 13:55:2174 virtual ~BrowserMainParts();
75
[email protected]f8abf722010-07-07 19:46:2476 // Parts to be called by |BrowserMain()|.
77 void EarlyInitialization();
[email protected]1fec64352010-07-27 13:55:2178 void MainMessageLoopStart();
[email protected]f8abf722010-07-07 19:46:2479
80 protected:
81 explicit BrowserMainParts(const MainFunctionParams& parameters);
82
[email protected]f8abf722010-07-07 19:46:2483 // Accessors for data members (below) ----------------------------------------
84 const MainFunctionParams& parameters() const {
85 return parameters_;
86 }
87 const CommandLine& parsed_command_line() const {
88 return parsed_command_line_;
89 }
[email protected]1fec64352010-07-27 13:55:2190 MessageLoop& main_message_loop() const {
91 return *main_message_loop_;
92 }
[email protected]f8abf722010-07-07 19:46:2493
[email protected]c1275ae2010-07-12 17:40:4994 // Methods to be overridden to provide platform-specific code; these
95 // correspond to the "parts" above.
96 virtual void PreEarlyInitialization() {}
97 virtual void PostEarlyInitialization() {}
[email protected]1fec64352010-07-27 13:55:2198 virtual void PreMainMessageLoopStart() {}
99 virtual void PostMainMessageLoopStart() {}
[email protected]c1275ae2010-07-12 17:40:49100
[email protected]1fec64352010-07-27 13:55:21101 private:
[email protected]f8abf722010-07-07 19:46:24102 // Methods for |EarlyInitialization()| ---------------------------------------
103
104 // A/B test for the maximum number of persistent connections per host.
105 void ConnectionFieldTrial();
106
107 // A/B test for determining a value for unused socket timeout.
108 void SocketTimeoutFieldTrial();
109
[email protected]78a258a2010-08-02 16:34:26110 // A/B test for the maximum number of connections per proxy server.
111 void ProxyConnectionsFieldTrial();
112
[email protected]f8abf722010-07-07 19:46:24113 // A/B test for spdy when --use-spdy not set.
114 void SpdyFieldTrial();
115
[email protected]8a3125a712010-08-09 18:58:51116 // A/B test for prefetching with --(enable|disable)-prefetch not set.
117 void PrefetchFieldTrial();
118
[email protected]06d94042010-08-25 01:45:22119 // A/B test for automatically establishing a backup TCP connection when a
120 // specified timeout value is reached.
121 void ConnectBackupJobsFieldTrial();
122
[email protected]f8abf722010-07-07 19:46:24123 // Used to initialize NSPR where appropriate.
[email protected]d7dbe28c2010-07-29 04:33:47124 virtual void InitializeSSL() = 0;
[email protected]f8abf722010-07-07 19:46:24125
[email protected]1fec64352010-07-27 13:55:21126 // Methods for |MainMessageLoopStart()| --------------------------------------
127
128 void InitializeMainThread();
129
[email protected]f8abf722010-07-07 19:46:24130 // Members initialized on construction ---------------------------------------
131
132 const MainFunctionParams& parameters_;
133 const CommandLine& parsed_command_line_;
134
135#if defined(TRACK_ALL_TASK_OBJECTS)
136 // Creating this object starts tracking the creation and deletion of Task
137 // instance. This MUST be done before main_message_loop, so that it is
138 // destroyed after the main_message_loop.
139 tracked_objects::AutoTracking tracking_objects_;
140#endif
141
142 // Statistical testing infrastructure for the entire browser.
143 FieldTrialList field_trial_;
144
[email protected]1fec64352010-07-27 13:55:21145 // Members initialized in |MainMessageLoopStart()| ---------------------------
146 scoped_ptr<MessageLoop> main_message_loop_;
147 scoped_ptr<SystemMonitor> system_monitor_;
148 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
149 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
150 scoped_ptr<ChromeThread> main_thread_;
151
[email protected]f8abf722010-07-07 19:46:24152 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
153};
154
155
[email protected]1152b7e2009-09-14 03:26:03156// Perform platform-specific work that needs to be done after the main event
157// loop has ended.
[email protected]3b6aa8b62009-09-15 21:36:11158void DidEndMainMessageLoop();
[email protected]1152b7e2009-09-14 03:26:03159
160// Records the conditions that can prevent Breakpad from generating and
161// sending crash reports. The presence of a Breakpad handler (after
162// attempting to initialize crash reporting) and the presence of a debugger
163// are registered with the UMA metrics service.
164void RecordBreakpadStatusUMA(MetricsService* metrics);
165
[email protected]34f73fb2010-03-24 20:50:34166// Displays a warning message if some minimum level of OS support is not
167// present on the current platform.
168void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03169
170#endif // CHROME_BROWSER_BROWSER_MAIN_H_