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

Side by Side Diff: ipc/ipc_channel_win.cc

Issue 1188923003: Stub in more IPC attachment brokering functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change the wireformat to use int32_t for HANDLE. Created 5 years, 6 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 (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 "ipc/ipc_channel_win.h" 5 #include "ipc/ipc_channel_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/pickle.h" 13 #include "base/pickle.h"
14 #include "base/process/process_handle.h" 14 #include "base/process/process_handle.h"
15 #include "base/rand_util.h" 15 #include "base/rand_util.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
19 #include "base/win/scoped_handle.h" 19 #include "base/win/scoped_handle.h"
20 #include "ipc/ipc_listener.h" 20 #include "ipc/ipc_listener.h"
21 #include "ipc/ipc_logging.h" 21 #include "ipc/ipc_logging.h"
22 #include "ipc/ipc_message_attachment_set.h"
22 #include "ipc/ipc_message_utils.h" 23 #include "ipc/ipc_message_utils.h"
23 24
24 namespace IPC { 25 namespace IPC {
25 26
26 ChannelWin::State::State(ChannelWin* channel) : is_pending(false) { 27 ChannelWin::State::State(ChannelWin* channel) : is_pending(false) {
27 memset(&context.overlapped, 0, sizeof(context.overlapped)); 28 memset(&context.overlapped, 0, sizeof(context.overlapped));
28 context.handler = channel; 29 context.handler = channel;
29 } 30 }
30 31
31 ChannelWin::State::~State() { 32 ChannelWin::State::~State() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 75 }
75 76
76 while (!output_queue_.empty()) { 77 while (!output_queue_.empty()) {
77 Message* m = output_queue_.front(); 78 Message* m = output_queue_.front();
78 output_queue_.pop(); 79 output_queue_.pop();
79 delete m; 80 delete m;
80 } 81 }
81 } 82 }
82 83
83 bool ChannelWin::Send(Message* message) { 84 bool ChannelWin::Send(Message* message) {
85 // TODO(erikchen): Remove this DCHECK once ChannelWin fully supports
86 // brokerable attachments. http://crbug.com/493414.
84 DCHECK(!message->HasAttachments()); 87 DCHECK(!message->HasAttachments());
85 DCHECK(thread_check_->CalledOnValidThread()); 88 DCHECK(thread_check_->CalledOnValidThread());
86 DVLOG(2) << "sending message @" << message << " on channel @" << this 89 DVLOG(2) << "sending message @" << message << " on channel @" << this
87 << " with type " << message->type() 90 << " with type " << message->type()
88 << " (" << output_queue_.size() << " in queue)"; 91 << " (" << output_queue_.size() << " in queue)";
89 92
93 // Sending a brokerable attachment requires a call to Channel::Send(), so
94 // Send() may be re-entrant. Brokered attachments must be sent before the
95 // Message itself.
96 if (message->HasBrokerableAttachments()) {
97 DCHECK(broker_);
98 for (const BrokerableAttachment* attachment :
99 message->attachment_set()->PeekBrokerableAttachments()) {
100 if (!broker_->SendAttachmentToProcess(attachment, peer_pid_))
101 return false;
102 }
103 }
104
90 #ifdef IPC_MESSAGE_LOG_ENABLED 105 #ifdef IPC_MESSAGE_LOG_ENABLED
91 Logging::GetInstance()->OnSendMessage(message, ""); 106 Logging::GetInstance()->OnSendMessage(message, "");
92 #endif 107 #endif
93 108
94 message->TraceMessageBegin(); 109 message->TraceMessageBegin();
95 output_queue_.push(message); 110 output_queue_.push(message);
96 // ensure waiting to write 111 // ensure waiting to write
97 if (!waiting_connect_) { 112 if (!waiting_connect_) {
98 if (!output_state_.is_pending) { 113 if (!output_state_.is_pending) {
99 if (!ProcessOutgoingMessages(NULL, 0)) 114 if (!ProcessOutgoingMessages(NULL, 0))
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 int secret; 525 int secret;
511 do { // Guarantee we get a non-zero value. 526 do { // Guarantee we get a non-zero value.
512 secret = base::RandInt(0, std::numeric_limits<int>::max()); 527 secret = base::RandInt(0, std::numeric_limits<int>::max());
513 } while (secret == 0); 528 } while (secret == 0);
514 529
515 id.append(GenerateUniqueRandomChannelID()); 530 id.append(GenerateUniqueRandomChannelID());
516 return id.append(base::StringPrintf("\\%d", secret)); 531 return id.append(base::StringPrintf("\\%d", secret));
517 } 532 }
518 533
519 } // namespace IPC 534 } // namespace IPC
OLDNEW
« ipc/brokerable_attachment.cc ('K') | « ipc/ipc.gypi ('k') | ipc/ipc_handle_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698