OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SERVICES_SERVICE_MANAGER_STANDALONE_CONTEXT_H_ | 5 #ifndef SERVICES_SERVICE_MANAGER_STANDALONE_CONTEXT_H_ |
6 #define SERVICES_SERVICE_MANAGER_STANDALONE_CONTEXT_H_ | 6 #define SERVICES_SERVICE_MANAGER_STANDALONE_CONTEXT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "mojo/edk/embedder/process_delegate.h" | |
17 #include "services/service_manager/runner/host/service_process_launcher.h" | 16 #include "services/service_manager/runner/host/service_process_launcher.h" |
18 #include "services/service_manager/service_manager.h" | 17 #include "services/service_manager/service_manager.h" |
19 #include "services/service_manager/standalone/tracer.h" | 18 #include "services/service_manager/standalone/tracer.h" |
20 #include "services/tracing/public/cpp/provider.h" | 19 #include "services/tracing/public/cpp/provider.h" |
21 | 20 |
22 namespace base { | 21 namespace base { |
23 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
24 } | 23 } |
25 | 24 |
26 namespace catalog { | 25 namespace catalog { |
27 class Catalog; | 26 class Catalog; |
28 } | 27 } |
29 | 28 |
30 namespace service_manager { | 29 namespace service_manager { |
31 | 30 |
32 constexpr size_t kThreadPoolMaxThreads = 3; | 31 constexpr size_t kThreadPoolMaxThreads = 3; |
33 | 32 |
34 // The "global" context for the service manager's main process. | 33 // The "global" context for the service manager's main process. |
35 class Context : public mojo::edk::ProcessDelegate { | 34 class Context { |
36 public: | 35 public: |
37 struct InitParams { | 36 struct InitParams { |
38 InitParams(); | 37 InitParams(); |
39 ~InitParams(); | 38 ~InitParams(); |
40 | 39 |
41 ServiceProcessLauncher::Delegate* | 40 ServiceProcessLauncher::Delegate* |
42 service_process_launcher_delegate = nullptr; | 41 service_process_launcher_delegate = nullptr; |
43 std::unique_ptr<base::Value> static_catalog; | 42 std::unique_ptr<base::Value> static_catalog; |
44 // If true the edk is initialized. | 43 // If true the edk is initialized. |
45 bool init_edk = true; | 44 bool init_edk = true; |
46 }; | 45 }; |
47 | 46 |
48 Context(); | 47 Context(); |
49 ~Context() override; | 48 ~Context(); |
50 | 49 |
51 static void EnsureEmbedderIsInitialized(); | 50 static void EnsureEmbedderIsInitialized(); |
52 | 51 |
53 // This must be called with a message loop set up for the current thread, | 52 // This must be called with a message loop set up for the current thread, |
54 // which must remain alive until after Shutdown() is called. | 53 // which must remain alive until after Shutdown() is called. |
55 void Init(std::unique_ptr<InitParams> init_params); | 54 void Init(std::unique_ptr<InitParams> init_params); |
56 | 55 |
57 // If Init() was called and succeeded, this must be called before destruction. | 56 // If Init() was called and succeeded, this must be called before destruction. |
58 void Shutdown(); | 57 void Shutdown(); |
59 | 58 |
60 // Run the application specified on the command line. | 59 // Run the application specified on the command line. |
61 void RunCommandLineApplication(); | 60 void RunCommandLineApplication(); |
62 | 61 |
63 ServiceManager* service_manager() { return service_manager_.get(); } | 62 ServiceManager* service_manager() { return service_manager_.get(); } |
64 | 63 |
65 private: | 64 private: |
66 // mojo::edk::ProcessDelegate: | 65 void OnShutdownComplete(); |
67 void OnShutdownComplete() override; | |
68 | 66 |
69 // Runs the app specified by |name|. | 67 // Runs the app specified by |name|. |
70 void Run(const std::string& name); | 68 void Run(const std::string& name); |
71 | 69 |
72 scoped_refptr<base::SingleThreadTaskRunner> service_manager_runner_; | 70 scoped_refptr<base::SingleThreadTaskRunner> service_manager_runner_; |
73 std::unique_ptr<base::Thread> io_thread_; | 71 std::unique_ptr<base::Thread> io_thread_; |
74 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | 72 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; |
75 | 73 |
76 // Ensure this is destructed before task_runners_ since it owns a message pipe | 74 // Ensure this is destructed before task_runners_ since it owns a message pipe |
77 // that needs the IO thread to destruct cleanly. | 75 // that needs the IO thread to destruct cleanly. |
78 Tracer tracer_; | 76 Tracer tracer_; |
79 tracing::Provider provider_; | 77 tracing::Provider provider_; |
80 std::unique_ptr<catalog::Catalog> catalog_; | 78 std::unique_ptr<catalog::Catalog> catalog_; |
81 std::unique_ptr<ServiceManager> service_manager_; | 79 std::unique_ptr<ServiceManager> service_manager_; |
82 base::Time main_entry_time_; | 80 base::Time main_entry_time_; |
83 bool init_edk_ = false; | 81 bool init_edk_ = false; |
84 | 82 |
85 DISALLOW_COPY_AND_ASSIGN(Context); | 83 DISALLOW_COPY_AND_ASSIGN(Context); |
86 }; | 84 }; |
87 | 85 |
88 } // namespace service_manager | 86 } // namespace service_manager |
89 | 87 |
90 #endif // SERVICES_SERVICE_MANAGER_STANDALONE_CONTEXT_H_ | 88 #endif // SERVICES_SERVICE_MANAGER_STANDALONE_CONTEXT_H_ |
OLD | NEW |