blob: cb663621eddcc1801b7deb24695adf4adae089bf [file] [log] [blame]
[email protected]d15b7ca2012-01-04 01:42:581// Copyright (c) 2012 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
[email protected]e6b5bc22011-09-08 22:01:565#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
6#define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
[email protected]1152b7e2009-09-14 03:26:037
[email protected]f8abf722010-07-07 19:46:248#include "base/basictypes.h"
[email protected]b48c9182011-10-26 18:03:309#include "base/memory/scoped_ptr.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/field_trial.h"
[email protected]f8abf722010-07-07 19:46:2411#include "base/tracked_objects.h"
[email protected]ae9e12a2012-07-31 17:48:1212#include "chrome/browser/chrome_browser_field_trials.h"
[email protected]c1702d712011-09-08 19:41:4313#include "chrome/browser/first_run/first_run.h"
[email protected]66013922011-09-13 18:53:4214#include "chrome/browser/process_singleton.h"
[email protected]61b53f972012-02-10 20:39:2315#include "chrome/browser/task_profiler/auto_tracking.h"
[email protected]fe7c4872012-05-10 20:06:0316#include "chrome/browser/ui/startup/startup_browser_creator.h"
[email protected]b48c9182011-10-26 18:03:3017#include "content/public/browser/browser_main_parts.h"
[email protected]f8abf722010-07-07 19:46:2418
[email protected]2f2f72b2013-03-08 22:37:3119class ActiveTabTracker;
[email protected]c1702d712011-09-08 19:41:4320class BrowserProcessImpl;
[email protected]50462bf02011-11-21 19:13:3121class ChromeBrowserMainExtraParts;
[email protected]edafd4c2011-05-10 17:18:5322class FieldTrialSynchronizer;
[email protected]1152b7e2009-09-14 03:26:0323class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5324class PrefService;
[email protected]c1702d712011-09-08 19:41:4325class Profile;
[email protected]fe7c4872012-05-10 20:06:0326class StartupBrowserCreator;
[email protected]08f1c5e2011-12-01 01:54:3427class StartupTimeBomb;
[email protected]f967b722011-09-07 00:58:0428class ShutdownWatcherHelper;
[email protected]44327692013-02-26 21:21:2229class ThreeDAPIObserver;
[email protected]c1702d712011-09-08 19:41:4330class TranslateManager;
[email protected]5f988b92011-05-18 07:14:0831
[email protected]cbce47242011-08-12 21:40:5932namespace chrome_browser {
33// For use by ShowMissingLocaleMessageBox.
34extern const char kMissingLocaleDataTitle[];
35extern const char kMissingLocaleDataMessage[];
36}
37
[email protected]10fe40c2011-11-05 03:27:4638namespace chrome_browser_metrics {
39class TrackingSynchronizer;
40}
41
[email protected]4573fbd2011-10-31 20:25:1842namespace content {
43struct MainFunctionParams;
44}
45
[email protected]0c1c4752012-08-09 20:30:2446namespace performance_monitor {
47class StartupTimer;
48}
49
[email protected]f967b722011-09-07 00:58:0450class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2451 public:
[email protected]f967b722011-09-07 00:58:0452 virtual ~ChromeBrowserMainParts();
[email protected]f8abf722010-07-07 19:46:2453
[email protected]50462bf02011-11-21 19:13:3154 // Add additional ChromeBrowserMainExtraParts.
55 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4556
[email protected]f8abf722010-07-07 19:46:2457 protected:
[email protected]4573fbd2011-10-31 20:25:1858 explicit ChromeBrowserMainParts(
59 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2460
[email protected]50462bf02011-11-21 19:13:3161 // content::BrowserMainParts overrides.
[email protected]97ef83f2011-12-19 19:26:3662 // These are called in-order by content::BrowserMainLoop.
63 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
64 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
[email protected]c7480942011-11-08 19:18:2765 virtual void PreEarlyInitialization() OVERRIDE;
66 virtual void PostEarlyInitialization() OVERRIDE;
[email protected]f967b722011-09-07 00:58:0467 virtual void ToolkitInitialized() OVERRIDE;
[email protected]c7480942011-11-08 19:18:2768 virtual void PreMainMessageLoopStart() OVERRIDE;
69 virtual void PostMainMessageLoopStart() OVERRIDE;
[email protected]69479b922012-02-02 09:56:2070 virtual int PreCreateThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3071 virtual void PreMainMessageLoopRun() OVERRIDE;
72 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
[email protected]c7480942011-11-08 19:18:2773 virtual void PostMainMessageLoopRun() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4174 virtual void PostDestroyThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3075
[email protected]97ef83f2011-12-19 19:26:3676 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
[email protected]278a34d2012-06-07 00:34:5877 // in order from PreMainMessageLoopRun(). See implementation for details.
[email protected]97ef83f2011-12-19 19:26:3678 virtual void PreProfileInit();
79 virtual void PostProfileInit();
80 virtual void PreBrowserStart();
81 virtual void PostBrowserStart();
82
[email protected]81054f812012-08-30 00:47:0983#if !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:5884 // Runs the PageCycler; called if the switch kVisitURLs is present.
85 virtual void RunPageCycler();
[email protected]81054f812012-08-30 00:47:0986#endif
[email protected]278a34d2012-06-07 00:34:5887
[email protected]b98def82012-06-28 23:42:4588 // Override this in subclasses to initialize platform specific field trials.
89 virtual void SetupPlatformFieldTrials();
90
[email protected]b48c9182011-10-26 18:03:3091 // Displays a warning message that we can't find any locale data files.
92 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2493
[email protected]50462bf02011-11-21 19:13:3194 const content::MainFunctionParams& parameters() const {
95 return parameters_;
96 }
97 const CommandLine& parsed_command_line() const {
98 return parsed_command_line_;
99 }
100
101 Profile* profile() { return profile_; }
102
[email protected]a5e8c6d2012-04-09 20:22:01103 const PrefService* local_state() const { return local_state_; }
104
[email protected]1fec64352010-07-27 13:55:21105 private:
[email protected]069cd9952011-10-01 16:34:45106 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
107
[email protected]50462bf02011-11-21 19:13:31108 // Constructs metrics service and does related initialization, including
109 // creation of field trials. Call only after labs have been converted to
110 // switches.
[email protected]5281db1d2012-01-11 22:51:54111 void SetupMetricsAndFieldTrials();
[email protected]edafd4c2011-05-10 17:18:53112
[email protected]5281db1d2012-01-11 22:51:54113 // Starts recording of metrics. This can only be called after we have a file
114 // thread.
115 void StartMetricsRecording();
116
[email protected]5cbeeef72012-02-08 02:05:18117 // Returns true if the user opted in to sending metric reports.
118 bool IsMetricsReportingEnabled();
119
[email protected]b48c9182011-10-26 18:03:30120 // Methods for Main Message Loop -------------------------------------------
121
[email protected]2e5b60a22011-11-28 15:56:41122 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30123 int PreMainMessageLoopRunImpl();
124
[email protected]f8abf722010-07-07 19:46:24125 // Members initialized on construction ---------------------------------------
126
[email protected]4573fbd2011-10-31 20:25:18127 const content::MainFunctionParams& parameters_;
[email protected]b48c9182011-10-26 18:03:30128 const CommandLine& parsed_command_line_;
129 int result_code_;
130
[email protected]08f1c5e2011-12-01 01:54:34131 // Create StartupTimeBomb object for watching jank during startup.
132 scoped_ptr<StartupTimeBomb> startup_watcher_;
133
[email protected]f967b722011-09-07 00:58:04134 // Create ShutdownWatcherHelper object for watching jank during shutdown.
135 // Please keep |shutdown_watcher| as the first object constructed, and hence
136 // it is destroyed last.
137 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24138
[email protected]0c1c4752012-08-09 20:30:24139 // A timer to hold data regarding startup and session restore times for
140 // PerformanceMonitor so that we don't have to start the entire
141 // PerformanceMonitor at browser startup.
142 scoped_ptr<performance_monitor::StartupTimer> startup_timer_;
143
[email protected]f8abf722010-07-07 19:46:24144 // Creating this object starts tracking the creation and deletion of Task
145 // instance. This MUST be done before main_message_loop, so that it is
146 // destroyed after the main_message_loop.
[email protected]61b53f972012-02-10 20:39:23147 task_profiler::AutoTracking tracking_objects_;
[email protected]f8abf722010-07-07 19:46:24148
[email protected]edafd4c2011-05-10 17:18:53149 // Statistical testing infrastructure for the entire browser. NULL until
150 // SetupMetricsAndFieldTrials is called.
151 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24152
[email protected]ae9e12a2012-07-31 17:48:12153 ChromeBrowserFieldTrials browser_field_trials_;
154
[email protected]50462bf02011-11-21 19:13:31155 // Vector of additional ChromeBrowserMainExtraParts.
156 // Parts are deleted in the inverse order they are added.
157 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
158
[email protected]0f247aea82011-09-03 03:05:51159 // Members initialized after / released before main_message_loop_ ------------
160
[email protected]c1702d712011-09-08 19:41:43161 scoped_ptr<BrowserProcessImpl> browser_process_;
[email protected]10fe40c2011-11-05 03:27:46162 scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
163 tracking_synchronizer_;
[email protected]81054f812012-08-30 00:47:09164#if !defined(OS_ANDROID)
165 // Browser creation happens on the Java side in Android.
166 scoped_ptr<StartupBrowserCreator> browser_creator_;
167
168 // Android doesn't support multiple browser processes, so it doesn't implement
169 // ProcessSingleton.
[email protected]c1702d712011-09-08 19:41:43170 scoped_ptr<ProcessSingleton> process_singleton_;
[email protected]81054f812012-08-30 00:47:09171#endif
[email protected]baacb232012-01-28 02:30:18172 scoped_ptr<first_run::MasterPrefs> master_prefs_;
[email protected]c1702d712011-09-08 19:41:43173 bool record_search_engine_;
174 TranslateManager* translate_manager_;
175 Profile* profile_;
176 bool run_message_loop_;
[email protected]66013922011-09-13 18:53:42177 ProcessSingleton::NotifyResult notify_result_;
[email protected]44327692013-02-26 21:21:22178 scoped_ptr<ThreeDAPIObserver> three_d_observer_;
[email protected]0f247aea82011-09-03 03:05:51179
[email protected]edafd4c2011-05-10 17:18:53180 // Initialized in SetupMetricsAndFieldTrials.
181 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
182
[email protected]2e5b60a22011-11-28 15:56:41183 // Members initialized in PreMainMessageLoopRun, needed in
184 // PreMainMessageLoopRunThreadsCreated.
[email protected]3f002a32013-01-02 17:52:38185 bool do_first_run_tasks_;
[email protected]2e5b60a22011-11-28 15:56:41186 PrefService* local_state_;
[email protected]650b2d52013-02-10 03:41:45187 base::FilePath user_data_dir_;
[email protected]2e5b60a22011-11-28 15:56:41188
[email protected]2f2f72b2013-03-08 22:37:31189#if !defined(OS_ANDROID)
190 scoped_ptr<ActiveTabTracker> active_tab_tracker_;
191#endif
192
[email protected]2e5b60a22011-11-28 15:56:41193 // Members needed across shutdown methods.
194 bool restart_last_session_;
195
[email protected]1948a4782012-04-30 13:45:44196 // Tests can set this to true to disable restricting cookie access in the
197 // network stack, as this can only be done once.
198 static bool disable_enforcing_cookie_policies_for_tests_;
199
[email protected]f967b722011-09-07 00:58:04200 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24201};
202
[email protected]1152b7e2009-09-14 03:26:03203// Records the conditions that can prevent Breakpad from generating and
204// sending crash reports. The presence of a Breakpad handler (after
205// attempting to initialize crash reporting) and the presence of a debugger
206// are registered with the UMA metrics service.
207void RecordBreakpadStatusUMA(MetricsService* metrics);
208
[email protected]34f73fb2010-03-24 20:50:34209// Displays a warning message if some minimum level of OS support is not
210// present on the current platform.
211void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03212
[email protected]45d72762011-04-15 18:58:20213// Records the time from our process' startup to the present time in
[email protected]843bc462012-06-19 17:43:31214// the Startup.BrowserMessageLoopStartTime UMA histogram.
[email protected]45d72762011-04-15 18:58:20215void RecordBrowserStartupTime();
216
[email protected]28f576f2011-08-26 20:46:55217// Records a time value to an UMA histogram in the context of the
218// PreReadExperiment field-trial. This also reports to the appropriate
219// sub-histogram (_PreRead(Enabled|Disabled)).
220void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
221
[email protected]e6b5bc22011-09-08 22:01:56222#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_