Roll src/third_party/WebKit eb1578b:b559582 (svn 193425:193437)
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main.h
blob4ce3238ba7c6268b65b90e04a7c5dbc932009a2b
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;
24 class MetricsService;
25 class PrefService;
26 class ProcessPowerCollector;
27 class Profile;
28 class StartupBrowserCreator;
29 class StartupTimeBomb;
30 class ShutdownWatcherHelper;
31 class ThreeDAPIObserver;
33 namespace chrome_browser {
34 // For use by ShowMissingLocaleMessageBox.
35 #if defined(OS_WIN)
36 extern const char kMissingLocaleDataTitle[];
37 #endif
39 #if defined(OS_WIN)
40 extern const char kMissingLocaleDataMessage[];
41 #endif
44 namespace metrics {
45 class TrackingSynchronizer;
48 class ChromeBrowserMainParts : public content::BrowserMainParts {
49 public:
50 ~ChromeBrowserMainParts() override;
52 // Add additional ChromeBrowserMainExtraParts.
53 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
55 protected:
56 explicit ChromeBrowserMainParts(
57 const content::MainFunctionParams& parameters);
59 // content::BrowserMainParts overrides.
60 // 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.
63 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;
74 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
75 // in order from PreMainMessageLoopRun(). See implementation for details.
76 virtual void PreProfileInit();
77 virtual void PostProfileInit();
78 virtual void PreBrowserStart();
79 virtual void PostBrowserStart();
81 // Displays a warning message that we can't find any locale data files.
82 virtual void ShowMissingLocaleMessageBox() = 0;
84 const content::MainFunctionParams& parameters() const {
85 return parameters_;
87 const base::CommandLine& parsed_command_line() const {
88 return parsed_command_line_;
90 const base::FilePath& user_data_dir() const {
91 return user_data_dir_;
94 Profile* profile() { return profile_; }
96 const PrefService* local_state() const { return local_state_; }
98 private:
99 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
101 // Constructs metrics service and does related initialization, including
102 // creation of field trials. Call only after labs have been converted to
103 // switches.
104 void SetupMetricsAndFieldTrials();
106 // Starts recording of metrics. This can only be called after we have a file
107 // thread.
108 void StartMetricsRecording();
110 // Record time from process startup to present time in an UMA histogram.
111 void RecordBrowserStartupTime();
113 // Create parameters for sampling stacks during startup.
114 static base::StackSamplingProfiler::SamplingParams GetStartupSamplingParams();
116 // Methods for Main Message Loop -------------------------------------------
118 int PreCreateThreadsImpl();
119 int PreMainMessageLoopRunImpl();
121 // Members initialized on construction ---------------------------------------
123 const content::MainFunctionParams parameters_;
124 const base::CommandLine& parsed_command_line_;
125 int result_code_;
127 // Create StartupTimeBomb object for watching jank during startup.
128 scoped_ptr<StartupTimeBomb> startup_watcher_;
130 // Create ShutdownWatcherHelper object for watching jank during shutdown.
131 // Please keep |shutdown_watcher| as the first object constructed, and hence
132 // it is destroyed last.
133 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
135 // Statistical testing infrastructure for the entire browser. NULL until
136 // SetupMetricsAndFieldTrials is called.
137 scoped_ptr<base::FieldTrialList> field_trial_list_;
139 ChromeBrowserFieldTrials browser_field_trials_;
141 #if !defined(OS_ANDROID) && !defined(OS_IOS)
142 // A monitor for attributing power consumption to origins.
143 scoped_ptr<ProcessPowerCollector> process_power_collector_;
144 #endif
146 // Vector of additional ChromeBrowserMainExtraParts.
147 // Parts are deleted in the inverse order they are added.
148 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
150 // A profiler that periodically samples stack traces. Used to sample startup
151 // behavior.
152 base::StackSamplingProfiler sampling_profiler_;
154 // Members initialized after / released before main_message_loop_ ------------
156 scoped_ptr<BrowserProcessImpl> browser_process_;
157 scoped_refptr<metrics::TrackingSynchronizer> tracking_synchronizer_;
158 #if !defined(OS_ANDROID)
159 // Browser creation happens on the Java side in Android.
160 scoped_ptr<StartupBrowserCreator> browser_creator_;
162 // Android doesn't support multiple browser processes, so it doesn't implement
163 // ProcessSingleton.
164 scoped_ptr<ChromeProcessSingleton> process_singleton_;
166 // Android's first run is done in Java instead of native.
167 scoped_ptr<first_run::MasterPrefs> master_prefs_;
168 #endif
169 Profile* profile_;
170 bool run_message_loop_;
171 ProcessSingleton::NotifyResult notify_result_;
172 scoped_ptr<ThreeDAPIObserver> three_d_observer_;
174 // Initialized in SetupMetricsAndFieldTrials.
175 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
177 // Members initialized in PreMainMessageLoopRun, needed in
178 // PreMainMessageLoopRunThreadsCreated.
179 PrefService* local_state_;
180 base::FilePath user_data_dir_;
182 // Members needed across shutdown methods.
183 bool restart_last_session_;
185 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
188 #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_