blob: c7e892585232fe7b5e4d587c66f3505468cff234 [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)
51class BrowserMainParts {
52 public:
53 // This static method is to be implemented by each platform and should
54 // instantiate the appropriate subclass.
55 static BrowserMainParts* CreateBrowserMainParts(
56 const MainFunctionParams& parameters);
57
[email protected]1fec64352010-07-27 13:55:2158 virtual ~BrowserMainParts();
59
[email protected]f8abf722010-07-07 19:46:2460 // Parts to be called by |BrowserMain()|.
61 void EarlyInitialization();
[email protected]1fec64352010-07-27 13:55:2162 void MainMessageLoopStart();
[email protected]f8abf722010-07-07 19:46:2463
64 protected:
65 explicit BrowserMainParts(const MainFunctionParams& parameters);
66
[email protected]f8abf722010-07-07 19:46:2467 // Accessors for data members (below) ----------------------------------------
68 const MainFunctionParams& parameters() const {
69 return parameters_;
70 }
71 const CommandLine& parsed_command_line() const {
72 return parsed_command_line_;
73 }
[email protected]1fec64352010-07-27 13:55:2174 MessageLoop& main_message_loop() const {
75 return *main_message_loop_;
76 }
[email protected]f8abf722010-07-07 19:46:2477
[email protected]c1275ae2010-07-12 17:40:4978 // Methods to be overridden to provide platform-specific code; these
79 // correspond to the "parts" above.
80 virtual void PreEarlyInitialization() {}
81 virtual void PostEarlyInitialization() {}
[email protected]1fec64352010-07-27 13:55:2182 virtual void PreMainMessageLoopStart() {}
83 virtual void PostMainMessageLoopStart() {}
[email protected]c1275ae2010-07-12 17:40:4984
[email protected]1fec64352010-07-27 13:55:2185 private:
[email protected]f8abf722010-07-07 19:46:2486 // Methods for |EarlyInitialization()| ---------------------------------------
87
88 // A/B test for the maximum number of persistent connections per host.
89 void ConnectionFieldTrial();
90
91 // A/B test for determining a value for unused socket timeout.
92 void SocketTimeoutFieldTrial();
93
94 // A/B test for spdy when --use-spdy not set.
95 void SpdyFieldTrial();
96
97 // Used to initialize NSPR where appropriate.
98 void InitializeSSL();
99
[email protected]1fec64352010-07-27 13:55:21100 // Methods for |MainMessageLoopStart()| --------------------------------------
101
102 void InitializeMainThread();
103
[email protected]f8abf722010-07-07 19:46:24104 // Members initialized on construction ---------------------------------------
105
106 const MainFunctionParams& parameters_;
107 const CommandLine& parsed_command_line_;
108
109#if defined(TRACK_ALL_TASK_OBJECTS)
110 // Creating this object starts tracking the creation and deletion of Task
111 // instance. This MUST be done before main_message_loop, so that it is
112 // destroyed after the main_message_loop.
113 tracked_objects::AutoTracking tracking_objects_;
114#endif
115
116 // Statistical testing infrastructure for the entire browser.
117 FieldTrialList field_trial_;
118
[email protected]1fec64352010-07-27 13:55:21119 // Members initialized in |MainMessageLoopStart()| ---------------------------
120 scoped_ptr<MessageLoop> main_message_loop_;
121 scoped_ptr<SystemMonitor> system_monitor_;
122 scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
123 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
124 scoped_ptr<ChromeThread> main_thread_;
125
[email protected]f8abf722010-07-07 19:46:24126 DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
127};
128
129
[email protected]1152b7e2009-09-14 03:26:03130// Perform platform-specific work that needs to be done after the main event
131// loop has ended.
[email protected]3b6aa8b62009-09-15 21:36:11132void DidEndMainMessageLoop();
[email protected]1152b7e2009-09-14 03:26:03133
134// Records the conditions that can prevent Breakpad from generating and
135// sending crash reports. The presence of a Breakpad handler (after
136// attempting to initialize crash reporting) and the presence of a debugger
137// are registered with the UMA metrics service.
138void RecordBreakpadStatusUMA(MetricsService* metrics);
139
[email protected]34f73fb2010-03-24 20:50:34140// Displays a warning message if some minimum level of OS support is not
141// present on the current platform.
142void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03143
144#endif // CHROME_BROWSER_BROWSER_MAIN_H_