blob: bd8f03ef5af88e861b43aca81f3d6a1914e2e76a [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]9a47c432013-04-19 20:33:5513#include "chrome/browser/chrome_process_singleton.h"
[email protected]c1702d712011-09-08 19:41:4314#include "chrome/browser/first_run/first_run.h"
[email protected]66013922011-09-13 18:53:4215#include "chrome/browser/process_singleton.h"
[email protected]61b53f972012-02-10 20:39:2316#include "chrome/browser/task_profiler/auto_tracking.h"
[email protected]fe7c4872012-05-10 20:06:0317#include "chrome/browser/ui/startup/startup_browser_creator.h"
[email protected]b48c9182011-10-26 18:03:3018#include "content/public/browser/browser_main_parts.h"
[email protected]af7ba1e2013-04-12 17:09:4519#include "content/public/browser/render_view_host.h"
[email protected]f8abf722010-07-07 19:46:2420
[email protected]2f2f72b2013-03-08 22:37:3121class ActiveTabTracker;
[email protected]c1702d712011-09-08 19:41:4322class BrowserProcessImpl;
[email protected]50462bf02011-11-21 19:13:3123class ChromeBrowserMainExtraParts;
[email protected]edafd4c2011-05-10 17:18:5324class FieldTrialSynchronizer;
[email protected]1152b7e2009-09-14 03:26:0325class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5326class PrefService;
[email protected]c1702d712011-09-08 19:41:4327class Profile;
[email protected]fe7c4872012-05-10 20:06:0328class StartupBrowserCreator;
[email protected]08f1c5e2011-12-01 01:54:3429class StartupTimeBomb;
[email protected]f967b722011-09-07 00:58:0430class ShutdownWatcherHelper;
[email protected]44327692013-02-26 21:21:2231class ThreeDAPIObserver;
[email protected]c1702d712011-09-08 19:41:4332class TranslateManager;
[email protected]5f988b92011-05-18 07:14:0833
[email protected]cbce47242011-08-12 21:40:5934namespace chrome_browser {
35// For use by ShowMissingLocaleMessageBox.
36extern const char kMissingLocaleDataTitle[];
37extern const char kMissingLocaleDataMessage[];
38}
39
[email protected]10fe40c2011-11-05 03:27:4640namespace chrome_browser_metrics {
41class TrackingSynchronizer;
42}
43
[email protected]4573fbd2011-10-31 20:25:1844namespace content {
45struct MainFunctionParams;
46}
47
[email protected]0c1c4752012-08-09 20:30:2448namespace performance_monitor {
49class StartupTimer;
50}
51
[email protected]f967b722011-09-07 00:58:0452class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2453 public:
[email protected]f967b722011-09-07 00:58:0454 virtual ~ChromeBrowserMainParts();
[email protected]f8abf722010-07-07 19:46:2455
[email protected]50462bf02011-11-21 19:13:3156 // Add additional ChromeBrowserMainExtraParts.
57 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4558
[email protected]f8abf722010-07-07 19:46:2459 protected:
[email protected]4573fbd2011-10-31 20:25:1860 explicit ChromeBrowserMainParts(
61 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2462
[email protected]50462bf02011-11-21 19:13:3163 // content::BrowserMainParts overrides.
[email protected]97ef83f2011-12-19 19:26:3664 // These are called in-order by content::BrowserMainLoop.
65 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
66 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
[email protected]c7480942011-11-08 19:18:2767 virtual void PreEarlyInitialization() OVERRIDE;
68 virtual void PostEarlyInitialization() OVERRIDE;
[email protected]f967b722011-09-07 00:58:0469 virtual void ToolkitInitialized() OVERRIDE;
[email protected]c7480942011-11-08 19:18:2770 virtual void PreMainMessageLoopStart() OVERRIDE;
71 virtual void PostMainMessageLoopStart() OVERRIDE;
[email protected]69479b922012-02-02 09:56:2072 virtual int PreCreateThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3073 virtual void PreMainMessageLoopRun() OVERRIDE;
74 virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
[email protected]c7480942011-11-08 19:18:2775 virtual void PostMainMessageLoopRun() OVERRIDE;
[email protected]2e5b60a22011-11-28 15:56:4176 virtual void PostDestroyThreads() OVERRIDE;
[email protected]b48c9182011-10-26 18:03:3077
[email protected]97ef83f2011-12-19 19:26:3678 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
[email protected]278a34d2012-06-07 00:34:5879 // in order from PreMainMessageLoopRun(). See implementation for details.
[email protected]97ef83f2011-12-19 19:26:3680 virtual void PreProfileInit();
81 virtual void PostProfileInit();
82 virtual void PreBrowserStart();
83 virtual void PostBrowserStart();
84
[email protected]81054f812012-08-30 00:47:0985#if !defined(OS_ANDROID)
[email protected]278a34d2012-06-07 00:34:5886 // Runs the PageCycler; called if the switch kVisitURLs is present.
87 virtual void RunPageCycler();
[email protected]81054f812012-08-30 00:47:0988#endif
[email protected]278a34d2012-06-07 00:34:5889
[email protected]b98def82012-06-28 23:42:4590 // Override this in subclasses to initialize platform specific field trials.
91 virtual void SetupPlatformFieldTrials();
92
[email protected]b48c9182011-10-26 18:03:3093 // Displays a warning message that we can't find any locale data files.
94 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2495
[email protected]50462bf02011-11-21 19:13:3196 const content::MainFunctionParams& parameters() const {
97 return parameters_;
98 }
99 const CommandLine& parsed_command_line() const {
100 return parsed_command_line_;
101 }
102
103 Profile* profile() { return profile_; }
104
[email protected]a5e8c6d2012-04-09 20:22:01105 const PrefService* local_state() const { return local_state_; }
106
[email protected]1fec64352010-07-27 13:55:21107 private:
[email protected]069cd9952011-10-01 16:34:45108 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
109
[email protected]50462bf02011-11-21 19:13:31110 // Constructs metrics service and does related initialization, including
111 // creation of field trials. Call only after labs have been converted to
112 // switches.
[email protected]5281db1d2012-01-11 22:51:54113 void SetupMetricsAndFieldTrials();
[email protected]edafd4c2011-05-10 17:18:53114
[email protected]5281db1d2012-01-11 22:51:54115 // Starts recording of metrics. This can only be called after we have a file
116 // thread.
117 void StartMetricsRecording();
118
[email protected]5cbeeef72012-02-08 02:05:18119 // Returns true if the user opted in to sending metric reports.
120 bool IsMetricsReportingEnabled();
121
[email protected]b48c9182011-10-26 18:03:30122 // Methods for Main Message Loop -------------------------------------------
123
[email protected]2e5b60a22011-11-28 15:56:41124 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30125 int PreMainMessageLoopRunImpl();
126
[email protected]f8abf722010-07-07 19:46:24127 // Members initialized on construction ---------------------------------------
128
[email protected]4573fbd2011-10-31 20:25:18129 const content::MainFunctionParams& parameters_;
[email protected]b48c9182011-10-26 18:03:30130 const CommandLine& parsed_command_line_;
131 int result_code_;
132
[email protected]08f1c5e2011-12-01 01:54:34133 // Create StartupTimeBomb object for watching jank during startup.
134 scoped_ptr<StartupTimeBomb> startup_watcher_;
135
[email protected]f967b722011-09-07 00:58:04136 // Create ShutdownWatcherHelper object for watching jank during shutdown.
137 // Please keep |shutdown_watcher| as the first object constructed, and hence
138 // it is destroyed last.
139 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24140
[email protected]0c1c4752012-08-09 20:30:24141 // A timer to hold data regarding startup and session restore times for
142 // PerformanceMonitor so that we don't have to start the entire
143 // PerformanceMonitor at browser startup.
144 scoped_ptr<performance_monitor::StartupTimer> startup_timer_;
145
[email protected]f8abf722010-07-07 19:46:24146 // Creating this object starts tracking the creation and deletion of Task
147 // instance. This MUST be done before main_message_loop, so that it is
148 // destroyed after the main_message_loop.
[email protected]61b53f972012-02-10 20:39:23149 task_profiler::AutoTracking tracking_objects_;
[email protected]f8abf722010-07-07 19:46:24150
[email protected]edafd4c2011-05-10 17:18:53151 // Statistical testing infrastructure for the entire browser. NULL until
152 // SetupMetricsAndFieldTrials is called.
153 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24154
[email protected]ae9e12a2012-07-31 17:48:12155 ChromeBrowserFieldTrials browser_field_trials_;
156
[email protected]af7ba1e2013-04-12 17:09:45157 content::RenderViewHost::CreatedCallback rvh_callback_;
158
[email protected]50462bf02011-11-21 19:13:31159 // Vector of additional ChromeBrowserMainExtraParts.
160 // Parts are deleted in the inverse order they are added.
161 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
162
[email protected]0f247aea82011-09-03 03:05:51163 // Members initialized after / released before main_message_loop_ ------------
164
[email protected]c1702d712011-09-08 19:41:43165 scoped_ptr<BrowserProcessImpl> browser_process_;
[email protected]10fe40c2011-11-05 03:27:46166 scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
167 tracking_synchronizer_;
[email protected]81054f812012-08-30 00:47:09168#if !defined(OS_ANDROID)
169 // Browser creation happens on the Java side in Android.
170 scoped_ptr<StartupBrowserCreator> browser_creator_;
171
172 // Android doesn't support multiple browser processes, so it doesn't implement
173 // ProcessSingleton.
[email protected]9a47c432013-04-19 20:33:55174 scoped_ptr<ChromeProcessSingleton> process_singleton_;
[email protected]81054f812012-08-30 00:47:09175#endif
[email protected]baacb232012-01-28 02:30:18176 scoped_ptr<first_run::MasterPrefs> master_prefs_;
[email protected]c1702d712011-09-08 19:41:43177 bool record_search_engine_;
178 TranslateManager* translate_manager_;
179 Profile* profile_;
180 bool run_message_loop_;
[email protected]66013922011-09-13 18:53:42181 ProcessSingleton::NotifyResult notify_result_;
[email protected]44327692013-02-26 21:21:22182 scoped_ptr<ThreeDAPIObserver> three_d_observer_;
[email protected]0f247aea82011-09-03 03:05:51183
[email protected]edafd4c2011-05-10 17:18:53184 // Initialized in SetupMetricsAndFieldTrials.
185 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
186
[email protected]2e5b60a22011-11-28 15:56:41187 // Members initialized in PreMainMessageLoopRun, needed in
188 // PreMainMessageLoopRunThreadsCreated.
[email protected]3f002a32013-01-02 17:52:38189 bool do_first_run_tasks_;
[email protected]2e5b60a22011-11-28 15:56:41190 PrefService* local_state_;
[email protected]650b2d52013-02-10 03:41:45191 base::FilePath user_data_dir_;
[email protected]2e5b60a22011-11-28 15:56:41192
[email protected]2f2f72b2013-03-08 22:37:31193#if !defined(OS_ANDROID)
194 scoped_ptr<ActiveTabTracker> active_tab_tracker_;
195#endif
196
[email protected]2e5b60a22011-11-28 15:56:41197 // Members needed across shutdown methods.
198 bool restart_last_session_;
199
[email protected]1948a4782012-04-30 13:45:44200 // Tests can set this to true to disable restricting cookie access in the
201 // network stack, as this can only be done once.
202 static bool disable_enforcing_cookie_policies_for_tests_;
203
[email protected]f967b722011-09-07 00:58:04204 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24205};
206
[email protected]1152b7e2009-09-14 03:26:03207// Records the conditions that can prevent Breakpad from generating and
208// sending crash reports. The presence of a Breakpad handler (after
209// attempting to initialize crash reporting) and the presence of a debugger
210// are registered with the UMA metrics service.
211void RecordBreakpadStatusUMA(MetricsService* metrics);
212
[email protected]34f73fb2010-03-24 20:50:34213// Displays a warning message if some minimum level of OS support is not
214// present on the current platform.
215void WarnAboutMinimumSystemRequirements();
[email protected]1152b7e2009-09-14 03:26:03216
[email protected]45d72762011-04-15 18:58:20217// Records the time from our process' startup to the present time in
[email protected]843bc462012-06-19 17:43:31218// the Startup.BrowserMessageLoopStartTime UMA histogram.
[email protected]45d72762011-04-15 18:58:20219void RecordBrowserStartupTime();
220
[email protected]28f576f2011-08-26 20:46:55221// Records a time value to an UMA histogram in the context of the
222// PreReadExperiment field-trial. This also reports to the appropriate
223// sub-histogram (_PreRead(Enabled|Disabled)).
224void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
225
[email protected]e6b5bc22011-09-08 22:01:56226#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_