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

Side by Side Diff: ipc/attachment_broker_privileged_win_unittest.cc

Issue 1292263003: ipc: Use a global for the process's attachment broker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_message2
Patch Set: Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <windows.h> 7 #include <windows.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 IPCTestBase::SetUp(); 213 IPCTestBase::SetUp();
214 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 214 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
215 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path_)); 215 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path_));
216 } 216 }
217 217
218 void TearDown() override { IPCTestBase::TearDown(); } 218 void TearDown() override { IPCTestBase::TearDown(); }
219 219
220 // Takes ownership of |broker|. Has no effect if called after CommonSetUp(). 220 // Takes ownership of |broker|. Has no effect if called after CommonSetUp().
221 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) { 221 void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) {
222 broker_.reset(broker); 222 broker_.reset(broker);
223 IPC::AttachmentBroker::SetGlobal(broker);
223 } 224 }
224 225
225 void CommonSetUp() { 226 void CommonSetUp() {
226 if (!broker_.get()) 227 if (!broker_.get())
227 set_broker(new IPC::AttachmentBrokerUnprivilegedWin); 228 set_broker(new IPC::AttachmentBrokerUnprivilegedWin);
228 broker_->AddObserver(&observer_); 229 broker_->AddObserver(&observer_);
229 set_attachment_broker(broker_.get()); 230 set_attachment_broker(broker_.get());
230 CreateChannel(&proxy_listener_); 231 CreateChannel(&proxy_listener_);
231 broker_->DesignateBrokerCommunicationChannel(channel()); 232 broker_->DesignateBrokerCommunicationChannel(channel());
232 ASSERT_TRUE(ConnectChannel()); 233 ASSERT_TRUE(ConnectChannel());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 const IPC::Message& message); 418 const IPC::Message& message);
418 419
419 int CommonPrivilegedProcessMain(OnMessageReceivedCallback callback, 420 int CommonPrivilegedProcessMain(OnMessageReceivedCallback callback,
420 const char* channel_name) { 421 const char* channel_name) {
421 LOG(INFO) << "Privileged process start."; 422 LOG(INFO) << "Privileged process start.";
422 base::MessageLoopForIO main_message_loop; 423 base::MessageLoopForIO main_message_loop;
423 ProxyListener listener; 424 ProxyListener listener;
424 425
425 // Set up IPC channel. 426 // Set up IPC channel.
426 IPC::AttachmentBrokerPrivilegedWin broker; 427 IPC::AttachmentBrokerPrivilegedWin broker;
428 IPC::AttachmentBroker::SetGlobal(&broker);
Tom Sepez 2015/09/11 15:58:30 This goes out of scope while the process is still
erikchen 2015/09/11 20:16:02 I updated the comment to say: """ Each process has
427 scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( 429 scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient(
428 IPCTestBase::GetChannelName(channel_name), &listener, &broker)); 430 IPCTestBase::GetChannelName(channel_name), &listener, &broker));
429 broker.RegisterCommunicationChannel(channel.get()); 431 broker.RegisterCommunicationChannel(channel.get());
430 CHECK(channel->Connect()); 432 CHECK(channel->Connect());
431 433
432 while (true) { 434 while (true) {
433 LOG(INFO) << "Privileged process spinning run loop."; 435 LOG(INFO) << "Privileged process spinning run loop.";
434 base::MessageLoop::current()->Run(); 436 base::MessageLoop::current()->Run();
435 ProxyListener::Reason reason = listener.get_reason(); 437 ProxyListener::Reason reason = listener.get_reason();
436 if (reason == ProxyListener::CHANNEL_ERROR) 438 if (reason == ProxyListener::CHANNEL_ERROR)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 SendControlMessage(sender, success); 553 SendControlMessage(sender, success);
552 } 554 }
553 } 555 }
554 556
555 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendHandleTwice) { 557 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SendHandleTwice) {
556 return CommonPrivilegedProcessMain(&SendHandleTwiceCallback, 558 return CommonPrivilegedProcessMain(&SendHandleTwiceCallback,
557 "SendHandleTwice"); 559 "SendHandleTwice");
558 } 560 }
559 561
560 } // namespace 562 } // namespace
OLDNEW
« ipc/attachment_broker.h ('K') | « ipc/attachment_broker.cc ('k') | ipc/ipc_channel_nacl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698