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

Side by Side Diff: mojo/edk/embedder/embedder.cc

Issue 2620633004: Remove mojo::edk::test::ScopedIPCSupport (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « mojo/edk/embedder/embedder.h ('k') | mojo/edk/embedder/embedder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/embedder/embedder.h" 5 #include "mojo/edk/embedder/embedder.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/task_runner.h" 16 #include "base/task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "mojo/edk/embedder/embedder_internal.h" 18 #include "mojo/edk/embedder/embedder_internal.h"
19 #include "mojo/edk/embedder/entrypoints.h" 19 #include "mojo/edk/embedder/entrypoints.h"
20 #include "mojo/edk/embedder/platform_channel_pair.h" 20 #include "mojo/edk/embedder/platform_channel_pair.h"
21 #include "mojo/edk/embedder/process_delegate.h"
22 #include "mojo/edk/system/core.h" 21 #include "mojo/edk/system/core.h"
22 #include "mojo/edk/system/node_controller.h"
23 23
24 #if !defined(OS_NACL) 24 #if !defined(OS_NACL)
25 #include "crypto/random.h" 25 #include "crypto/random.h"
26 #endif 26 #endif
27 27
28 namespace mojo { 28 namespace mojo {
29 namespace edk { 29 namespace edk {
30 30
31 class Core; 31 class Core;
32 class PlatformSupport; 32 class PlatformSupport;
33 33
34 namespace internal { 34 namespace internal {
35 35
36 Core* g_core; 36 Core* g_core;
37 ProcessDelegate* g_process_delegate;
38 37
39 Core* GetCore() { return g_core; } 38 Core* GetCore() { return g_core; }
40 39
41 } // namespace internal 40 } // namespace internal
42 41
43 void SetMaxMessageSize(size_t bytes) { 42 void SetMaxMessageSize(size_t bytes) {
44 } 43 }
45 44
46 void ChildProcessLaunched(base::ProcessHandle child_process, 45 void ChildProcessLaunched(base::ProcessHandle child_process,
47 ScopedPlatformHandle server_pipe, 46 ScopedPlatformHandle server_pipe,
(...skipping 28 matching lines...) Expand all
76 CHECK(platform_channel.is_valid()); 75 CHECK(platform_channel.is_valid());
77 SetParentPipeHandle(std::move(platform_channel)); 76 SetParentPipeHandle(std::move(platform_channel));
78 } 77 }
79 78
80 ScopedMessagePipeHandle ConnectToPeerProcess(ScopedPlatformHandle pipe) { 79 ScopedMessagePipeHandle ConnectToPeerProcess(ScopedPlatformHandle pipe) {
81 return ConnectToPeerProcess(std::move(pipe), GenerateRandomToken()); 80 return ConnectToPeerProcess(std::move(pipe), GenerateRandomToken());
82 } 81 }
83 82
84 ScopedMessagePipeHandle ConnectToPeerProcess(ScopedPlatformHandle pipe, 83 ScopedMessagePipeHandle ConnectToPeerProcess(ScopedPlatformHandle pipe,
85 const std::string& peer_token) { 84 const std::string& peer_token) {
86 CHECK(internal::g_process_delegate);
87 DCHECK(pipe.is_valid()); 85 DCHECK(pipe.is_valid());
88 DCHECK(!peer_token.empty()); 86 DCHECK(!peer_token.empty());
89 return internal::g_core->ConnectToPeerProcess(std::move(pipe), peer_token); 87 return internal::g_core->ConnectToPeerProcess(std::move(pipe), peer_token);
90 } 88 }
91 89
92 void ClosePeerConnection(const std::string& peer_token) { 90 void ClosePeerConnection(const std::string& peer_token) {
93 CHECK(internal::g_process_delegate);
94 return internal::g_core->ClosePeerConnection(peer_token); 91 return internal::g_core->ClosePeerConnection(peer_token);
95 } 92 }
96 93
97 void Init() { 94 void Init() {
98 MojoSystemThunks thunks = MakeSystemThunks(); 95 MojoSystemThunks thunks = MakeSystemThunks();
99 size_t expected_size = MojoEmbedderSetSystemThunks(&thunks); 96 size_t expected_size = MojoEmbedderSetSystemThunks(&thunks);
100 DCHECK_EQ(expected_size, sizeof(thunks)); 97 DCHECK_EQ(expected_size, sizeof(thunks));
101 98
102 internal::g_core = new Core(); 99 internal::g_core = new Core();
103 } 100 }
(...skipping 26 matching lines...) Expand all
130 127
131 MojoResult PassSharedMemoryHandle( 128 MojoResult PassSharedMemoryHandle(
132 MojoHandle mojo_handle, 129 MojoHandle mojo_handle,
133 base::SharedMemoryHandle* shared_memory_handle, 130 base::SharedMemoryHandle* shared_memory_handle,
134 size_t* num_bytes, 131 size_t* num_bytes,
135 bool* read_only) { 132 bool* read_only) {
136 return internal::g_core->PassSharedMemoryHandle( 133 return internal::g_core->PassSharedMemoryHandle(
137 mojo_handle, shared_memory_handle, num_bytes, read_only); 134 mojo_handle, shared_memory_handle, num_bytes, read_only);
138 } 135 }
139 136
140 void InitIPCSupport(ProcessDelegate* process_delegate, 137 void InitIPCSupport(scoped_refptr<base::TaskRunner> io_thread_task_runner) {
141 scoped_refptr<base::TaskRunner> io_thread_task_runner) {
142 CHECK(internal::g_core); 138 CHECK(internal::g_core);
143 internal::g_core->SetIOTaskRunner(io_thread_task_runner); 139 internal::g_core->SetIOTaskRunner(io_thread_task_runner);
144 internal::g_process_delegate = process_delegate;
145 } 140 }
146 141
147 void ShutdownIPCSupport() { 142 scoped_refptr<base::TaskRunner> GetIOTaskRunner() {
148 CHECK(internal::g_process_delegate); 143 return internal::g_core->GetNodeController()->io_task_runner();
144 }
145
146 void ShutdownIPCSupport(const base::Closure& callback) {
149 CHECK(internal::g_core); 147 CHECK(internal::g_core);
150 internal::g_core->RequestShutdown( 148 internal::g_core->RequestShutdown(callback);
151 base::Bind(&ProcessDelegate::OnShutdownComplete,
152 base::Unretained(internal::g_process_delegate)));
153 } 149 }
154 150
155 #if defined(OS_MACOSX) && !defined(OS_IOS) 151 #if defined(OS_MACOSX) && !defined(OS_IOS)
156 void SetMachPortProvider(base::PortProvider* port_provider) { 152 void SetMachPortProvider(base::PortProvider* port_provider) {
157 DCHECK(port_provider); 153 DCHECK(port_provider);
158 internal::g_core->SetMachPortProvider(port_provider); 154 internal::g_core->SetMachPortProvider(port_provider);
159 } 155 }
160 #endif 156 #endif
161 157
162 ScopedMessagePipeHandle CreateMessagePipe( 158 ScopedMessagePipeHandle CreateMessagePipe(
163 ScopedPlatformHandle platform_handle) { 159 ScopedPlatformHandle platform_handle) {
164 CHECK(internal::g_process_delegate);
165 return internal::g_core->CreateMessagePipe(std::move(platform_handle)); 160 return internal::g_core->CreateMessagePipe(std::move(platform_handle));
166 } 161 }
167 162
168 ScopedMessagePipeHandle CreateParentMessagePipe( 163 ScopedMessagePipeHandle CreateParentMessagePipe(
169 const std::string& token, const std::string& child_token) { 164 const std::string& token, const std::string& child_token) {
170 CHECK(internal::g_process_delegate);
171 return internal::g_core->CreateParentMessagePipe(token, child_token); 165 return internal::g_core->CreateParentMessagePipe(token, child_token);
172 } 166 }
173 167
174 ScopedMessagePipeHandle CreateChildMessagePipe(const std::string& token) { 168 ScopedMessagePipeHandle CreateChildMessagePipe(const std::string& token) {
175 CHECK(internal::g_process_delegate);
176 return internal::g_core->CreateChildMessagePipe(token); 169 return internal::g_core->CreateChildMessagePipe(token);
177 } 170 }
178 171
179 std::string GenerateRandomToken() { 172 std::string GenerateRandomToken() {
180 char random_bytes[16]; 173 char random_bytes[16];
181 #if defined(OS_NACL) 174 #if defined(OS_NACL)
182 // Not secure. For NaCl only! 175 // Not secure. For NaCl only!
183 base::RandBytes(random_bytes, 16); 176 base::RandBytes(random_bytes, 16);
184 #else 177 #else
185 crypto::RandBytes(random_bytes, 16); 178 crypto::RandBytes(random_bytes, 16);
186 #endif 179 #endif
187 return base::HexEncode(random_bytes, 16); 180 return base::HexEncode(random_bytes, 16);
188 } 181 }
189 182
190 MojoResult SetProperty(MojoPropertyType type, const void* value) { 183 MojoResult SetProperty(MojoPropertyType type, const void* value) {
191 CHECK(internal::g_core); 184 CHECK(internal::g_core);
192 return internal::g_core->SetProperty(type, value); 185 return internal::g_core->SetProperty(type, value);
193 } 186 }
194 187
195 } // namespace edk 188 } // namespace edk
196 } // namespace mojo 189 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/embedder.h ('k') | mojo/edk/embedder/embedder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698