| 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_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ | 5 #ifndef CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ |
| 6 #define CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ | 6 #define CONTENT_BROWSER_MOJO_MOJO_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" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
| 15 #include "base/sequenced_task_runner.h" | |
| 16 #include "services/shell/public/cpp/interface_provider.h" | |
| 17 #include "services/shell/public/cpp/interface_registry.h" | |
| 18 #include "services/shell/public/interfaces/connector.mojom.h" | 13 #include "services/shell/public/interfaces/connector.mojom.h" |
| 19 | 14 |
| 20 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
| 21 #include "content/public/browser/android/service_registry_android.h" | 16 #include "content/public/browser/android/service_registry_android.h" |
| 22 #endif | 17 #endif |
| 23 | 18 |
| 24 namespace shell { | 19 namespace shell { |
| 25 class Connection; | 20 class Connection; |
| 26 class Connector; | 21 class Connector; |
| 27 } | 22 } |
| 28 | 23 |
| 29 namespace content { | 24 namespace content { |
| 30 | 25 |
| 31 // Helper class to establish a connection between the shell and a single child | 26 // Helper class to establish a connection between the shell and a single child |
| 32 // process. Process hosts can use this when launching new processes which | 27 // process. Process hosts can use this when launching new processes which |
| 33 // should be registered with the shell. | 28 // should be registered with the shell. |
| 34 class MojoChildConnection { | 29 class MojoChildConnection { |
| 35 public: | 30 public: |
| 36 // Prepares a new child connection for a child process which will be | 31 // Prepares a new child connection for a child process which will be |
| 37 // identified to the shell as |application_name|. |instance_id| must be | 32 // identified to the shell as |application_name|. |instance_id| must be |
| 38 // unique among all child connections using the same |application_name|. | 33 // unique among all child connections using the same |application_name|. |
| 39 // |connector| is the connector to use to establish the connection. | 34 // |connector| is the connector to use to establish the connection. |
| 40 MojoChildConnection(const std::string& application_name, | 35 MojoChildConnection(const std::string& application_name, |
| 41 const std::string& instance_id, | 36 const std::string& instance_id, |
| 42 const std::string& child_token, | 37 const std::string& child_token, |
| 43 shell::Connector* connector, | 38 shell::Connector* connector); |
| 44 scoped_refptr<base::SequencedTaskRunner> io_task_runner); | |
| 45 ~MojoChildConnection(); | 39 ~MojoChildConnection(); |
| 46 | 40 |
| 47 shell::InterfaceRegistry* GetInterfaceRegistry() { | 41 shell::Connection* connection() const { |
| 48 return &interface_registry_; | 42 return connection_.get(); |
| 49 } | |
| 50 | |
| 51 shell::InterfaceProvider* GetRemoteInterfaces() { | |
| 52 return &remote_interfaces_; | |
| 53 } | 43 } |
| 54 | 44 |
| 55 // A token which must be passed to the child process via | 45 // A token which must be passed to the child process via |
| 56 // |switches::kPrimordialPipeToken| in order for the child to initialize its | 46 // |switches::kPrimordialPipeToken| in order for the child to initialize its |
| 57 // end of the shell connection pipe. | 47 // end of the shell connection pipe. |
| 58 std::string service_token() const { return service_token_; } | 48 std::string service_token() const { return service_token_; } |
| 59 | 49 |
| 60 // Sets the child connection's process handle. This should be called as soon | 50 // Sets the child connection's process handle. This should be called as soon |
| 61 // as the process has been launched, and the connection will not be fully | 51 // as the process has been launched, and the connection will not be fully |
| 62 // functional until this is called. | 52 // functional until this is called. |
| 63 void SetProcessHandle(base::ProcessHandle handle); | 53 void SetProcessHandle(base::ProcessHandle handle); |
| 64 | 54 |
| 65 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
| 66 ServiceRegistryAndroid* service_registry_android() { | 56 ServiceRegistryAndroid* service_registry_android() { |
| 67 return service_registry_android_.get(); | 57 return service_registry_android_.get(); |
| 68 } | 58 } |
| 69 #endif | 59 #endif |
| 70 | 60 |
| 71 private: | 61 private: |
| 72 class IOThreadContext; | |
| 73 | |
| 74 void GetInterface(const mojo::String& interface_name, | |
| 75 mojo::ScopedMessagePipeHandle request_handle); | |
| 76 | |
| 77 scoped_refptr<IOThreadContext> context_; | |
| 78 | |
| 79 const std::string service_token_; | 62 const std::string service_token_; |
| 80 | 63 std::unique_ptr<shell::Connection> connection_; |
| 81 shell::InterfaceRegistry interface_registry_; | 64 shell::mojom::PIDReceiverPtr pid_receiver_; |
| 82 shell::InterfaceProvider remote_interfaces_; | |
| 83 | |
| 84 #if defined(OS_ANDROID) | 65 #if defined(OS_ANDROID) |
| 85 std::unique_ptr<ServiceRegistryAndroid> service_registry_android_; | 66 std::unique_ptr<ServiceRegistryAndroid> service_registry_android_; |
| 86 #endif | 67 #endif |
| 87 | 68 |
| 88 base::WeakPtrFactory<MojoChildConnection> weak_factory_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(MojoChildConnection); | 69 DISALLOW_COPY_AND_ASSIGN(MojoChildConnection); |
| 91 }; | 70 }; |
| 92 | 71 |
| 93 } // namespace content | 72 } // namespace content |
| 94 | 73 |
| 95 #endif // CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ | 74 #endif // CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ |
| OLD | NEW |