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/tracked_objects.h"
12 #include "chrome/browser/chrome_browser_field_trials.h"
13 #include "chrome/browser/chrome_process_singleton.h"
14 #include "chrome/browser/first_run/first_run.h"
15 #include "chrome/browser/process_singleton.h"
16 #include "chrome/browser/task_profiler/auto_tracking.h"
17 #include "chrome/browser/ui/startup/startup_browser_creator.h"
18 #include "content/public/browser/browser_main_parts.h"
19 #include "content/public/browser/render_view_host.h"
21 class ActiveTabTracker
;
22 class BrowserProcessImpl
;
23 class ChromeBrowserMainExtraParts
;
24 class FieldTrialSynchronizer
;
28 class StartupBrowserCreator
;
29 class StartupTimeBomb
;
30 class ShutdownWatcherHelper
;
31 class ThreeDAPIObserver
;
32 class TranslateManager
;
34 namespace chrome_browser
{
35 // For use by ShowMissingLocaleMessageBox.
36 extern const char kMissingLocaleDataTitle
[];
37 extern const char kMissingLocaleDataMessage
[];
40 namespace chrome_browser_metrics
{
41 class TrackingSynchronizer
;
45 struct MainFunctionParams
;
48 namespace performance_monitor
{
52 class ChromeBrowserMainParts
: public content::BrowserMainParts
{
54 virtual ~ChromeBrowserMainParts();
56 // Add additional ChromeBrowserMainExtraParts.
57 virtual void AddParts(ChromeBrowserMainExtraParts
* parts
);
60 explicit ChromeBrowserMainParts(
61 const content::MainFunctionParams
& parameters
);
63 // content::BrowserMainParts overrides.
64 // 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.
67 virtual void PreEarlyInitialization() OVERRIDE
;
68 virtual void PostEarlyInitialization() OVERRIDE
;
69 virtual void ToolkitInitialized() OVERRIDE
;
70 virtual void PreMainMessageLoopStart() OVERRIDE
;
71 virtual void PostMainMessageLoopStart() OVERRIDE
;
72 virtual int PreCreateThreads() OVERRIDE
;
73 virtual void PreMainMessageLoopRun() OVERRIDE
;
74 virtual bool MainMessageLoopRun(int* result_code
) OVERRIDE
;
75 virtual void PostMainMessageLoopRun() OVERRIDE
;
76 virtual void PostDestroyThreads() OVERRIDE
;
78 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
79 // in order from PreMainMessageLoopRun(). See implementation for details.
80 virtual void PreProfileInit();
81 virtual void PostProfileInit();
82 virtual void PreBrowserStart();
83 virtual void PostBrowserStart();
85 #if !defined(OS_ANDROID)
86 // Runs the PageCycler; called if the switch kVisitURLs is present.
87 virtual void RunPageCycler();
90 // Override this in subclasses to initialize platform specific field trials.
91 virtual void SetupPlatformFieldTrials();
93 // Displays a warning message that we can't find any locale data files.
94 virtual void ShowMissingLocaleMessageBox() = 0;
96 const content::MainFunctionParams
& parameters() const {
99 const CommandLine
& parsed_command_line() const {
100 return parsed_command_line_
;
103 Profile
* profile() { return profile_
; }
105 const PrefService
* local_state() const { return local_state_
; }
108 // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
110 // Constructs metrics service and does related initialization, including
111 // creation of field trials. Call only after labs have been converted to
113 void SetupMetricsAndFieldTrials();
115 // Starts recording of metrics. This can only be called after we have a file
117 void StartMetricsRecording();
119 // Returns true if the user opted in to sending metric reports.
120 bool IsMetricsReportingEnabled();
122 // Methods for Main Message Loop -------------------------------------------
124 int PreCreateThreadsImpl();
125 int PreMainMessageLoopRunImpl();
127 // Members initialized on construction ---------------------------------------
129 const content::MainFunctionParams
& parameters_
;
130 const CommandLine
& parsed_command_line_
;
133 // Create StartupTimeBomb object for watching jank during startup.
134 scoped_ptr
<StartupTimeBomb
> startup_watcher_
;
136 // 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_
;
141 // 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_
;
146 // 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.
149 task_profiler::AutoTracking tracking_objects_
;
151 // Statistical testing infrastructure for the entire browser. NULL until
152 // SetupMetricsAndFieldTrials is called.
153 scoped_ptr
<base::FieldTrialList
> field_trial_list_
;
155 ChromeBrowserFieldTrials browser_field_trials_
;
157 content::RenderViewHost::CreatedCallback rvh_callback_
;
159 // Vector of additional ChromeBrowserMainExtraParts.
160 // Parts are deleted in the inverse order they are added.
161 std::vector
<ChromeBrowserMainExtraParts
*> chrome_extra_parts_
;
163 // Members initialized after / released before main_message_loop_ ------------
165 scoped_ptr
<BrowserProcessImpl
> browser_process_
;
166 scoped_refptr
<chrome_browser_metrics::TrackingSynchronizer
>
167 tracking_synchronizer_
;
168 #if !defined(OS_ANDROID)
169 // Browser creation happens on the Java side in Android.
170 scoped_ptr
<StartupBrowserCreator
> browser_creator_
;
172 // Android doesn't support multiple browser processes, so it doesn't implement
174 scoped_ptr
<ChromeProcessSingleton
> process_singleton_
;
176 scoped_ptr
<first_run::MasterPrefs
> master_prefs_
;
177 bool record_search_engine_
;
178 TranslateManager
* translate_manager_
;
180 bool run_message_loop_
;
181 ProcessSingleton::NotifyResult notify_result_
;
182 scoped_ptr
<ThreeDAPIObserver
> three_d_observer_
;
184 // Initialized in SetupMetricsAndFieldTrials.
185 scoped_refptr
<FieldTrialSynchronizer
> field_trial_synchronizer_
;
187 // Members initialized in PreMainMessageLoopRun, needed in
188 // PreMainMessageLoopRunThreadsCreated.
189 bool do_first_run_tasks_
;
190 PrefService
* local_state_
;
191 base::FilePath user_data_dir_
;
193 #if !defined(OS_ANDROID)
194 scoped_ptr
<ActiveTabTracker
> active_tab_tracker_
;
197 // Members needed across shutdown methods.
198 bool restart_last_session_
;
200 // 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_
;
204 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts
);
207 // 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.
211 void RecordBreakpadStatusUMA(MetricsService
* metrics
);
213 // Displays a warning message if some minimum level of OS support is not
214 // present on the current platform.
215 void WarnAboutMinimumSystemRequirements();
217 // Record time from process startup to present time in an UMA histogram.
218 // |is_first_run| - is the current launch part of a first run.
219 void RecordBrowserStartupTime(bool is_first_run
);
221 // 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)).
224 void RecordPreReadExperimentTime(const char* name
, base::TimeDelta time
);
226 #endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_