OLD | NEW |
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 "ipc/mojo/ipc_channel_mojo.h" | 5 #include "ipc/mojo/ipc_channel_mojo.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 ASSERT_TRUE(sender->Send(message)); | 59 ASSERT_TRUE(sender->Send(message)); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 bool received_ok_; | 63 bool received_ok_; |
64 }; | 64 }; |
65 | 65 |
66 class ChannelClient { | 66 class ChannelClient { |
67 public: | 67 public: |
68 explicit ChannelClient(IPC::Listener* listener, const char* name) { | 68 explicit ChannelClient(IPC::Listener* listener, const char* name) { |
69 ipc_support_.reset( | 69 channel_ = IPC::ChannelMojo::Create(NULL, main_message_loop_.task_runner(), |
70 new IPC::ScopedIPCSupport(main_message_loop_.task_runner())); | |
71 channel_ = IPC::ChannelMojo::Create(NULL, | |
72 IPCTestBase::GetChannelName(name), | 70 IPCTestBase::GetChannelName(name), |
73 IPC::Channel::MODE_CLIENT, | 71 IPC::Channel::MODE_CLIENT, listener); |
74 listener); | |
75 } | 72 } |
76 | 73 |
77 void Connect() { | 74 void Connect() { |
78 CHECK(channel_->Connect()); | 75 CHECK(channel_->Connect()); |
79 } | 76 } |
80 | 77 |
81 void Close() { | 78 void Close() { |
82 channel_->Close(); | 79 channel_->Close(); |
83 | 80 |
84 base::RunLoop run_loop; | 81 base::RunLoop run_loop; |
85 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); | 82 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
86 run_loop.Run(); | 83 run_loop.Run(); |
87 } | 84 } |
88 | 85 |
89 IPC::ChannelMojo* channel() const { return channel_.get(); } | 86 IPC::ChannelMojo* channel() const { return channel_.get(); } |
90 | 87 |
91 private: | 88 private: |
92 base::MessageLoopForIO main_message_loop_; | 89 base::MessageLoopForIO main_message_loop_; |
93 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_; | |
94 scoped_ptr<IPC::ChannelMojo> channel_; | 90 scoped_ptr<IPC::ChannelMojo> channel_; |
95 }; | 91 }; |
96 | 92 |
97 class IPCChannelMojoTestBase : public IPCTestBase { | 93 class IPCChannelMojoTestBase : public IPCTestBase { |
98 public: | 94 public: |
99 void InitWithMojo(const std::string& test_client_name) { | 95 void InitWithMojo(const std::string& test_client_name) { |
100 Init(test_client_name); | 96 Init(test_client_name); |
101 ipc_support_.reset(new IPC::ScopedIPCSupport(task_runner())); | |
102 } | 97 } |
103 | 98 |
104 void TearDown() override { | 99 void TearDown() override { |
105 // Make sure Mojo IPC support is properly shutdown on the I/O loop before | 100 // Make sure Mojo IPC support is properly shutdown on the I/O loop before |
106 // TearDown continues. | 101 // TearDown continues. |
107 ipc_support_.reset(); | |
108 base::RunLoop run_loop; | 102 base::RunLoop run_loop; |
109 task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); | 103 task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
110 run_loop.Run(); | 104 run_loop.Run(); |
111 | 105 |
112 IPCTestBase::TearDown(); | 106 IPCTestBase::TearDown(); |
113 } | 107 } |
114 | |
115 private: | |
116 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_; | |
117 }; | 108 }; |
118 | 109 |
119 class IPCChannelMojoTest : public IPCChannelMojoTestBase { | 110 class IPCChannelMojoTest : public IPCChannelMojoTestBase { |
120 protected: | 111 protected: |
121 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( | 112 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( |
122 const IPC::ChannelHandle& handle, | 113 const IPC::ChannelHandle& handle, |
123 base::SequencedTaskRunner* runner) override { | 114 base::SequencedTaskRunner* runner) override { |
124 host_.reset(new IPC::ChannelMojoHost(task_runner())); | 115 host_.reset(new IPC::ChannelMojoHost(task_runner())); |
125 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), | 116 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), |
126 handle); | 117 task_runner(), handle); |
127 } | 118 } |
128 | 119 |
129 bool DidStartClient() override { | 120 bool DidStartClient() override { |
130 bool ok = IPCTestBase::DidStartClient(); | 121 bool ok = IPCTestBase::DidStartClient(); |
131 DCHECK(ok); | 122 DCHECK(ok); |
132 host_->OnClientLaunched(client_process().Handle()); | 123 host_->OnClientLaunched(client_process().Handle()); |
133 return ok; | 124 return ok; |
134 } | 125 } |
135 | 126 |
136 private: | 127 private: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 }; | 215 }; |
225 | 216 |
226 | 217 |
227 class IPCChannelMojoErrorTest : public IPCChannelMojoTestBase { | 218 class IPCChannelMojoErrorTest : public IPCChannelMojoTestBase { |
228 protected: | 219 protected: |
229 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( | 220 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( |
230 const IPC::ChannelHandle& handle, | 221 const IPC::ChannelHandle& handle, |
231 base::SequencedTaskRunner* runner) override { | 222 base::SequencedTaskRunner* runner) override { |
232 host_.reset(new IPC::ChannelMojoHost(task_runner())); | 223 host_.reset(new IPC::ChannelMojoHost(task_runner())); |
233 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), | 224 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), |
234 handle); | 225 task_runner(), handle); |
235 } | 226 } |
236 | 227 |
237 bool DidStartClient() override { | 228 bool DidStartClient() override { |
238 bool ok = IPCTestBase::DidStartClient(); | 229 bool ok = IPCTestBase::DidStartClient(); |
239 DCHECK(ok); | 230 DCHECK(ok); |
240 host_->OnClientLaunched(client_process().Handle()); | 231 host_->OnClientLaunched(client_process().Handle()); |
241 return ok; | 232 return ok; |
242 } | 233 } |
243 | 234 |
244 private: | 235 private: |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 } | 549 } |
559 | 550 |
560 #if defined(OS_WIN) | 551 #if defined(OS_WIN) |
561 class IPCChannelMojoDeadHandleTest : public IPCChannelMojoTestBase { | 552 class IPCChannelMojoDeadHandleTest : public IPCChannelMojoTestBase { |
562 protected: | 553 protected: |
563 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( | 554 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( |
564 const IPC::ChannelHandle& handle, | 555 const IPC::ChannelHandle& handle, |
565 base::SequencedTaskRunner* runner) override { | 556 base::SequencedTaskRunner* runner) override { |
566 host_.reset(new IPC::ChannelMojoHost(task_runner())); | 557 host_.reset(new IPC::ChannelMojoHost(task_runner())); |
567 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), | 558 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), |
568 handle); | 559 task_runner(), handle); |
569 } | 560 } |
570 | 561 |
571 virtual bool DidStartClient() override { | 562 virtual bool DidStartClient() override { |
572 IPCTestBase::DidStartClient(); | 563 IPCTestBase::DidStartClient(); |
573 const base::ProcessHandle client = client_process().Handle(); | 564 const base::ProcessHandle client = client_process().Handle(); |
574 // Forces GetFileHandleForProcess() fail. It happens occasionally | 565 // Forces GetFileHandleForProcess() fail. It happens occasionally |
575 // in production, so we should exercise it somehow. | 566 // in production, so we should exercise it somehow. |
576 // TODO(morrita): figure out how to safely test this. See crbug.com/464109. | 567 // TODO(morrita): figure out how to safely test this. See crbug.com/464109. |
577 // ::CloseHandle(client); | 568 // ::CloseHandle(client); |
578 host_->OnClientLaunched(client); | 569 host_->OnClientLaunched(client); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 base::MessageLoop::current()->Run(); | 774 base::MessageLoop::current()->Run(); |
784 | 775 |
785 client.Close(); | 776 client.Close(); |
786 | 777 |
787 return 0; | 778 return 0; |
788 } | 779 } |
789 | 780 |
790 #endif // OS_LINUX | 781 #endif // OS_LINUX |
791 | 782 |
792 } // namespace | 783 } // namespace |
OLD | NEW |