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

Side by Side Diff: ipc/ipc_channel_win.cc

Issue 1185133006: IPC: Make ChannelReader inherit from SupportsAttachmentBrokering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from tsepez. 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
« no previous file with comments | « ipc/ipc_channel_win.h ('k') | ipc/ipc_fuzzing_tests.cc » ('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 "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"
(...skipping 16 matching lines...) Expand all
27 memset(&context.overlapped, 0, sizeof(context.overlapped)); 27 memset(&context.overlapped, 0, sizeof(context.overlapped));
28 context.handler = channel; 28 context.handler = channel;
29 } 29 }
30 30
31 ChannelWin::State::~State() { 31 ChannelWin::State::~State() {
32 static_assert(offsetof(ChannelWin::State, context) == 0, 32 static_assert(offsetof(ChannelWin::State, context) == 0,
33 "ChannelWin::State should have context as its first data" 33 "ChannelWin::State should have context as its first data"
34 "member."); 34 "member.");
35 } 35 }
36 36
37 ChannelWin::ChannelWin(const IPC::ChannelHandle &channel_handle, 37 ChannelWin::ChannelWin(const IPC::ChannelHandle& channel_handle,
38 Mode mode, Listener* listener) 38 Mode mode,
39 Listener* listener,
40 AttachmentBroker* broker)
39 : ChannelReader(listener), 41 : ChannelReader(listener),
40 input_state_(this), 42 input_state_(this),
41 output_state_(this), 43 output_state_(this),
42 peer_pid_(base::kNullProcessId), 44 peer_pid_(base::kNullProcessId),
43 waiting_connect_(mode & MODE_SERVER_FLAG), 45 waiting_connect_(mode & MODE_SERVER_FLAG),
44 processing_incoming_(false), 46 processing_incoming_(false),
45 validate_client_(false), 47 validate_client_(false),
46 client_secret_(0), 48 client_secret_(0),
47 weak_factory_(this) { 49 weak_factory_(this),
50 broker_(broker) {
48 CreatePipe(channel_handle, mode); 51 CreatePipe(channel_handle, mode);
49 } 52 }
50 53
51 ChannelWin::~ChannelWin() { 54 ChannelWin::~ChannelWin() {
52 Close(); 55 Close();
53 } 56 }
54 57
55 void ChannelWin::Close() { 58 void ChannelWin::Close() {
56 if (thread_check_.get()) 59 if (thread_check_.get())
57 DCHECK(thread_check_->CalledOnValidThread()); 60 DCHECK(thread_check_->CalledOnValidThread());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (!waiting_connect_) { 97 if (!waiting_connect_) {
95 if (!output_state_.is_pending) { 98 if (!output_state_.is_pending) {
96 if (!ProcessOutgoingMessages(NULL, 0)) 99 if (!ProcessOutgoingMessages(NULL, 0))
97 return false; 100 return false;
98 } 101 }
99 } 102 }
100 103
101 return true; 104 return true;
102 } 105 }
103 106
107 AttachmentBroker* ChannelWin::GetAttachmentBroker() {
108 return broker_;
109 }
110
104 base::ProcessId ChannelWin::GetPeerPID() const { 111 base::ProcessId ChannelWin::GetPeerPID() const {
105 return peer_pid_; 112 return peer_pid_;
106 } 113 }
107 114
108 base::ProcessId ChannelWin::GetSelfPID() const { 115 base::ProcessId ChannelWin::GetSelfPID() const {
109 return GetCurrentProcessId(); 116 return GetCurrentProcessId();
110 } 117 }
111 118
112 // static 119 // static
113 bool ChannelWin::IsNamedServerInitialized( 120 bool ChannelWin::IsNamedServerInitialized(
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 // We don't want to re-enter Close(). 476 // We don't want to re-enter Close().
470 Close(); 477 Close();
471 listener()->OnChannelError(); 478 listener()->OnChannelError();
472 } 479 }
473 } 480 }
474 481
475 //------------------------------------------------------------------------------ 482 //------------------------------------------------------------------------------
476 // Channel's methods 483 // Channel's methods
477 484
478 // static 485 // static
479 scoped_ptr<Channel> Channel::Create( 486 scoped_ptr<Channel> Channel::Create(const IPC::ChannelHandle& channel_handle,
480 const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { 487 Mode mode,
488 Listener* listener,
489 AttachmentBroker* broker) {
481 return scoped_ptr<Channel>( 490 return scoped_ptr<Channel>(
482 new ChannelWin(channel_handle, mode, listener)); 491 new ChannelWin(channel_handle, mode, listener, broker));
483 } 492 }
484 493
485 // static 494 // static
486 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { 495 bool Channel::IsNamedServerInitialized(const std::string& channel_id) {
487 return ChannelWin::IsNamedServerInitialized(channel_id); 496 return ChannelWin::IsNamedServerInitialized(channel_id);
488 } 497 }
489 498
490 // static 499 // static
491 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { 500 std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) {
492 // Windows pipes can be enumerated by low-privileged processes. So, we 501 // Windows pipes can be enumerated by low-privileged processes. So, we
493 // append a strong random value after the \ character. This value is not 502 // append a strong random value after the \ character. This value is not
494 // included in the pipe name, but sent as part of the client hello, to 503 // included in the pipe name, but sent as part of the client hello, to
495 // hijacking the pipe name to spoof the client. 504 // hijacking the pipe name to spoof the client.
496 505
497 std::string id = prefix; 506 std::string id = prefix;
498 if (!id.empty()) 507 if (!id.empty())
499 id.append("."); 508 id.append(".");
500 509
501 int secret; 510 int secret;
502 do { // Guarantee we get a non-zero value. 511 do { // Guarantee we get a non-zero value.
503 secret = base::RandInt(0, std::numeric_limits<int>::max()); 512 secret = base::RandInt(0, std::numeric_limits<int>::max());
504 } while (secret == 0); 513 } while (secret == 0);
505 514
506 id.append(GenerateUniqueRandomChannelID()); 515 id.append(GenerateUniqueRandomChannelID());
507 return id.append(base::StringPrintf("\\%d", secret)); 516 return id.append(base::StringPrintf("\\%d", secret));
508 } 517 }
509 518
510 } // namespace IPC 519 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_win.h ('k') | ipc/ipc_fuzzing_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698