Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: content/common/service_manager/child_connection.h

Issue 2680973006: Mojo EDK: Add safe process connection API (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "services/service_manager/public/cpp/identity.h" 18 #include "services/service_manager/public/cpp/identity.h"
18 #include "services/service_manager/public/cpp/interface_provider.h" 19 #include "services/service_manager/public/cpp/interface_provider.h"
19 #include "services/service_manager/public/interfaces/connector.mojom.h" 20 #include "services/service_manager/public/interfaces/connector.mojom.h"
20 21
21 namespace service_manager { 22 namespace service_manager {
22 class Connector; 23 class Connector;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 27
27 // Helper class to establish a connection between the Service Manager and a 28 // Helper class to establish a connection between the Service Manager and a
28 // single child process. Process hosts can use this when launching new processes 29 // single child process. Process hosts can use this when launching new processes
29 // which should be registered with the service manager. 30 // which should be registered with the service manager.
30 class CONTENT_EXPORT ChildConnection { 31 class CONTENT_EXPORT ChildConnection {
31 public: 32 public:
32 // Prepares a new child connection for a child process which will be 33 // Prepares a new child connection for a child process which will be
33 // identified to the service manager as |name|. |instance_id| must be unique 34 // identified to the service manager as |name|. |instance_id| must be unique
34 // among all child connections using the same |name|. |connector| is the 35 // among all child connections using the same |name|. |connector| is the
35 // connector to use to establish the connection. 36 // connector to use to establish the connection.
36 ChildConnection(const std::string& name, 37 ChildConnection(const std::string& name,
37 const std::string& instance_id, 38 const std::string& instance_id,
38 const std::string& child_token, 39 mojo::edk::PendingProcessConnection* process_connection,
39 service_manager::Connector* connector, 40 service_manager::Connector* connector,
40 scoped_refptr<base::SequencedTaskRunner> io_task_runner); 41 scoped_refptr<base::SequencedTaskRunner> io_task_runner);
41 ~ChildConnection(); 42 ~ChildConnection();
42 43
43 service_manager::InterfaceProvider* GetRemoteInterfaces() { 44 service_manager::InterfaceProvider* GetRemoteInterfaces() {
44 return &remote_interfaces_; 45 return &remote_interfaces_;
45 } 46 }
46 47
47 const service_manager::Identity& child_identity() const { 48 const service_manager::Identity& child_identity() const {
48 return child_identity_; 49 return child_identity_;
49 } 50 }
50 51
51 // A token which must be passed to the child process via 52 // A token which must be passed to the child process via
52 // |switches::kPrimordialPipeToken| in order for the child to initialize its 53 // |switches::kPrimordialPipeToken| in order for the child to initialize its
53 // end of the Service Manager connection pipe. 54 // end of the Service Manager connection pipe.
54 std::string service_token() const { return service_token_; } 55 std::string service_token() const { return service_token_; }
55 56
56 // 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
57 // 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
58 // functional until this is called. 59 // functional until this is called.
59 void SetProcessHandle(base::ProcessHandle handle); 60 void SetProcessHandle(base::ProcessHandle handle);
60 61
61 private: 62 private:
62 class IOThreadContext; 63 class IOThreadContext;
63 64
64 const std::string child_token_;
65 scoped_refptr<IOThreadContext> context_; 65 scoped_refptr<IOThreadContext> context_;
66 service_manager::Identity child_identity_; 66 service_manager::Identity child_identity_;
67 const 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_; 70 service_manager::InterfaceProvider remote_interfaces_;
71 71
72 base::WeakPtrFactory<ChildConnection> weak_factory_; 72 base::WeakPtrFactory<ChildConnection> weak_factory_;
73 73
74 DISALLOW_COPY_AND_ASSIGN(ChildConnection); 74 DISALLOW_COPY_AND_ASSIGN(ChildConnection);
75 }; 75 };
76 76
77 } // namespace content 77 } // namespace content
78 78
79 #endif // CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_ 79 #endif // CONTENT_COMMON_SERVICE_MANAGER_CHILD_CONNECTION_H_
OLDNEW
« no previous file with comments | « content/common/child_process_host_impl.cc ('k') | content/common/service_manager/child_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698