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