[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / 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 <memory>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/run_loop.h"
13 #include "build/build_config.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 "chrome/common/buildflags.h"
19 #include "content/public/browser/browser_main_parts.h"
20 #include "content/public/common/main_function_params.h"
21
22 #if BUILDFLAG(ENABLE_DOWNGRADE_PROCESSING)
23 #include "chrome/browser/downgrade/downgrade_manager.h"
24 #endif
25
26 class BrowserProcessImpl;
27 class ChromeBrowserMainExtraParts;
28 class StartupData;
29 class PrefService;
30 class Profile;
31 class StartupBrowserCreator;
32 class ShutdownWatcherHelper;
33 class WebUsbDetector;
34
35 namespace base {
36 class RunLoop;
37 }
38
39 namespace tracing {
40 class TraceEventSystemStatsMonitor;
41 }
42
43 namespace performance_monitor {
44 class SystemMonitor;
45 }
46
47 class ChromeBrowserMainParts : public content::BrowserMainParts {
48  public:
49   ~ChromeBrowserMainParts() override;
50
51   // Add additional ChromeBrowserMainExtraParts.
52   virtual void AddParts(ChromeBrowserMainExtraParts* parts);
53
54 #if !defined(OS_ANDROID)
55   // Returns the RunLoop that would be run by MainMessageLoopRun. This is used
56   // by InProcessBrowserTests to allow them to run until the BrowserProcess is
57   // ready for the browser to exit.
58   static std::unique_ptr<base::RunLoop> TakeRunLoopForTest();
59 #endif
60
61  protected:
62   ChromeBrowserMainParts(const content::MainFunctionParams& parameters,
63                          StartupData* startup_data);
64
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   int PreEarlyInitialization() override;
70   void PostEarlyInitialization() override;
71   void ToolkitInitialized() override;
72   void PreMainMessageLoopStart() override;
73   void PostMainMessageLoopStart() override;
74   int PreCreateThreads() override;
75   void PostCreateThreads() override;
76   void PreMainMessageLoopRun() override;
77   bool MainMessageLoopRun(int* result_code) override;
78   void PostMainMessageLoopRun() override;
79   void PostDestroyThreads() override;
80
81   // Additional stages for ChromeBrowserMainExtraParts. These stages are called
82   // in order from PreMainMessageLoopRun(). See implementation for details.
83   virtual void PreProfileInit();
84   virtual void PostProfileInit();
85   virtual void PreBrowserStart();
86   virtual void PostBrowserStart();
87
88   // Displays a warning message that we can't find any locale data files.
89   virtual void ShowMissingLocaleMessageBox() = 0;
90
91   const content::MainFunctionParams& parameters() const {
92     return parameters_;
93   }
94   const base::CommandLine& parsed_command_line() const {
95     return parsed_command_line_;
96   }
97   const base::FilePath& user_data_dir() const {
98     return user_data_dir_;
99   }
100
101   Profile* profile() { return profile_; }
102
103  private:
104   friend class ChromeBrowserMainPartsTestApi;
105
106   // Constructs the metrics service and initializes metrics recording.
107   void SetupMetrics();
108
109   // Starts recording of metrics. This can only be called after we have a file
110   // thread.
111   static void StartMetricsRecording();
112
113   // Record time from process startup to present time in an UMA histogram.
114   void RecordBrowserStartupTime();
115
116   // Reads origin trial policy data from local state and configures command line
117   // for child processes.
118   void SetupOriginTrialsCommandLine(PrefService* local_state);
119
120   // Calling during PreEarlyInitialization() to complete the remaining tasks
121   // after the local state is loaded. Return value is an exit status,
122   // RESULT_CODE_NORMAL_EXIT indicates success. If the return value is
123   // RESULT_CODE_MISSING_DATA, then |failed_to_load_resource_bundle| indicates
124   // if the ResourceBundle couldn't be loaded.
125   int OnLocalStateLoaded(bool* failed_to_load_resource_bundle);
126
127   // Applies any preferences (to local state) needed for first run. This is
128   // always called and early outs if not first-run. Return value is an exit
129   // status, RESULT_CODE_NORMAL_EXIT indicates success.
130   int ApplyFirstRunPrefs();
131
132   // Methods for Main Message Loop -------------------------------------------
133
134   int PreCreateThreadsImpl();
135   int PreMainMessageLoopRunImpl();
136
137   // Members initialized on construction ---------------------------------------
138
139   const content::MainFunctionParams parameters_;
140   // TODO(sky): remove this. This class (and related calls), may mutate the
141   // CommandLine, so it is misleading keeping a const ref here.
142   const base::CommandLine& parsed_command_line_;
143   int result_code_;
144
145 #if !defined(OS_ANDROID)
146   // Create ShutdownWatcherHelper object for watching jank during shutdown.
147   // Please keep |shutdown_watcher| as the first object constructed, and hence
148   // it is destroyed last.
149   std::unique_ptr<ShutdownWatcherHelper> shutdown_watcher_;
150
151   std::unique_ptr<WebUsbDetector> web_usb_detector_;
152 #endif  // !defined(OS_ANDROID)
153
154   // Vector of additional ChromeBrowserMainExtraParts.
155   // Parts are deleted in the inverse order they are added.
156   std::vector<ChromeBrowserMainExtraParts*> chrome_extra_parts_;
157
158   // The system monitor instance, used by some subsystems to collect the system
159   // metrics they need.
160   std::unique_ptr<performance_monitor::SystemMonitor> system_monitor_;
161
162   // The system stats monitor used by chrome://tracing. This doesn't do anything
163   // until tracing of the |system_stats| category is enabled.
164   std::unique_ptr<tracing::TraceEventSystemStatsMonitor>
165       trace_event_system_stats_monitor_;
166
167   // Whether PerformPreMainMessageLoopStartup() is called on VariationsService.
168   // Initialized to true if |MainFunctionParams::ui_task| is null (meaning not
169   // running browser_tests), but may be forced to true for tests.
170   bool should_call_pre_main_loop_start_startup_on_variations_service_;
171
172   // Members initialized after / released before main_message_loop_ ------------
173
174   std::unique_ptr<BrowserProcessImpl> browser_process_;
175
176 #if !defined(OS_ANDROID)
177   // Browser creation happens on the Java side in Android.
178   std::unique_ptr<StartupBrowserCreator> browser_creator_;
179
180   // Android doesn't support multiple browser processes, so it doesn't implement
181   // ProcessSingleton.
182   std::unique_ptr<ChromeProcessSingleton> process_singleton_;
183
184   ProcessSingleton::NotifyResult notify_result_ =
185       ProcessSingleton::PROCESS_NONE;
186
187   // Members needed across shutdown methods.
188   bool restart_last_session_ = false;
189 #endif  // !defined(OS_ANDROID)
190
191 #if BUILDFLAG(ENABLE_DOWNGRADE_PROCESSING)
192   downgrade::DowngradeManager downgrade_manager_;
193 #endif
194
195 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
196   // Android's first run is done in Java instead of native. Chrome OS does not
197   // use master preferences.
198   std::unique_ptr<first_run::MasterPrefs> master_prefs_;
199 #endif
200
201   Profile* profile_;
202   bool run_message_loop_;
203
204   base::FilePath user_data_dir_;
205
206   StartupData* startup_data_;
207
208   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
209 };
210
211 #endif  // CHROME_BROWSER_CHROME_BROWSER_MAIN_H_