blob: 2ed1097610c5f95361eca071a2664e0734c650a1 [file] [log] [blame]
[email protected]d15b7ca2012-01-04 01:42:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1152b7e2009-09-14 03:26:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e6b5bc22011-09-08 22:01:565#ifndef CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
6#define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
[email protected]1152b7e2009-09-14 03:26:037
dcheng4af48582016-04-19 00:29:358#include <memory>
wittman832321f52016-10-10 18:18:389#include <vector>
dcheng4af48582016-04-19 00:29:3510
avie4d7b6f2015-12-26 00:59:1811#include "base/macros.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/field_trial.h"
Jamie Madillaba2fd202017-10-11 14:20:3713#include "base/profiler/stack_sampling_profiler.h"
avie4d7b6f2015-12-26 00:59:1814#include "build/build_config.h"
[email protected]ae9e12a2012-07-31 17:48:1215#include "chrome/browser/chrome_browser_field_trials.h"
[email protected]9a47c432013-04-19 20:33:5516#include "chrome/browser/chrome_process_singleton.h"
[email protected]c1702d712011-09-08 19:41:4317#include "chrome/browser/first_run/first_run.h"
[email protected]66013922011-09-13 18:53:4218#include "chrome/browser/process_singleton.h"
[email protected]fe7c4872012-05-10 20:06:0319#include "chrome/browser/ui/startup/startup_browser_creator.h"
Jamie Madillaba2fd202017-10-11 14:20:3720#include "chrome/common/stack_sampling_configuration.h"
21#include "components/metrics/call_stack_profile_params.h"
[email protected]b48c9182011-10-26 18:03:3022#include "content/public/browser/browser_main_parts.h"
[email protected]57624ab2013-08-01 16:01:5123#include "content/public/common/main_function_params.h"
[email protected]f8abf722010-07-07 19:46:2424
[email protected]c1702d712011-09-08 19:41:4325class BrowserProcessImpl;
[email protected]50462bf02011-11-21 19:13:3126class ChromeBrowserMainExtraParts;
[email protected]edafd4c2011-05-10 17:18:5327class FieldTrialSynchronizer;
[email protected]edafd4c2011-05-10 17:18:5328class PrefService;
[email protected]c1702d712011-09-08 19:41:4329class Profile;
[email protected]fe7c4872012-05-10 20:06:0330class StartupBrowserCreator;
[email protected]08f1c5e2011-12-01 01:54:3431class StartupTimeBomb;
[email protected]f967b722011-09-07 00:58:0432class ShutdownWatcherHelper;
[email protected]44327692013-02-26 21:21:2233class ThreeDAPIObserver;
juncai1da12032016-07-15 19:10:1234class WebUsbDetector;
[email protected]5f988b92011-05-18 07:14:0835
[email protected]cbce47242011-08-12 21:40:5936namespace chrome_browser {
37// For use by ShowMissingLocaleMessageBox.
[email protected]49aa5a32014-02-03 10:00:4438#if defined(OS_WIN)
[email protected]cbce47242011-08-12 21:40:5939extern const char kMissingLocaleDataTitle[];
[email protected]49aa5a32014-02-03 10:00:4440#endif
41
[email protected]893124a22014-04-15 00:45:2842#if defined(OS_WIN)
[email protected]cbce47242011-08-12 21:40:5943extern const char kMissingLocaleDataMessage[];
[email protected]49aa5a32014-02-03 10:00:4444#endif
[email protected]cbce47242011-08-12 21:40:5945}
46
[email protected]f967b722011-09-07 00:58:0447class ChromeBrowserMainParts : public content::BrowserMainParts {
[email protected]f8abf722010-07-07 19:46:2448 public:
Daniel Chenga542fca2014-10-21 09:51:2949 ~ChromeBrowserMainParts() override;
[email protected]f8abf722010-07-07 19:46:2450
[email protected]50462bf02011-11-21 19:13:3151 // Add additional ChromeBrowserMainExtraParts.
52 virtual void AddParts(ChromeBrowserMainExtraParts* parts);
[email protected]069cd9952011-10-01 16:34:4553
[email protected]f8abf722010-07-07 19:46:2454 protected:
[email protected]4573fbd2011-10-31 20:25:1855 explicit ChromeBrowserMainParts(
56 const content::MainFunctionParams& parameters);
[email protected]f8abf722010-07-07 19:46:2457
[email protected]50462bf02011-11-21 19:13:3158 // content::BrowserMainParts overrides.
[email protected]97ef83f2011-12-19 19:26:3659 // These are called in-order by content::BrowserMainLoop.
60 // Each stage calls the same stages in any ChromeBrowserMainExtraParts added
61 // with AddParts() from ChromeContentBrowserClient::CreateBrowserMainParts.
Scott Violet9068b4df2018-01-12 16:44:2162 int PreEarlyInitialization() override;
Daniel Chenga542fca2014-10-21 09:51:2963 void PostEarlyInitialization() override;
64 void ToolkitInitialized() override;
65 void PreMainMessageLoopStart() override;
66 void PostMainMessageLoopStart() override;
67 int PreCreateThreads() override;
Xi Cheng8c9653712018-01-24 06:07:2768 void PostCreateThreads() override;
bend32292b2016-10-07 00:21:5869 void ServiceManagerConnectionStarted(
70 content::ServiceManagerConnection* connection) override;
Daniel Chenga542fca2014-10-21 09:51:2971 void PreMainMessageLoopRun() override;
72 bool MainMessageLoopRun(int* result_code) override;
73 void PostMainMessageLoopRun() override;
bcwhiteda097d32017-01-12 23:55:0374 void PreShutdown() override;
Daniel Chenga542fca2014-10-21 09:51:2975 void PostDestroyThreads() override;
[email protected]b48c9182011-10-26 18:03:3076
[email protected]97ef83f2011-12-19 19:26:3677 // Additional stages for ChromeBrowserMainExtraParts. These stages are called
[email protected]278a34d2012-06-07 00:34:5878 // in order from PreMainMessageLoopRun(). See implementation for details.
[email protected]97ef83f2011-12-19 19:26:3679 virtual void PreProfileInit();
80 virtual void PostProfileInit();
81 virtual void PreBrowserStart();
82 virtual void PostBrowserStart();
83
[email protected]b48c9182011-10-26 18:03:3084 // Displays a warning message that we can't find any locale data files.
85 virtual void ShowMissingLocaleMessageBox() = 0;
[email protected]f8abf722010-07-07 19:46:2486
[email protected]50462bf02011-11-21 19:13:3187 const content::MainFunctionParams& parameters() const {
88 return parameters_;
89 }
[email protected]2f3b1cc2014-03-17 23:07:1590 const base::CommandLine& parsed_command_line() const {
[email protected]50462bf02011-11-21 19:13:3191 return parsed_command_line_;
92 }
mlermana312cec2015-01-28 21:13:3393 const base::FilePath& user_data_dir() const {
94 return user_data_dir_;
95 }
[email protected]50462bf02011-11-21 19:13:3196
97 Profile* profile() { return profile_; }
98
[email protected]1fec64352010-07-27 13:55:2199 private:
robliaoce2e7d32016-09-19 18:29:00100 // Sets up the field trials and related initialization. Call only after
101 // about:flags have been converted to switches.
102 void SetupFieldTrials();
[email protected]069cd9952011-10-01 16:34:45103
robliaoce2e7d32016-09-19 18:29:00104 // Constructs the metrics service and initializes metrics recording.
105 void SetupMetrics();
[email protected]edafd4c2011-05-10 17:18:53106
[email protected]5281db1d2012-01-11 22:51:54107 // Starts recording of metrics. This can only be called after we have a file
108 // thread.
109 void StartMetricsRecording();
110
[email protected]e8b6ca02013-07-10 18:00:51111 // Record time from process startup to present time in an UMA histogram.
[email protected]69e90692013-07-31 02:13:29112 void RecordBrowserStartupTime();
[email protected]e8b6ca02013-07-10 18:00:51113
iclelland27f4bcb2016-06-22 16:41:03114 // Reads origin trial policy data from local state and configures command line
115 // for child processes.
Scott Violet4fe34bfb2018-01-10 22:20:29116 void SetupOriginTrialsCommandLine(PrefService* local_state);
iclelland27f4bcb2016-06-22 16:41:03117
[email protected]b48c9182011-10-26 18:03:30118 // Methods for Main Message Loop -------------------------------------------
119
[email protected]2e5b60a22011-11-28 15:56:41120 int PreCreateThreadsImpl();
[email protected]b48c9182011-10-26 18:03:30121 int PreMainMessageLoopRunImpl();
122
[email protected]f8abf722010-07-07 19:46:24123 // Members initialized on construction ---------------------------------------
124
[email protected]57624ab2013-08-01 16:01:51125 const content::MainFunctionParams parameters_;
[email protected]2f3b1cc2014-03-17 23:07:15126 const base::CommandLine& parsed_command_line_;
[email protected]b48c9182011-10-26 18:03:30127 int result_code_;
128
[email protected]08f1c5e2011-12-01 01:54:34129 // Create StartupTimeBomb object for watching jank during startup.
dcheng4af48582016-04-19 00:29:35130 std::unique_ptr<StartupTimeBomb> startup_watcher_;
[email protected]08f1c5e2011-12-01 01:54:34131
[email protected]f967b722011-09-07 00:58:04132 // 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.
dcheng4af48582016-04-19 00:29:35135 std::unique_ptr<ShutdownWatcherHelper> shutdown_watcher_;
[email protected]f8abf722010-07-07 19:46:24136
robliaoce2e7d32016-09-19 18:29:00137 // Statistical testing infrastructure for the entire browser. nullptr until
138 // |SetupFieldTrials()| is called.
dcheng4af48582016-04-19 00:29:35139 std::unique_ptr<base::FieldTrialList> field_trial_list_;
[email protected]f8abf722010-07-07 19:46:24140
[email protected]ae9e12a2012-07-31 17:48:12141 ChromeBrowserFieldTrials browser_field_trials_;
142
thestig0c55ee32017-06-20 22:17:51143#if !defined(OS_ANDROID)
juncai1da12032016-07-15 19:10:12144 std::unique_ptr<WebUsbDetector> web_usb_detector_;
dhnishi3cf1d2aa2014-08-26 22:25:07145#endif
146
[email protected]50462bf02011-11-21 19:13:31147 // Vector of additional ChromeBrowserMainExtraParts.
148 // Parts are deleted in the inverse order they are added.
149 std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
150
Xi Cheng8c9653712018-01-24 06:07:27151 // A profiler that periodically samples stack traces on the UI thread.
152 base::StackSamplingProfiler ui_thread_sampling_profiler_;
Jamie Madillaba2fd202017-10-11 14:20:37153
[email protected]0f247aea82011-09-03 03:05:51154 // Members initialized after / released before main_message_loop_ ------------
155
dcheng4af48582016-04-19 00:29:35156 std::unique_ptr<BrowserProcessImpl> browser_process_;
pkasting28ae5792016-05-20 21:39:14157
bshe0d948072016-01-05 19:06:20158#if !defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09159 // Browser creation happens on the Java side in Android.
dcheng4af48582016-04-19 00:29:35160 std::unique_ptr<StartupBrowserCreator> browser_creator_;
[email protected]81054f812012-08-30 00:47:09161
162 // Android doesn't support multiple browser processes, so it doesn't implement
163 // ProcessSingleton.
dcheng4af48582016-04-19 00:29:35164 std::unique_ptr<ChromeProcessSingleton> process_singleton_;
[email protected]d29f4e312013-08-07 05:28:31165
166 // Android's first run is done in Java instead of native.
dcheng4af48582016-04-19 00:29:35167 std::unique_ptr<first_run::MasterPrefs> master_prefs_;
pkasting28ae5792016-05-20 21:39:14168
169 ProcessSingleton::NotifyResult notify_result_ =
170 ProcessSingleton::PROCESS_NONE;
171
172 // Members needed across shutdown methods.
173 bool restart_last_session_ = false;
bshe0d948072016-01-05 19:06:20174#endif
pkasting28ae5792016-05-20 21:39:14175
[email protected]c1702d712011-09-08 19:41:43176 Profile* profile_;
177 bool run_message_loop_;
dcheng4af48582016-04-19 00:29:35178 std::unique_ptr<ThreeDAPIObserver> three_d_observer_;
[email protected]0f247aea82011-09-03 03:05:51179
robliaoce2e7d32016-09-19 18:29:00180 // Initialized in |SetupFieldTrials()|.
[email protected]edafd4c2011-05-10 17:18:53181 scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
182
[email protected]650b2d52013-02-10 03:41:45183 base::FilePath user_data_dir_;
[email protected]2e5b60a22011-11-28 15:56:41184
[email protected]f967b722011-09-07 00:58:04185 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
[email protected]f8abf722010-07-07 19:46:24186};
187
[email protected]e6b5bc22011-09-08 22:01:56188#endif // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_