blob: aa9d6cc450e473c182a14fcaf3bdae9cb2386397 [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]57624ab2013-08-01 16:01:5119#include "content/public/common/main_function_params.h"
[email protected]f8abf722010-07-07 19:46:2420
[email protected]c1702d712011-09-08 19:41:4321class BrowserProcessImpl;
[email protected]50462bf02011-11-21 19:13:3122class ChromeBrowserMainExtraParts;
[email protected]edafd4c2011-05-10 17:18:5323class FieldTrialSynchronizer;
[email protected]1152b7e2009-09-14 03:26:0324class MetricsService;
[email protected]edafd4c2011-05-10 17:18:5325class PrefService;
dhnishi3cf1d2aa2014-08-26 22:25:0726class ProcessPowerCollector;
[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]5f988b92011-05-18 07:14:0832
[email protected]cbce47242011-08-12 21:40:5933namespace chrome_browser {
34// For use by ShowMissingLocaleMessageBox.
[email protected]49aa5a32014-02-03 10:00:4435#if defined(OS_WIN)
[email protected]cbce47242011-08-12 21:40:5936extern const char kMissingLocaleDataTitle[];
[email protected]49aa5a32014-02-03 10:00:4437#endif
38
[email protected]893124a22014-04-15 00:45:2839#if defined(OS_WIN)
[email protected]cbce47242011-08-12 21:40:5940extern const char kMissingLocaleDataMessage[];
[email protected]49aa5a32014-02-03 10:00:4441#endif
[email protected]cbce47242011-08-12 21:40:5942}
43
gunsch840bc412014-09-18 19:38:0644namespace metrics {
[email protected]10fe40c2011-11-05 03:27:4645class TrackingSynchronizer;
46}
47
[email protected]f967b722011-09-07 00:58:0448class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2449 public:
Daniel Chenga542fca2014-10-21 09:51:2950 ~ChromeBrowserMainParts() override;
[email protected]f8abf722010-07-07 19:46:2451
[email protected]50462bf02011-11-21 19:13:3152 // Add additional ChromeBrowserMainExtraParts.
53 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4554
[email protected]f8abf722010-07-07 19:46:2455 protected:
[email protected]4573fbd2011-10-31 20:25:1856 explicit ChromeBrowserMainParts(
57 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2458
[email protected]50462bf02011-11-21 19:13:3159 // content::BrowserMainParts overrides.
[email protected]97ef83f2011-12-19 19:26:3660 // These are called in-order by content::BrowserMainLoop.
61 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
62 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
Daniel Chenga542fca2014-10-21 09:51:2963 void PreEarlyInitialization() override;
64 void PostEarlyInitialization() override;
65 void ToolkitInitialized() override;
66 void PreMainMessageLoopStart() override;
67 void PostMainMessageLoopStart() override;
68 int PreCreateThreads() override;
69 void PreMainMessageLoopRun() override;
70 bool MainMessageLoopRun(int* result_code) override;
71 void PostMainMessageLoopRun() override;
72 void PostDestroyThreads() override;
[email protected]b48c9182011-10-26 18:03:3073
[email protected]97ef83f2011-12-19 19:26:3674 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
[email protected]278a34d2012-06-07 00:34:5875 // in order from PreMainMessageLoopRun(). See implementation for details.
[email protected]97ef83f2011-12-19 19:26:3676 virtual void PreProfileInit();
77 virtual void PostProfileInit();
78 virtual void PreBrowserStart();
79 virtual void PostBrowserStart();
80
[email protected]b48c9182011-10-26 18:03:3081 // Displays a warning message that we can't find any locale data files.
82 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2483
[email protected]50462bf02011-11-21 19:13:3184 const content::MainFunctionParams& parameters() const {
85 return parameters_;
86 }
[email protected]2f3b1cc2014-03-17 23:07:1587 const base::CommandLine& parsed_command_line() const {
[email protected]50462bf02011-11-21 19:13:3188 return parsed_command_line_;
89 }
mlermana312cec2015-01-28 21:13:3390 const base::FilePath& user_data_dir() const {
91 return user_data_dir_;
92 }
[email protected]50462bf02011-11-21 19:13:3193
94 Profile* profile() { return profile_; }
95
[email protected]a5e8c6d2012-04-09 20:22:0196 const PrefService* local_state() const { return local_state_; }
97
[email protected]1fec64352010-07-27 13:55:2198 private:
[email protected]069cd9952011-10-01 16:34:4599 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
100
[email protected]50462bf02011-11-21 19:13:31101 // Constructs metrics service and does related initialization, including
102 // creation of field trials. Call only after labs have been converted to
103 // switches.
[email protected]5281db1d2012-01-11 22:51:54104 void SetupMetricsAndFieldTrials();
[email protected]edafd4c2011-05-10 17:18:53105
[email protected]5281db1d2012-01-11 22:51:54106 // Starts recording of metrics. This can only be called after we have a file
107 // thread.
108 void StartMetricsRecording();
109
[email protected]e8b6ca02013-07-10 18:00:51110 // Record time from process startup to present time in an UMA histogram.
[email protected]69e90692013-07-31 02:13:29111 void RecordBrowserStartupTime();
[email protected]e8b6ca02013-07-10 18:00:51112
113 // Records a time value to an UMA histogram in the context of the
114 // PreReadExperiment field-trial. This also reports to the appropriate
115 // sub-histogram (_PreRead(Enabled|Disabled)).
116 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
117
[email protected]b48c9182011-10-26 18:03:30118 // Methods for Main Message Loop -------------------------------------------
119
[email protected]2e5b60a22011-11-28 15:56:41120 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30121 int PreMainMessageLoopRunImpl();
122
[email protected]f8abf722010-07-07 19:46:24123 // Members initialized on construction ---------------------------------------
124
[email protected]57624ab2013-08-01 16:01:51125 const content::MainFunctionParams parameters_;
[email protected]2f3b1cc2014-03-17 23:07:15126 const base::CommandLine& parsed_command_line_;
[email protected]b48c9182011-10-26 18:03:30127 int result_code_;
128
[email protected]08f1c5e2011-12-01 01:54:34129 // Create StartupTimeBomb object for watching jank during startup.
130 scoped_ptr<StartupTimeBomb> startup_watcher_;
131
[email protected]f967b722011-09-07 00:58:04132 // Create ShutdownWatcherHelper object for watching jank during shutdown.
133 // Please keep |shutdown_watcher| as the first object constructed, and hence
134 // it is destroyed last.
135 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24136
[email protected]f8abf722010-07-07 19:46:24137 // Creating this object starts tracking the creation and deletion of Task
138 // instance. This MUST be done before main_message_loop, so that it is
139 // destroyed after the main_message_loop.
[email protected]61b53f972012-02-10 20:39:23140 task_profiler::AutoTracking tracking_objects_;
[email protected]f8abf722010-07-07 19:46:24141
[email protected]edafd4c2011-05-10 17:18:53142 // Statistical testing infrastructure for the entire browser. NULL until
143 // SetupMetricsAndFieldTrials is called.
144 scoped_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24145
[email protected]ae9e12a2012-07-31 17:48:12146 ChromeBrowserFieldTrials browser_field_trials_;
147
dhnishi3cf1d2aa2014-08-26 22:25:07148#if !defined(OS_ANDROID) && !defined(OS_IOS)
149 // A monitor for attributing power consumption to origins.
150 scoped_ptr<ProcessPowerCollector> process_power_collector_;
151#endif
152
[email protected]50462bf02011-11-21 19:13:31153 // Vector of additional ChromeBrowserMainExtraParts.
154 // Parts are deleted in the inverse order they are added.
155 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
156
[email protected]0f247aea82011-09-03 03:05:51157 // Members initialized after / released before main_message_loop_ ------------
158
[email protected]c1702d712011-09-08 19:41:43159 scoped_ptr<BrowserProcessImpl> browser_process_;
gunsch840bc412014-09-18 19:38:06160 scoped_refptr<metrics::TrackingSynchronizer> tracking_synchronizer_;
[email protected]81054f812012-08-30 00:47:09161#if !defined(OS_ANDROID)
162 // Browser creation happens on the Java side in Android.
163 scoped_ptr<StartupBrowserCreator> browser_creator_;
164
165 // Android doesn't support multiple browser processes, so it doesn't implement
166 // ProcessSingleton.
[email protected]9a47c432013-04-19 20:33:55167 scoped_ptr<ChromeProcessSingleton> process_singleton_;
[email protected]d29f4e312013-08-07 05:28:31168
169 // Android's first run is done in Java instead of native.
[email protected]baacb232012-01-28 02:30:18170 scoped_ptr<first_run::MasterPrefs> master_prefs_;
[email protected]d29f4e312013-08-07 05:28:31171#endif
[email protected]c1702d712011-09-08 19:41:43172 Profile* profile_;
173 bool run_message_loop_;
[email protected]66013922011-09-13 18:53:42174 ProcessSingleton::NotifyResult notify_result_;
[email protected]44327692013-02-26 21:21:22175 scoped_ptr<ThreeDAPIObserver> three_d_observer_;
[email protected]0f247aea82011-09-03 03:05:51176
[email protected]edafd4c2011-05-10 17:18:53177 // Initialized in SetupMetricsAndFieldTrials.
178 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
179
[email protected]2e5b60a22011-11-28 15:56:41180 // Members initialized in PreMainMessageLoopRun, needed in
181 // PreMainMessageLoopRunThreadsCreated.
[email protected]2e5b60a22011-11-28 15:56:41182 PrefService* local_state_;
[email protected]650b2d52013-02-10 03:41:45183 base::FilePath user_data_dir_;
[email protected]2e5b60a22011-11-28 15:56:41184
185 // Members needed across shutdown methods.
186 bool restart_last_session_;
187
[email protected]1948a4782012-04-30 13:45:44188 // Tests can set this to true to disable restricting cookie access in the
189 // network stack, as this can only be done once.
190 static bool disable_enforcing_cookie_policies_for_tests_;
191
[email protected]f967b722011-09-07 00:58:04192 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24193};
194
[email protected]e6b5bc22011-09-08 22:01:56195#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_