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

Side by Side Diff: mojo/system/multiprocess_message_pipe_unittest.cc

Issue 137063010: Mojo: Move platform handle/channel stuff in system to embedder namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/embedder_unittest.cc ('k') | mojo/system/platform_channel_pair.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // TODO(vtl): Enable this on non-POSIX once we have a non-POSIX implementation. 5 // TODO(vtl): Enable this on non-POSIX once we have a non-POSIX implementation.
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 30 matching lines...) Expand all
41 void PostTask(const tracked_objects::Location& from_here, 41 void PostTask(const tracked_objects::Location& from_here,
42 const base::Closure& task) { 42 const base::Closure& task) {
43 task_runner()->PostTask(from_here, task); 43 task_runner()->PostTask(from_here, task);
44 } 44 }
45 45
46 void PostTaskAndWait(const tracked_objects::Location& from_here, 46 void PostTaskAndWait(const tracked_objects::Location& from_here,
47 const base::Closure& task) { 47 const base::Closure& task) {
48 test::PostTaskAndWait(task_runner(), from_here, task); 48 test::PostTaskAndWait(task_runner(), from_here, task);
49 } 49 }
50 50
51 void Init(ScopedPlatformHandle platform_handle, 51 void Init(embedder::ScopedPlatformHandle platform_handle,
52 scoped_refptr<MessagePipe> mp) { 52 scoped_refptr<MessagePipe> mp) {
53 io_thread_.StartWithOptions( 53 io_thread_.StartWithOptions(
54 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 54 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
55 PostTask(FROM_HERE, 55 PostTask(FROM_HERE,
56 base::Bind(&IOThreadWrapper::InitOnIOThread, 56 base::Bind(&IOThreadWrapper::InitOnIOThread,
57 base::Unretained(this), 57 base::Unretained(this),
58 base::Passed(&platform_handle), mp)); 58 base::Passed(&platform_handle), mp));
59 } 59 }
60 60
61 void Shutdown() { 61 void Shutdown() {
62 PostTaskAndWait(FROM_HERE, 62 PostTaskAndWait(FROM_HERE,
63 base::Bind(&IOThreadWrapper::ShutdownOnIOThread, 63 base::Bind(&IOThreadWrapper::ShutdownOnIOThread,
64 base::Unretained(this))); 64 base::Unretained(this)));
65 io_thread_.Stop(); 65 io_thread_.Stop();
66 } 66 }
67 67
68 bool is_initialized() const { return !!channel_.get(); } 68 bool is_initialized() const { return !!channel_.get(); }
69 69
70 base::MessageLoop* message_loop() { 70 base::MessageLoop* message_loop() {
71 return io_thread_.message_loop(); 71 return io_thread_.message_loop();
72 } 72 }
73 73
74 scoped_refptr<base::TaskRunner> task_runner() { 74 scoped_refptr<base::TaskRunner> task_runner() {
75 return message_loop()->message_loop_proxy(); 75 return message_loop()->message_loop_proxy();
76 } 76 }
77 77
78 private: 78 private:
79 void InitOnIOThread(ScopedPlatformHandle platform_handle, 79 void InitOnIOThread(embedder::ScopedPlatformHandle platform_handle,
80 scoped_refptr<MessagePipe> mp) { 80 scoped_refptr<MessagePipe> mp) {
81 CHECK_EQ(base::MessageLoop::current(), message_loop()); 81 CHECK_EQ(base::MessageLoop::current(), message_loop());
82 CHECK(platform_handle.is_valid()); 82 CHECK(platform_handle.is_valid());
83 83
84 // Create and initialize |Channel|. 84 // Create and initialize |Channel|.
85 channel_ = new Channel(); 85 channel_ = new Channel();
86 CHECK(channel_->Init(platform_handle.Pass())); 86 CHECK(channel_->Init(platform_handle.Pass()));
87 87
88 // Attach the message pipe endpoint. 88 // Attach the message pipe endpoint.
89 // Note: On the "server" (parent process) side, we need not attach the 89 // Note: On the "server" (parent process) side, we need not attach the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 mp->RemoveWaiter(0, &waiter); 145 mp->RemoveWaiter(0, &waiter);
146 return wait_result; 146 return wait_result;
147 } 147 }
148 148
149 // For each message received, sends a reply message with the same contents 149 // For each message received, sends a reply message with the same contents
150 // repeated twice, until the other end is closed or it receives "quitquitquit" 150 // repeated twice, until the other end is closed or it receives "quitquitquit"
151 // (which it doesn't reply to). It'll return the number of messages received, 151 // (which it doesn't reply to). It'll return the number of messages received,
152 // not including any "quitquitquit" message, modulo 100. 152 // not including any "quitquitquit" message, modulo 100.
153 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) { 153 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
154 IOThreadWrapper io_thread_wrapper; 154 IOThreadWrapper io_thread_wrapper;
155 ScopedPlatformHandle client_platform_handle = 155 embedder::ScopedPlatformHandle client_platform_handle =
156 MultiprocessMessagePipeTest::client_platform_handle.Pass(); 156 MultiprocessMessagePipeTest::client_platform_handle.Pass();
157 CHECK(client_platform_handle.is_valid()); 157 CHECK(client_platform_handle.is_valid());
158 scoped_refptr<MessagePipe> mp(new MessagePipe( 158 scoped_refptr<MessagePipe> mp(new MessagePipe(
159 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 159 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
160 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 160 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
161 io_thread_wrapper.Init(client_platform_handle.Pass(), mp); 161 io_thread_wrapper.Init(client_platform_handle.Pass(), mp);
162 162
163 const std::string quitquitquit("quitquitquit"); 163 const std::string quitquitquit("quitquitquit");
164 int rv = 0; 164 int rv = 0;
165 for (;; rv = (rv + 1) % 100) { 165 for (;; rv = (rv + 1) % 100) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 mp->Close(0); 288 mp->Close(0);
289 289
290 EXPECT_EQ(static_cast<int>(kNumMessages % 100), WaitForChildShutdown()); 290 EXPECT_EQ(static_cast<int>(kNumMessages % 100), WaitForChildShutdown());
291 } 291 }
292 292
293 } // namespace 293 } // namespace
294 } // namespace system 294 } // namespace system
295 } // namespace mojo 295 } // namespace mojo
296 296
297 #endif // defined(OS_POSIX) 297 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « mojo/system/embedder_unittest.cc ('k') | mojo/system/platform_channel_pair.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698