1 // Copyright 2013 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 CONTENT_SHELL_BROWSER_SHELL_BROWSER_MAIN_PARTS_H_
6 #define CONTENT_SHELL_BROWSER_SHELL_BROWSER_MAIN_PARTS_H_
7 
8 #include <memory>
9 
10 #include "base/macros.h"
11 #include "base/metrics/field_trial.h"
12 #include "build/build_config.h"
13 #include "content/public/browser/browser_main_parts.h"
14 #include "content/public/common/main_function_params.h"
15 #include "content/shell/browser/shell_browser_context.h"
16 #include "ui/base/buildflags.h"
17 
18 namespace performance_manager {
19 class PerformanceManagerLifetime;
20 }  // namespace performance_manager
21 
22 #if BUILDFLAG(USE_GTK)
23 namespace ui {
24 class GtkUiDelegate;
25 }
26 #endif
27 
28 namespace content {
29 class ShellPlatformDelegate;
30 
31 class ShellBrowserMainParts : public BrowserMainParts {
32  public:
33   explicit ShellBrowserMainParts(const MainFunctionParams& parameters);
34   ~ShellBrowserMainParts() override;
35 
36   // BrowserMainParts overrides.
37   int PreEarlyInitialization() override;
38   int PreCreateThreads() override;
39   void PostCreateThreads() override;
40   void PreMainMessageLoopStart() override;
41   void PostMainMessageLoopStart() override;
42   void ToolkitInitialized() override;
43   void PreMainMessageLoopRun() override;
44   bool MainMessageLoopRun(int* result_code) override;
45   void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
46   void PostMainMessageLoopRun() override;
47   void PostDestroyThreads() override;
48 
browser_context()49   ShellBrowserContext* browser_context() { return browser_context_.get(); }
off_the_record_browser_context()50   ShellBrowserContext* off_the_record_browser_context() {
51     return off_the_record_browser_context_.get();
52   }
53 
54  protected:
55   virtual void InitializeBrowserContexts();
56   virtual void InitializeMessageLoopContext();
57   // Gets the ShellPlatformDelegate to be used. May be a subclass of
58   // ShellPlatformDelegate to change behaviour based on platform or for tests.
59   virtual std::unique_ptr<ShellPlatformDelegate> CreateShellPlatformDelegate();
60 
set_browser_context(ShellBrowserContext * context)61   void set_browser_context(ShellBrowserContext* context) {
62     browser_context_.reset(context);
63   }
set_off_the_record_browser_context(ShellBrowserContext * context)64   void set_off_the_record_browser_context(ShellBrowserContext* context) {
65     off_the_record_browser_context_.reset(context);
66   }
67 
68  private:
69 
70   std::unique_ptr<ShellBrowserContext> browser_context_;
71   std::unique_ptr<ShellBrowserContext> off_the_record_browser_context_;
72 
73   // For running content_browsertests.
74   const MainFunctionParams parameters_;
75   bool run_message_loop_;
76 
77 #if BUILDFLAG(USE_GTK)
78   std::unique_ptr<ui::GtkUiDelegate> gtk_ui_delegate_;
79 #endif
80 
81   std::unique_ptr<performance_manager::PerformanceManagerLifetime>
82       performance_manager_lifetime_;
83 
84   DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts);
85 };
86 
87 }  // namespace content
88 
89 #endif  // CONTENT_SHELL_BROWSER_SHELL_BROWSER_MAIN_PARTS_H_
90