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

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

Issue 2420253002: Rename shell namespace to service_manager (Closed)
Patch Set: . Created 4 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "content/common/service_manager/child_connection.h" 5 #include "content/common/service_manager/child_connection.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "content/public/common/service_manager_connection.h" 11 #include "content/public/common/service_manager_connection.h"
12 #include "mojo/edk/embedder/embedder.h" 12 #include "mojo/edk/embedder/embedder.h"
13 #include "mojo/public/cpp/system/message_pipe.h" 13 #include "mojo/public/cpp/system/message_pipe.h"
14 #include "services/service_manager/public/cpp/connector.h" 14 #include "services/service_manager/public/cpp/connector.h"
15 #include "services/service_manager/public/cpp/identity.h" 15 #include "services/service_manager/public/cpp/identity.h"
16 #include "services/service_manager/public/cpp/interface_registry.h" 16 #include "services/service_manager/public/cpp/interface_registry.h"
17 #include "services/service_manager/public/interfaces/service.mojom.h" 17 #include "services/service_manager/public/interfaces/service.mojom.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 namespace { 21 namespace {
22 22
23 void CallBinderOnTaskRunner( 23 void CallBinderOnTaskRunner(
24 const shell::InterfaceRegistry::Binder& binder, 24 const service_manager::InterfaceRegistry::Binder& binder,
25 scoped_refptr<base::SequencedTaskRunner> task_runner, 25 scoped_refptr<base::SequencedTaskRunner> task_runner,
26 const std::string& interface_name, 26 const std::string& interface_name,
27 mojo::ScopedMessagePipeHandle request_handle) { 27 mojo::ScopedMessagePipeHandle request_handle) {
28 task_runner->PostTask( 28 task_runner->PostTask(
29 FROM_HERE, 29 FROM_HERE,
30 base::Bind(binder, interface_name, base::Passed(&request_handle))); 30 base::Bind(binder, interface_name, base::Passed(&request_handle)));
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 class ChildConnection::IOThreadContext 35 class ChildConnection::IOThreadContext
36 : public base::RefCountedThreadSafe<IOThreadContext> { 36 : public base::RefCountedThreadSafe<IOThreadContext> {
37 public: 37 public:
38 IOThreadContext() {} 38 IOThreadContext() {}
39 39
40 void Initialize(const shell::Identity& child_identity, 40 void Initialize(const service_manager::Identity& child_identity,
41 shell::Connector* connector, 41 service_manager::Connector* connector,
42 mojo::ScopedMessagePipeHandle service_pipe, 42 mojo::ScopedMessagePipeHandle service_pipe,
43 scoped_refptr<base::SequencedTaskRunner> io_task_runner) { 43 scoped_refptr<base::SequencedTaskRunner> io_task_runner) {
44 DCHECK(!io_task_runner_); 44 DCHECK(!io_task_runner_);
45 io_task_runner_ = io_task_runner; 45 io_task_runner_ = io_task_runner;
46 std::unique_ptr<shell::Connector> io_thread_connector; 46 std::unique_ptr<service_manager::Connector> io_thread_connector;
47 if (connector) 47 if (connector)
48 io_thread_connector = connector->Clone(); 48 io_thread_connector = connector->Clone();
49 io_task_runner_->PostTask( 49 io_task_runner_->PostTask(
50 FROM_HERE, 50 FROM_HERE,
51 base::Bind(&IOThreadContext::InitializeOnIOThread, this, 51 base::Bind(&IOThreadContext::InitializeOnIOThread, this,
52 child_identity, 52 child_identity,
53 base::Passed(&io_thread_connector), 53 base::Passed(&io_thread_connector),
54 base::Passed(&service_pipe))); 54 base::Passed(&service_pipe)));
55 } 55 }
56 56
(...skipping 21 matching lines...) Expand all
78 FROM_HERE, 78 FROM_HERE,
79 base::Bind(&IOThreadContext::SetProcessHandleOnIOThread, this, handle)); 79 base::Bind(&IOThreadContext::SetProcessHandleOnIOThread, this, handle));
80 } 80 }
81 81
82 private: 82 private:
83 friend class base::RefCountedThreadSafe<IOThreadContext>; 83 friend class base::RefCountedThreadSafe<IOThreadContext>;
84 84
85 virtual ~IOThreadContext() {} 85 virtual ~IOThreadContext() {}
86 86
87 void InitializeOnIOThread( 87 void InitializeOnIOThread(
88 const shell::Identity& child_identity, 88 const service_manager::Identity& child_identity,
89 std::unique_ptr<shell::Connector> connector, 89 std::unique_ptr<service_manager::Connector> connector,
90 mojo::ScopedMessagePipeHandle service_pipe) { 90 mojo::ScopedMessagePipeHandle service_pipe) {
91 shell::mojom::ServicePtr service; 91 service_manager::mojom::ServicePtr service;
92 service.Bind(mojo::InterfacePtrInfo<shell::mojom::Service>( 92 service.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>(
93 std::move(service_pipe), 0u)); 93 std::move(service_pipe), 0u));
94 shell::mojom::PIDReceiverRequest pid_receiver_request = 94 service_manager::mojom::PIDReceiverRequest pid_receiver_request =
95 mojo::GetProxy(&pid_receiver_); 95 mojo::GetProxy(&pid_receiver_);
96 96
97 shell::Connector::ConnectParams params(child_identity); 97 service_manager::Connector::ConnectParams params(child_identity);
98 params.set_client_process_connection(std::move(service), 98 params.set_client_process_connection(std::move(service),
99 std::move(pid_receiver_request)); 99 std::move(pid_receiver_request));
100 100
101 // In some unit testing scenarios a null connector is passed. 101 // In some unit testing scenarios a null connector is passed.
102 if (connector) 102 if (connector)
103 connection_ = connector->Connect(&params); 103 connection_ = connector->Connect(&params);
104 } 104 }
105 105
106 void ShutDownOnIOThread() { 106 void ShutDownOnIOThread() {
107 connection_.reset(); 107 connection_.reset();
108 pid_receiver_.reset(); 108 pid_receiver_.reset();
109 } 109 }
110 110
111 void SetProcessHandleOnIOThread(base::ProcessHandle handle) { 111 void SetProcessHandleOnIOThread(base::ProcessHandle handle) {
112 DCHECK(pid_receiver_.is_bound()); 112 DCHECK(pid_receiver_.is_bound());
113 pid_receiver_->SetPID(base::GetProcId(handle)); 113 pid_receiver_->SetPID(base::GetProcId(handle));
114 pid_receiver_.reset(); 114 pid_receiver_.reset();
115 } 115 }
116 116
117 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 117 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
118 std::unique_ptr<shell::Connection> connection_; 118 std::unique_ptr<service_manager::Connection> connection_;
119 shell::mojom::PIDReceiverPtr pid_receiver_; 119 service_manager::mojom::PIDReceiverPtr pid_receiver_;
120 120
121 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); 121 DISALLOW_COPY_AND_ASSIGN(IOThreadContext);
122 }; 122 };
123 123
124 ChildConnection::ChildConnection( 124 ChildConnection::ChildConnection(
125 const std::string& service_name, 125 const std::string& service_name,
126 const std::string& instance_id, 126 const std::string& instance_id,
127 const std::string& child_token, 127 const std::string& child_token,
128 shell::Connector* connector, 128 service_manager::Connector* connector,
129 scoped_refptr<base::SequencedTaskRunner> io_task_runner) 129 scoped_refptr<base::SequencedTaskRunner> io_task_runner)
130 : context_(new IOThreadContext), 130 : context_(new IOThreadContext),
131 child_identity_(service_name, shell::mojom::kInheritUserID, instance_id), 131 child_identity_(service_name,
132 service_manager::mojom::kInheritUserID,
133 instance_id),
132 service_token_(mojo::edk::GenerateRandomToken()), 134 service_token_(mojo::edk::GenerateRandomToken()),
133 weak_factory_(this) { 135 weak_factory_(this) {
134 mojo::ScopedMessagePipeHandle service_pipe = 136 mojo::ScopedMessagePipeHandle service_pipe =
135 mojo::edk::CreateParentMessagePipe(service_token_, child_token); 137 mojo::edk::CreateParentMessagePipe(service_token_, child_token);
136 138
137 context_->Initialize(child_identity_, connector, std::move(service_pipe), 139 context_->Initialize(child_identity_, connector, std::move(service_pipe),
138 io_task_runner); 140 io_task_runner);
139 remote_interfaces_.Forward( 141 remote_interfaces_.Forward(
140 base::Bind(&CallBinderOnTaskRunner, 142 base::Bind(&CallBinderOnTaskRunner,
141 base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread, 143 base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread,
142 context_), io_task_runner)); 144 context_), io_task_runner));
143 } 145 }
144 146
145 ChildConnection::~ChildConnection() { 147 ChildConnection::~ChildConnection() {
146 context_->ShutDown(); 148 context_->ShutDown();
147 } 149 }
148 150
149 void ChildConnection::SetProcessHandle(base::ProcessHandle handle) { 151 void ChildConnection::SetProcessHandle(base::ProcessHandle handle) {
150 context_->SetProcessHandle(handle); 152 context_->SetProcessHandle(handle);
151 } 153 }
152 154
153 } // namespace content 155 } // namespace content
OLDNEW
« no previous file with comments | « content/common/service_manager/child_connection.h ('k') | content/common/service_manager/embedded_service_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698