Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main.h
blob140a9606bc4cc776b60cfae1e6477b821be24529
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/stack_sampling_configuration.h"
18 #include "chrome/browser/ui/startup/startup_browser_creator.h"
19 #include "content/public/browser/browser_main_parts.h"
20 #include "content/public/common/main_function_params.h"
22 class BrowserProcessImpl;
23 class ChromeBrowserMainExtraParts;
24 class FieldTrialSynchronizer;
25 class MetricsService;
26 class PrefService;
27 class ProcessPowerCollector;
28 class Profile;
29 class StartupBrowserCreator;
30 class StartupTimeBomb;
31 class ShutdownWatcherHelper;
32 class ThreeDAPIObserver;
34 namespace chrome_browser {
35 // For use by ShowMissingLocaleMessageBox.
36 #if defined(OS_WIN)
37 extern const char kMissingLocaleDataTitle[];
38 #endif
40 #if defined(OS_WIN)
41 extern const char kMissingLocaleDataMessage[];
42 #endif
45 namespace metrics {
46 class TrackingSynchronizer;
49 namespace webusb {
50 class WebUsbBrowserClient;
51 class WebUsbDetector;
54 class ChromeBrowserMainParts : public content::BrowserMainParts {
55 public:
56 ~ChromeBrowserMainParts() override;
58 // Add additional ChromeBrowserMainExtraParts.
59 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
61 protected:
62 explicit ChromeBrowserMainParts(
63 const content::MainFunctionParams& parameters);
65 // content::BrowserMainParts overrides.
66 // These are called in-order by content::BrowserMainLoop.
67 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
68 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
69 void PreEarlyInitialization() override;
70 void PostEarlyInitialization() override;
71 void ToolkitInitialized() override;
72 void PreMainMessageLoopStart() override;
73 void PostMainMessageLoopStart() override;
74 int PreCreateThreads() override;
75 void PreMainMessageLoopRun() override;
76 bool MainMessageLoopRun(int* result_code) override;
77 void PostMainMessageLoopRun() override;
78 void PostDestroyThreads() override;
80 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
81 // in order from PreMainMessageLoopRun(). See implementation for details.
82 virtual void PreProfileInit();
83 virtual void PostProfileInit();
84 virtual void PreBrowserStart();
85 virtual void PostBrowserStart();
87 // Displays a warning message that we can't find any locale data files.
88 virtual void ShowMissingLocaleMessageBox() = 0;
90 const content::MainFunctionParams& parameters() const {
91 return parameters_;
93 const base::CommandLine& parsed_command_line() const {
94 return parsed_command_line_;
96 const base::FilePath& user_data_dir() const {
97 return user_data_dir_;
100 Profile* profile() { return profile_; }
102 const PrefService* local_state() const { return local_state_; }
104 private:
105 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
107 // Constructs metrics service and does related initialization, including
108 // creation of field trials. Call only after labs have been converted to
109 // switches.
110 void SetupMetricsAndFieldTrials();
112 // Starts recording of metrics. This can only be called after we have a file
113 // thread.
114 void StartMetricsRecording();
116 // Record time from process startup to present time in an UMA histogram.
117 void RecordBrowserStartupTime();
119 // Methods for Main Message Loop -------------------------------------------
121 int PreCreateThreadsImpl();
122 int PreMainMessageLoopRunImpl();
124 // Members initialized on construction ---------------------------------------
126 const content::MainFunctionParams parameters_;
127 const base::CommandLine& parsed_command_line_;
128 int result_code_;
130 // Create StartupTimeBomb object for watching jank during startup.
131 scoped_ptr<StartupTimeBomb> startup_watcher_;
133 // Create ShutdownWatcherHelper object for watching jank during shutdown.
134 // Please keep |shutdown_watcher| as the first object constructed, and hence
135 // it is destroyed last.
136 scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
138 // Statistical testing infrastructure for the entire browser. NULL until
139 // SetupMetricsAndFieldTrials is called.
140 scoped_ptr<base::FieldTrialList> field_trial_list_;
142 ChromeBrowserFieldTrials browser_field_trials_;
144 #if !defined(OS_ANDROID) && !defined(OS_IOS)
145 // A monitor for attributing power consumption to origins.
146 scoped_ptr<ProcessPowerCollector> process_power_collector_;
148 scoped_ptr<webusb::WebUsbBrowserClient> webusb_browser_client_;
149 scoped_ptr<webusb::WebUsbDetector> webusb_detector_;
150 #endif
152 // Vector of additional ChromeBrowserMainExtraParts.
153 // Parts are deleted in the inverse order they are added.
154 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
156 // The configuration to use for the stack sampling profiler below.
157 StackSamplingConfiguration sampling_profiler_config_;
159 // A profiler that periodically samples stack traces. Used to sample startup
160 // behavior.
161 base::StackSamplingProfiler sampling_profiler_;
163 // Members initialized after / released before main_message_loop_ ------------
165 scoped_ptr<BrowserProcessImpl> browser_process_;
166 scoped_refptr<metrics::TrackingSynchronizer> tracking_synchronizer_;
167 #if !defined(OS_ANDROID)
168 // Browser creation happens on the Java side in Android.
169 scoped_ptr<StartupBrowserCreator> browser_creator_;
171 // Android doesn't support multiple browser processes, so it doesn't implement
172 // ProcessSingleton.
173 scoped_ptr<ChromeProcessSingleton> process_singleton_;
175 // Android's first run is done in Java instead of native.
176 scoped_ptr<first_run::MasterPrefs> master_prefs_;
177 #endif
178 Profile* profile_;
179 bool run_message_loop_;
180 ProcessSingleton::NotifyResult notify_result_;
181 scoped_ptr<ThreeDAPIObserver> three_d_observer_;
183 // Initialized in SetupMetricsAndFieldTrials.
184 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
186 // Members initialized in PreMainMessageLoopRun, needed in
187 // PreMainMessageLoopRunThreadsCreated.
188 PrefService* local_state_;
189 base::FilePath user_data_dir_;
191 // Members needed across shutdown methods.
192 bool restart_last_session_;
194 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
197 #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_