OLD | NEW |
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/browser/mojo/mojo_child_connection.h" | 5 #include "content/browser/mojo/mojo_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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "mojo/shell/public/interfaces/shell_client.mojom.h" | 24 #include "mojo/shell/public/interfaces/shell_client.mojom.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 namespace { | 27 namespace { |
28 | 28 |
29 const char kMojoRenderProcessHostConnection[] = | 29 const char kMojoRenderProcessHostConnection[] = |
30 "mojo_render_process_host_connection"; | 30 "mojo_render_process_host_connection"; |
31 | 31 |
32 class RenderProcessHostConnection : public base::SupportsUserData::Data { | 32 class RenderProcessHostConnection : public base::SupportsUserData::Data { |
33 public: | 33 public: |
34 explicit RenderProcessHostConnection(scoped_ptr<mojo::Connection> connection) | 34 explicit RenderProcessHostConnection( |
| 35 std::unique_ptr<mojo::Connection> connection) |
35 : connection_(std::move(connection)) {} | 36 : connection_(std::move(connection)) {} |
36 ~RenderProcessHostConnection() override {} | 37 ~RenderProcessHostConnection() override {} |
37 | 38 |
38 mojo::Connection* get() const { return connection_.get(); } | 39 mojo::Connection* get() const { return connection_.get(); } |
39 | 40 |
40 private: | 41 private: |
41 scoped_ptr<mojo::Connection> connection_; | 42 std::unique_ptr<mojo::Connection> connection_; |
42 | 43 |
43 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostConnection); | 44 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostConnection); |
44 }; | 45 }; |
45 | 46 |
46 void SetMojoConnection(RenderProcessHost* render_process_host, | 47 void SetMojoConnection(RenderProcessHost* render_process_host, |
47 scoped_ptr<mojo::Connection> connection) { | 48 std::unique_ptr<mojo::Connection> connection) { |
48 render_process_host->SetUserData( | 49 render_process_host->SetUserData( |
49 kMojoRenderProcessHostConnection, | 50 kMojoRenderProcessHostConnection, |
50 new RenderProcessHostConnection(std::move(connection))); | 51 new RenderProcessHostConnection(std::move(connection))); |
51 } | 52 } |
52 | 53 |
53 class PIDSender : public RenderProcessHostObserver { | 54 class PIDSender : public RenderProcessHostObserver { |
54 public: | 55 public: |
55 PIDSender( | 56 PIDSender( |
56 RenderProcessHost* host, | 57 RenderProcessHost* host, |
57 mojo::shell::mojom::PIDReceiverPtr pid_receiver) | 58 mojo::shell::mojom::PIDReceiverPtr pid_receiver) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // PIDSender manages its own lifetime. | 111 // PIDSender manages its own lifetime. |
111 new PIDSender(render_process_host, std::move(pid_receiver)); | 112 new PIDSender(render_process_host, std::move(pid_receiver)); |
112 | 113 |
113 mojo::Identity target(kRendererMojoApplicationName, | 114 mojo::Identity target(kRendererMojoApplicationName, |
114 mojo::shell::mojom::kInheritUserID, | 115 mojo::shell::mojom::kInheritUserID, |
115 base::StringPrintf("%d_%d", child_process_id, | 116 base::StringPrintf("%d_%d", child_process_id, |
116 instance_id)); | 117 instance_id)); |
117 mojo::Connector::ConnectParams params(target); | 118 mojo::Connector::ConnectParams params(target); |
118 params.set_client_process_connection(std::move(client), | 119 params.set_client_process_connection(std::move(client), |
119 std::move(pid_receiver_request)); | 120 std::move(pid_receiver_request)); |
120 scoped_ptr<mojo::Connection> connection = | 121 std::unique_ptr<mojo::Connection> connection = |
121 MojoShellConnection::Get()->GetConnector()->Connect(¶ms); | 122 MojoShellConnection::Get()->GetConnector()->Connect(¶ms); |
122 | 123 |
123 // Store the connection on the RPH so client code can access it later via | 124 // Store the connection on the RPH so client code can access it later via |
124 // GetMojoConnection(). | 125 // GetMojoConnection(). |
125 SetMojoConnection(render_process_host, std::move(connection)); | 126 SetMojoConnection(render_process_host, std::move(connection)); |
126 | 127 |
127 return pipe_token; | 128 return pipe_token; |
128 } | 129 } |
129 | 130 |
130 mojo::Connection* GetMojoConnection(RenderProcessHost* render_process_host) { | 131 mojo::Connection* GetMojoConnection(RenderProcessHost* render_process_host) { |
131 RenderProcessHostConnection* connection = | 132 RenderProcessHostConnection* connection = |
132 static_cast<RenderProcessHostConnection*>( | 133 static_cast<RenderProcessHostConnection*>( |
133 render_process_host->GetUserData(kMojoRenderProcessHostConnection)); | 134 render_process_host->GetUserData(kMojoRenderProcessHostConnection)); |
134 return connection ? connection->get() : nullptr; | 135 return connection ? connection->get() : nullptr; |
135 } | 136 } |
136 | 137 |
137 } // namespace content | 138 } // namespace content |
OLD | NEW |