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