1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
6 #define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/field_trial.h"
11 #include "base/profiler/stack_sampling_profiler.h"
12 #include "base/tracked_objects.h"
13 #include "chrome/browser/chrome_browser_field_trials.h"
14 #include "chrome/browser/chrome_process_singleton.h"
15 #include "chrome/browser/first_run/first_run.h"
16 #include "chrome/browser/process_singleton.h"
17 #include "chrome/browser/ui/startup/startup_browser_creator.h"
18 #include "content/public/browser/browser_main_parts.h"
19 #include "content/public/common/main_function_params.h"
21 class BrowserProcessImpl
;
22 class ChromeBrowserMainExtraParts
;
23 class FieldTrialSynchronizer
;
26 class ProcessPowerCollector
;
28 class StartupBrowserCreator
;
29 class StartupTimeBomb
;
30 class ShutdownWatcherHelper
;
31 class ThreeDAPIObserver
;
33 namespace chrome_browser
{
34 // For use by ShowMissingLocaleMessageBox.
36 extern const char kMissingLocaleDataTitle
[];
40 extern const char kMissingLocaleDataMessage
[];
45 class TrackingSynchronizer
;
49 class WebUsbBrowserClient
;
53 class ChromeBrowserMainParts
: public content::BrowserMainParts
{
55 ~ChromeBrowserMainParts() override
;
57 // Add additional ChromeBrowserMainExtraParts.
58 virtual void AddParts(ChromeBrowserMainExtraParts
* parts
);
61 explicit ChromeBrowserMainParts(
62 const content::MainFunctionParams
& parameters
);
64 // content::BrowserMainParts overrides.
65 // These are called in-order by content::BrowserMainLoop.
66 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
67 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
68 void PreEarlyInitialization() override
;
69 void PostEarlyInitialization() override
;
70 void ToolkitInitialized() override
;
71 void PreMainMessageLoopStart() override
;
72 void PostMainMessageLoopStart() override
;
73 int PreCreateThreads() override
;
74 void PreMainMessageLoopRun() override
;
75 bool MainMessageLoopRun(int* result_code
) override
;
76 void PostMainMessageLoopRun() override
;
77 void PostDestroyThreads() override
;
79 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
80 // in order from PreMainMessageLoopRun(). See implementation for details.
81 virtual void PreProfileInit();
82 virtual void PostProfileInit();
83 virtual void PreBrowserStart();
84 virtual void PostBrowserStart();
86 // Displays a warning message that we can't find any locale data files.
87 virtual void ShowMissingLocaleMessageBox() = 0;
89 const content::MainFunctionParams
& parameters() const {
92 const base::CommandLine
& parsed_command_line() const {
93 return parsed_command_line_
;
95 const base::FilePath
& user_data_dir() const {
96 return user_data_dir_
;
99 Profile
* profile() { return profile_
; }
101 const PrefService
* local_state() const { return local_state_
; }
104 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
106 // Constructs metrics service and does related initialization, including
107 // creation of field trials. Call only after labs have been converted to
109 void SetupMetricsAndFieldTrials();
111 // Starts recording of metrics. This can only be called after we have a file
113 void StartMetricsRecording();
115 // Record time from process startup to present time in an UMA histogram.
116 void RecordBrowserStartupTime();
118 // Methods for Main Message Loop -------------------------------------------
120 int PreCreateThreadsImpl();
121 int PreMainMessageLoopRunImpl();
123 // Members initialized on construction ---------------------------------------
125 const content::MainFunctionParams parameters_
;
126 const base::CommandLine
& parsed_command_line_
;
129 // Create StartupTimeBomb object for watching jank during startup.
130 scoped_ptr
<StartupTimeBomb
> startup_watcher_
;
132 // 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_
;
137 // Statistical testing infrastructure for the entire browser. NULL until
138 // SetupMetricsAndFieldTrials is called.
139 scoped_ptr
<base::FieldTrialList
> field_trial_list_
;
141 ChromeBrowserFieldTrials browser_field_trials_
;
143 #if !defined(OS_ANDROID) && !defined(OS_IOS)
144 // A monitor for attributing power consumption to origins.
145 scoped_ptr
<ProcessPowerCollector
> process_power_collector_
;
147 scoped_ptr
<webusb::WebUsbBrowserClient
> webusb_browser_client_
;
148 scoped_ptr
<webusb::WebUsbDetector
> webusb_detector_
;
151 // Vector of additional ChromeBrowserMainExtraParts.
152 // Parts are deleted in the inverse order they are added.
153 std::vector
<ChromeBrowserMainExtraParts
*> chrome_extra_parts_
;
155 // A profiler that periodically samples stack traces. Used to sample startup
157 base::StackSamplingProfiler sampling_profiler_
;
159 // Members initialized after / released before main_message_loop_ ------------
161 scoped_ptr
<BrowserProcessImpl
> browser_process_
;
162 scoped_refptr
<metrics::TrackingSynchronizer
> tracking_synchronizer_
;
163 #if !defined(OS_ANDROID)
164 // Browser creation happens on the Java side in Android.
165 scoped_ptr
<StartupBrowserCreator
> browser_creator_
;
167 // Android doesn't support multiple browser processes, so it doesn't implement
169 scoped_ptr
<ChromeProcessSingleton
> process_singleton_
;
171 // Android's first run is done in Java instead of native.
172 scoped_ptr
<first_run::MasterPrefs
> master_prefs_
;
175 bool run_message_loop_
;
176 ProcessSingleton::NotifyResult notify_result_
;
177 scoped_ptr
<ThreeDAPIObserver
> three_d_observer_
;
179 // Initialized in SetupMetricsAndFieldTrials.
180 scoped_refptr
<FieldTrialSynchronizer
> field_trial_synchronizer_
;
182 // Members initialized in PreMainMessageLoopRun, needed in
183 // PreMainMessageLoopRunThreadsCreated.
184 PrefService
* local_state_
;
185 base::FilePath user_data_dir_
;
187 // Members needed across shutdown methods.
188 bool restart_last_session_
;
190 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts
);
193 #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_