OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 COMPILE_ASSERT(!offsetof(Channel::ChannelImpl::State, context), | 30 COMPILE_ASSERT(!offsetof(Channel::ChannelImpl::State, context), |
31 starts_with_io_context); | 31 starts_with_io_context); |
32 } | 32 } |
33 | 33 |
34 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, | 34 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, |
35 Mode mode, Listener* listener) | 35 Mode mode, Listener* listener) |
36 : ChannelReader(listener), | 36 : ChannelReader(listener), |
37 ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)), | 37 ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)), |
38 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)), | 38 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)), |
39 pipe_(INVALID_HANDLE_VALUE), | 39 pipe_(INVALID_HANDLE_VALUE), |
| 40 peer_pid_(base::kNullProcessId), |
40 waiting_connect_(mode & MODE_SERVER_FLAG), | 41 waiting_connect_(mode & MODE_SERVER_FLAG), |
41 processing_incoming_(false), | 42 processing_incoming_(false), |
42 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 43 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
43 client_secret_(0), | 44 client_secret_(0), |
44 validate_client_(false) { | 45 validate_client_(false) { |
45 CreatePipe(channel_handle, mode); | 46 CreatePipe(channel_handle, mode); |
46 } | 47 } |
47 | 48 |
48 Channel::ChannelImpl::~ChannelImpl() { | 49 Channel::ChannelImpl::~ChannelImpl() { |
49 Close(); | 50 Close(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // The hello message contains one parameter containing the PID. | 153 // The hello message contains one parameter containing the PID. |
153 MessageIterator it = MessageIterator(msg); | 154 MessageIterator it = MessageIterator(msg); |
154 int32 claimed_pid = it.NextInt(); | 155 int32 claimed_pid = it.NextInt(); |
155 if (validate_client_ && (it.NextInt() != client_secret_)) { | 156 if (validate_client_ && (it.NextInt() != client_secret_)) { |
156 NOTREACHED(); | 157 NOTREACHED(); |
157 // Something went wrong. Abort connection. | 158 // Something went wrong. Abort connection. |
158 Close(); | 159 Close(); |
159 listener()->OnChannelError(); | 160 listener()->OnChannelError(); |
160 return; | 161 return; |
161 } | 162 } |
| 163 peer_pid_ = claimed_pid; |
162 // validation completed. | 164 // validation completed. |
163 validate_client_ = false; | 165 validate_client_ = false; |
164 listener()->OnChannelConnected(claimed_pid); | 166 listener()->OnChannelConnected(claimed_pid); |
165 } | 167 } |
166 | 168 |
167 bool Channel::ChannelImpl::DidEmptyInputBuffers() { | 169 bool Channel::ChannelImpl::DidEmptyInputBuffers() { |
168 // We don't need to do anything here. | 170 // We don't need to do anything here. |
169 return true; | 171 return true; |
170 } | 172 } |
171 | 173 |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 462 } |
461 | 463 |
462 void Channel::Close() { | 464 void Channel::Close() { |
463 channel_impl_->Close(); | 465 channel_impl_->Close(); |
464 } | 466 } |
465 | 467 |
466 void Channel::set_listener(Listener* listener) { | 468 void Channel::set_listener(Listener* listener) { |
467 channel_impl_->set_listener(listener); | 469 channel_impl_->set_listener(listener); |
468 } | 470 } |
469 | 471 |
| 472 base::ProcessId Channel::peer_pid() const { |
| 473 return channel_impl_->peer_pid(); |
| 474 } |
| 475 |
470 bool Channel::Send(Message* message) { | 476 bool Channel::Send(Message* message) { |
471 return channel_impl_->Send(message); | 477 return channel_impl_->Send(message); |
472 } | 478 } |
473 | 479 |
474 // static | 480 // static |
475 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { | 481 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { |
476 return ChannelImpl::IsNamedServerInitialized(channel_id); | 482 return ChannelImpl::IsNamedServerInitialized(channel_id); |
477 } | 483 } |
478 | 484 |
479 // static | 485 // static |
(...skipping 10 matching lines...) Expand all Loading... |
490 int secret; | 496 int secret; |
491 do { // Guarantee we get a non-zero value. | 497 do { // Guarantee we get a non-zero value. |
492 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 498 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
493 } while (secret == 0); | 499 } while (secret == 0); |
494 | 500 |
495 id.append(GenerateUniqueRandomChannelID()); | 501 id.append(GenerateUniqueRandomChannelID()); |
496 return id.append(base::StringPrintf("\\%d", secret)); | 502 return id.append(base::StringPrintf("\\%d", secret)); |
497 } | 503 } |
498 | 504 |
499 } // namespace IPC | 505 } // namespace IPC |
OLD | NEW |