Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chrome_browser_main.h
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.
4
5 #ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
6 #define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
7
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/common/main_function_params.h"
20
21 class BrowserProcessImpl;
22 class ChromeBrowserMainExtraParts;
23 class FieldTrialSynchronizer;
24 class MetricsService;
25 class PrefService;
26 class Profile;
27 class StartupBrowserCreator;
28 class StartupTimeBomb;
29 class ShutdownWatcherHelper;
30 class ThreeDAPIObserver;
31
32 namespace chrome_browser {
33 // For use by ShowMissingLocaleMessageBox.
34 #if defined(OS_WIN)
35 extern const char kMissingLocaleDataTitle[];
36 #endif
37
38 #if defined(OS_WIN) || defined(TOOLKIT_GTK)
39 extern const char kMissingLocaleDataMessage[];
40 #endif
41 }
42
43 namespace chrome_browser_metrics {
44 class TrackingSynchronizer;
45 }
46
47 namespace performance_monitor {
48 class StartupTimer;
49 }
50
51 class ChromeBrowserMainParts : public content::BrowserMainParts {
52  public:
53   virtual ~ChromeBrowserMainParts();
54
55   // Add additional ChromeBrowserMainExtraParts.
56   virtual void AddParts(ChromeBrowserMainExtraParts* parts);
57
58  protected:
59   explicit ChromeBrowserMainParts(
60       const content::MainFunctionParams& parameters);
61
62   // content::BrowserMainParts overrides.
63   // These are called in-order by content::BrowserMainLoop.
64   // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
65   // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
66   virtual void PreEarlyInitialization() OVERRIDE;
67   virtual void PostEarlyInitialization() OVERRIDE;
68   virtual void ToolkitInitialized() OVERRIDE;
69   virtual void PreMainMessageLoopStart() OVERRIDE;
70   virtual void PostMainMessageLoopStart() OVERRIDE;
71   virtual int PreCreateThreads() OVERRIDE;
72   virtual void PreMainMessageLoopRun() OVERRIDE;
73   virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
74   virtual void PostMainMessageLoopRun() OVERRIDE;
75   virtual void PostDestroyThreads() OVERRIDE;
76
77   // Additional stages for ChromeBrowserMainExtraParts. These stages are called
78   // in order from PreMainMessageLoopRun(). See implementation for details.
79   virtual void PreProfileInit();
80   virtual void PostProfileInit();
81   virtual void PreBrowserStart();
82   virtual void PostBrowserStart();
83
84   // Displays a warning message that we can't find any locale data files.
85   virtual void ShowMissingLocaleMessageBox() = 0;
86
87   const content::MainFunctionParams& parameters() const {
88     return parameters_;
89   }
90   const CommandLine& parsed_command_line() const {
91     return parsed_command_line_;
92   }
93
94   Profile* profile() { return profile_; }
95
96   const PrefService* local_state() const { return local_state_; }
97
98  private:
99   // Methods for |SetupMetricsAndFieldTrials()| --------------------------------
100
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();
105
106   // Starts recording of metrics. This can only be called after we have a file
107   // thread.
108   void StartMetricsRecording();
109
110   // Returns true if the user opted in to sending metric reports.
111   bool IsMetricsReportingEnabled();
112
113   // Record time from process startup to present time in an UMA histogram.
114   void RecordBrowserStartupTime();
115
116   // Records a time value to an UMA histogram in the context of the
117   // PreReadExperiment field-trial. This also reports to the appropriate
118   // sub-histogram (_PreRead(Enabled|Disabled)).
119   void RecordPreReadExperimentTime(const char* name, base::TimeDelta time);
120
121   // Methods for Main Message Loop -------------------------------------------
122
123   int PreCreateThreadsImpl();
124   int PreMainMessageLoopRunImpl();
125
126   // Members initialized on construction ---------------------------------------
127
128   const content::MainFunctionParams parameters_;
129   const CommandLine& parsed_command_line_;
130   int result_code_;
131
132   // Create StartupTimeBomb object for watching jank during startup.
133   scoped_ptr<StartupTimeBomb> startup_watcher_;
134
135   // Create ShutdownWatcherHelper object for watching jank during shutdown.
136   // Please keep |shutdown_watcher| as the first object constructed, and hence
137   // it is destroyed last.
138   scoped_ptr<ShutdownWatcherHelper> shutdown_watcher_;
139
140   // A timer to hold data regarding startup and session restore times for
141   // PerformanceMonitor so that we don't have to start the entire
142   // PerformanceMonitor at browser startup.
143   scoped_ptr<performance_monitor::StartupTimer> startup_timer_;
144
145   // Creating this object starts tracking the creation and deletion of Task
146   // instance. This MUST be done before main_message_loop, so that it is
147   // destroyed after the main_message_loop.
148   task_profiler::AutoTracking tracking_objects_;
149
150   // Statistical testing infrastructure for the entire browser. NULL until
151   // SetupMetricsAndFieldTrials is called.
152   scoped_ptr<base::FieldTrialList> field_trial_list_;
153
154   ChromeBrowserFieldTrials browser_field_trials_;
155
156   // Vector of additional ChromeBrowserMainExtraParts.
157   // Parts are deleted in the inverse order they are added.
158   std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
159
160   // Members initialized after / released before main_message_loop_ ------------
161
162   scoped_ptr<BrowserProcessImpl> browser_process_;
163   scoped_refptr<chrome_browser_metrics::TrackingSynchronizer>
164       tracking_synchronizer_;
165 #if !defined(OS_ANDROID)
166   // Browser creation happens on the Java side in Android.
167   scoped_ptr<StartupBrowserCreator> browser_creator_;
168
169   // Android doesn't support multiple browser processes, so it doesn't implement
170   // ProcessSingleton.
171   scoped_ptr<ChromeProcessSingleton> process_singleton_;
172
173   // Android's first run is done in Java instead of native.
174   scoped_ptr<first_run::MasterPrefs> master_prefs_;
175 #endif
176   Profile* profile_;
177   bool run_message_loop_;
178   ProcessSingleton::NotifyResult notify_result_;
179   scoped_ptr<ThreeDAPIObserver> three_d_observer_;
180
181   // Initialized in SetupMetricsAndFieldTrials.
182   scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
183
184   // Members initialized in PreMainMessageLoopRun, needed in
185   // PreMainMessageLoopRunThreadsCreated.
186   PrefService* local_state_;
187   base::FilePath user_data_dir_;
188
189   // Members needed across shutdown methods.
190   bool restart_last_session_;
191
192   // Tests can set this to true to disable restricting cookie access in the
193   // network stack, as this can only be done once.
194   static bool disable_enforcing_cookie_policies_for_tests_;
195
196   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
197 };
198
199 #endif  // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_