| 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_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ | 5 #ifndef CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ |
| 6 #define CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ | 6 #define CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 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/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "mojo/edk/embedder/pending_process_connection.h" | 17 #include "mojo/edk/embedder/pending_process_connection.h" |
| 18 #include "services/service_manager/public/cpp/identity.h" | 18 #include "services/service_manager/public/cpp/identity.h" |
| 19 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 20 #include "services/service_manager/public/interfaces/connector.mojom.h" | 19 #include "services/service_manager/public/interfaces/connector.mojom.h" |
| 21 | 20 |
| 22 namespace service_manager { | 21 namespace service_manager { |
| 23 class Connector; | 22 class Connector; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 | 26 |
| 28 // Helper class to establish a connection between the Service Manager and a | 27 // Helper class to establish a connection between the Service Manager and a |
| 29 // single child process. Process hosts can use this when launching new processes | 28 // single child process. Process hosts can use this when launching new processes |
| 30 // which should be registered with the service manager. | 29 // which should be registered with the service manager. |
| 31 class CONTENT_EXPORT ChildConnection { | 30 class CONTENT_EXPORT ChildConnection { |
| 32 public: | 31 public: |
| 33 // Prepares a new child connection for a child process which will be | 32 // Prepares a new child connection for a child process which will be |
| 34 // identified to the service manager as |name|. |instance_id| must be unique | 33 // identified to the service manager as |name|. |instance_id| must be unique |
| 35 // among all child connections using the same |name|. |connector| is the | 34 // among all child connections using the same |name|. |connector| is the |
| 36 // connector to use to establish the connection. | 35 // connector to use to establish the connection. |
| 37 ChildConnection(const std::string& name, | 36 ChildConnection(const std::string& name, |
| 38 const std::string& instance_id, | 37 const std::string& instance_id, |
| 39 mojo::edk::PendingProcessConnection* process_connection, | 38 mojo::edk::PendingProcessConnection* process_connection, |
| 40 service_manager::Connector* connector, | 39 service_manager::Connector* connector, |
| 41 scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 40 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
| 42 ~ChildConnection(); | 41 ~ChildConnection(); |
| 43 | 42 |
| 44 service_manager::InterfaceProvider* GetRemoteInterfaces() { | 43 // Binds an implementation of |interface_name| to |interface_pipe| in the |
| 45 return &remote_interfaces_; | 44 // child. |
| 46 } | 45 void BindInterface(const std::string& interface_name, |
| 46 mojo::ScopedMessagePipeHandle interface_pipe); |
| 47 | 47 |
| 48 const service_manager::Identity& child_identity() const { | 48 const service_manager::Identity& child_identity() const { |
| 49 return child_identity_; | 49 return child_identity_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // A token which must be passed to the child process via | 52 // A token which must be passed to the child process via |
| 53 // |switches::kPrimordialPipeToken| in order for the child to initialize its | 53 // |switches::kPrimordialPipeToken| in order for the child to initialize its |
| 54 // end of the Service Manager connection pipe. | 54 // end of the Service Manager connection pipe. |
| 55 std::string service_token() const { return service_token_; } | 55 std::string service_token() const { return service_token_; } |
| 56 | 56 |
| 57 // Sets the child connection's process handle. This should be called as soon | 57 // Sets the child connection's process handle. This should be called as soon |
| 58 // as the process has been launched, and the connection will not be fully | 58 // as the process has been launched, and the connection will not be fully |
| 59 // functional until this is called. | 59 // functional until this is called. |
| 60 void SetProcessHandle(base::ProcessHandle handle); | 60 void SetProcessHandle(base::ProcessHandle handle); |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 class IOThreadContext; | 63 class IOThreadContext; |
| 64 | 64 |
| 65 scoped_refptr<IOThreadContext> context_; | 65 scoped_refptr<IOThreadContext> context_; |
| 66 service_manager::Identity child_identity_; | 66 service_manager::Identity child_identity_; |
| 67 std::string service_token_; | 67 std::string service_token_; |
| 68 base::ProcessHandle process_handle_ = base::kNullProcessHandle; | 68 base::ProcessHandle process_handle_ = base::kNullProcessHandle; |
| 69 | 69 |
| 70 service_manager::InterfaceProvider remote_interfaces_; | |
| 71 | |
| 72 base::WeakPtrFactory<ChildConnection> weak_factory_; | 70 base::WeakPtrFactory<ChildConnection> weak_factory_; |
| 73 | 71 |
| 74 DISALLOW_COPY_AND_ASSIGN(ChildConnection); | 72 DISALLOW_COPY_AND_ASSIGN(ChildConnection); |
| 75 }; | 73 }; |
| 76 | 74 |
| 77 } // namespace content | 75 } // namespace content |
| 78 | 76 |
| 79 #endif // CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ | 77 #endif // CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ |
| OLD | NEW |