OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ |
6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ | 6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/utility_process_host.h" | 16 #include "content/public/browser/utility_process_host.h" |
17 #include "content/public/browser/utility_process_host_client.h" | 17 #include "content/public/browser/utility_process_host_client.h" |
18 #include "content/public/common/service_registry.h" | 18 #include "content/public/common/service_registry.h" |
19 #include "mojo/public/cpp/bindings/interface_ptr.h" | 19 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 20 #include "services/shell/public/cpp/interface_provider.h" |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 // Implements a client to a Mojo service running on a utility process. Takes | 24 // Implements a client to a Mojo service running on a utility process. Takes |
24 // care of starting the utility process and connecting to the remote Mojo | 25 // care of starting the utility process and connecting to the remote Mojo |
25 // service. The utility process is terminated in the destructor. | 26 // service. The utility process is terminated in the destructor. |
26 // Note: This class is not thread-safe. It is bound to the | 27 // Note: This class is not thread-safe. It is bound to the |
27 // SingleThreadTaskRunner it is created on. | 28 // SingleThreadTaskRunner it is created on. |
28 template <class MojoInterface> | 29 template <class MojoInterface> |
29 class UtilityProcessMojoClient { | 30 class UtilityProcessMojoClient { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // Starts the utility process and connects to the remote Mojo service. | 101 // Starts the utility process and connects to the remote Mojo service. |
101 void StartOnIOThread(const std::string& mojo_interface_name, | 102 void StartOnIOThread(const std::string& mojo_interface_name, |
102 mojo::ScopedMessagePipeHandle interface_pipe) { | 103 mojo::ScopedMessagePipeHandle interface_pipe) { |
103 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
104 utility_host_ = UtilityProcessHost::Create(nullptr, nullptr)->AsWeakPtr(); | 105 utility_host_ = UtilityProcessHost::Create(nullptr, nullptr)->AsWeakPtr(); |
105 utility_host_->SetName(process_name_); | 106 utility_host_->SetName(process_name_); |
106 if (disable_sandbox_) | 107 if (disable_sandbox_) |
107 utility_host_->DisableSandbox(); | 108 utility_host_->DisableSandbox(); |
108 | 109 |
109 utility_host_->Start(); | 110 utility_host_->Start(); |
110 | 111 utility_host_->GetRemoteInterfaces()->GetInterface( |
111 ServiceRegistry* service_registry = utility_host_->GetServiceRegistry(); | 112 mojo_interface_name, std::move(interface_pipe)); |
112 service_registry->ConnectToRemoteService(mojo_interface_name, | |
113 std::move(interface_pipe)); | |
114 } | 113 } |
115 | 114 |
116 // Properties of the utility process. | 115 // Properties of the utility process. |
117 base::string16 process_name_; | 116 base::string16 process_name_; |
118 bool disable_sandbox_ = false; | 117 bool disable_sandbox_ = false; |
119 | 118 |
120 // Must only be accessed on the IO thread. | 119 // Must only be accessed on the IO thread. |
121 base::WeakPtr<UtilityProcessHost> utility_host_; | 120 base::WeakPtr<UtilityProcessHost> utility_host_; |
122 | 121 |
123 DISALLOW_COPY_AND_ASSIGN(Helper); | 122 DISALLOW_COPY_AND_ASSIGN(Helper); |
(...skipping 11 matching lines...) Expand all Loading... |
135 | 134 |
136 // Checks that this class is always accessed from the same thread. | 135 // Checks that this class is always accessed from the same thread. |
137 base::ThreadChecker thread_checker_; | 136 base::ThreadChecker thread_checker_; |
138 | 137 |
139 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoClient); | 138 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoClient); |
140 }; | 139 }; |
141 | 140 |
142 } // namespace content | 141 } // namespace content |
143 | 142 |
144 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ | 143 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_ |
OLD | NEW |