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

Side by Side Diff: ipc/ipc_test_base.cc

Issue 553283002: IPC::ChannelMojo: Introduce IPC::MojoBootstrap for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build error Created 6 years, 3 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 | « ipc/ipc_test_base.h ('k') | ipc/mojo/BUILD.gn » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "ipc/ipc_test_base.h" 7 #include "ipc/ipc_test_base.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 scoped_ptr<base::MessageLoop> message_loop) { 45 scoped_ptr<base::MessageLoop> message_loop) {
46 DCHECK(!test_client_name.empty()); 46 DCHECK(!test_client_name.empty());
47 DCHECK(test_client_name_.empty()); 47 DCHECK(test_client_name_.empty());
48 DCHECK(!message_loop_); 48 DCHECK(!message_loop_);
49 49
50 test_client_name_ = test_client_name; 50 test_client_name_ = test_client_name;
51 message_loop_ = message_loop.Pass(); 51 message_loop_ = message_loop.Pass();
52 } 52 }
53 53
54 void IPCTestBase::CreateChannel(IPC::Listener* listener) { 54 void IPCTestBase::CreateChannel(IPC::Listener* listener) {
55 CreateChannelFromChannelHandle( 55 CreateChannelFromChannelHandle(GetTestChannelHandle(), listener);
56 GetChannelName(test_client_name_), listener);
57 } 56 }
58 57
59 bool IPCTestBase::ConnectChannel() { 58 bool IPCTestBase::ConnectChannel() {
60 CHECK(channel_.get()); 59 CHECK(channel_.get());
61 return channel_->Connect(); 60 return channel_->Connect();
62 } 61 }
63 62
64 scoped_ptr<IPC::Channel> IPCTestBase::ReleaseChannel() { 63 scoped_ptr<IPC::Channel> IPCTestBase::ReleaseChannel() {
65 return channel_.Pass(); 64 return channel_.Pass();
66 } 65 }
(...skipping 16 matching lines...) Expand all
83 channel_ = CreateChannelFactory( 82 channel_ = CreateChannelFactory(
84 channel_handle, task_runner().get())->BuildChannel(listener); 83 channel_handle, task_runner().get())->BuildChannel(listener);
85 } 84 }
86 85
87 void IPCTestBase::CreateChannelProxy( 86 void IPCTestBase::CreateChannelProxy(
88 IPC::Listener* listener, 87 IPC::Listener* listener,
89 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) { 88 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner) {
90 CHECK(!channel_.get()); 89 CHECK(!channel_.get());
91 CHECK(!channel_proxy_.get()); 90 CHECK(!channel_proxy_.get());
92 channel_proxy_ = IPC::ChannelProxy::Create( 91 channel_proxy_ = IPC::ChannelProxy::Create(
93 CreateChannelFactory(GetChannelName(test_client_name_), 92 CreateChannelFactory(GetTestChannelHandle(), ipc_task_runner.get()),
94 ipc_task_runner.get()),
95 listener, 93 listener,
96 ipc_task_runner); 94 ipc_task_runner);
97 } 95 }
98 96
99 void IPCTestBase::DestroyChannelProxy() { 97 void IPCTestBase::DestroyChannelProxy() {
100 CHECK(channel_proxy_.get()); 98 CHECK(channel_proxy_.get());
101 channel_proxy_.reset(); 99 channel_proxy_.reset();
102 } 100 }
103 101
102 std::string IPCTestBase::GetTestMainName() const {
103 return test_client_name_ + "TestClientMain";
104 }
105
106 bool IPCTestBase::DidStartClient() {
107 DCHECK_NE(base::kNullProcessHandle, client_process_);
108 return client_process_ != base::kNullProcessHandle;
109 }
110
111 #if defined(OS_POSIX)
112
104 bool IPCTestBase::StartClient() { 113 bool IPCTestBase::StartClient() {
105 DCHECK(client_process_ == base::kNullProcessHandle); 114 return StartClientWithFD(channel_
115 ? channel_->GetClientFileDescriptor()
116 : channel_proxy_->GetClientFileDescriptor());
117 }
106 118
107 std::string test_main = test_client_name_ + "TestClientMain"; 119 bool IPCTestBase::StartClientWithFD(int ipcfd) {
120 DCHECK_EQ(client_process_, base::kNullProcessHandle);
108 121
109 #if defined(OS_WIN)
110 client_process_ = SpawnChild(test_main);
111 #elif defined(OS_POSIX)
112 base::FileHandleMappingVector fds_to_map; 122 base::FileHandleMappingVector fds_to_map;
113 const int ipcfd = channel_.get()
114 ? channel_->GetClientFileDescriptor()
115 : channel_proxy_->GetClientFileDescriptor();
116 if (ipcfd > -1) 123 if (ipcfd > -1)
117 fds_to_map.push_back(std::pair<int, int>(ipcfd, 124 fds_to_map.push_back(std::pair<int, int>(ipcfd,
118 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); 125 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
119 base::LaunchOptions options; 126 base::LaunchOptions options;
120 options.fds_to_remap = &fds_to_map; 127 options.fds_to_remap = &fds_to_map;
121 client_process_ = SpawnChildWithOptions(test_main, options); 128 client_process_ = SpawnChildWithOptions(GetTestMainName(), options);
129
130 return DidStartClient();
131 }
132
133 #elif defined(OS_WIN)
134
135 bool IPCTestBase::StartClient() {
136 DCHECK_EQ(client_process_, base::kNullProcessHandle);
137 client_process_ = SpawnChild(GetTestMainName());
138 return DidStartClient();
139 }
140
122 #endif 141 #endif
123 142
124 return client_process_ != base::kNullProcessHandle;
125 }
126
127 bool IPCTestBase::WaitForClientShutdown() { 143 bool IPCTestBase::WaitForClientShutdown() {
128 DCHECK(client_process_ != base::kNullProcessHandle); 144 DCHECK(client_process_ != base::kNullProcessHandle);
129 145
130 bool rv = base::WaitForSingleProcess(client_process_, 146 bool rv = base::WaitForSingleProcess(client_process_,
131 base::TimeDelta::FromSeconds(5)); 147 base::TimeDelta::FromSeconds(5));
132 base::CloseProcessHandle(client_process_); 148 base::CloseProcessHandle(client_process_);
133 client_process_ = base::kNullProcessHandle; 149 client_process_ = base::kNullProcessHandle;
134 return rv; 150 return rv;
135 } 151 }
136 152
153 IPC::ChannelHandle IPCTestBase::GetTestChannelHandle() {
154 return GetChannelName(test_client_name_);
155 }
156
137 scoped_refptr<base::TaskRunner> IPCTestBase::task_runner() { 157 scoped_refptr<base::TaskRunner> IPCTestBase::task_runner() {
138 return message_loop_->message_loop_proxy(); 158 return message_loop_->message_loop_proxy();
139 } 159 }
140 160
141 scoped_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory( 161 scoped_ptr<IPC::ChannelFactory> IPCTestBase::CreateChannelFactory(
142 const IPC::ChannelHandle& handle, 162 const IPC::ChannelHandle& handle,
143 base::TaskRunner* runner) { 163 base::TaskRunner* runner) {
144 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER); 164 return IPC::ChannelFactory::Create(handle, IPC::Channel::MODE_SERVER);
145 } 165 }
OLDNEW
« no previous file with comments | « ipc/ipc_test_base.h ('k') | ipc/mojo/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698