| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // | 135 // |
| 136 // This allows us to potentially process some outgoing messages and | 136 // This allows us to potentially process some outgoing messages and |
| 137 // interleave other work on this thread when we're getting hammered with | 137 // interleave other work on this thread when we're getting hammered with |
| 138 // input messages. Potentially, this could be tuned to be more efficient | 138 // input messages. Potentially, this could be tuned to be more efficient |
| 139 // with some testing. | 139 // with some testing. |
| 140 input_state_.is_pending = true; | 140 input_state_.is_pending = true; |
| 141 return READ_PENDING; | 141 return READ_PENDING; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { | 144 bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { |
| 145 // We don't need to do anything here. | 145 // Make sure we get a hello when client validation is required. |
| 146 if (validate_client_) |
| 147 return IsHelloMessage(*msg); |
| 146 return true; | 148 return true; |
| 147 } | 149 } |
| 148 | 150 |
| 149 void Channel::ChannelImpl::HandleHelloMessage(const Message& msg) { | 151 void Channel::ChannelImpl::HandleHelloMessage(const Message& msg) { |
| 150 // The hello message contains one parameter containing the PID. | 152 // The hello message contains one parameter containing the PID. |
| 151 MessageIterator it = MessageIterator(msg); | 153 MessageIterator it = MessageIterator(msg); |
| 152 int32 claimed_pid = it.NextInt(); | 154 int32 claimed_pid = it.NextInt(); |
| 153 if (validate_client_ && (it.NextInt() != client_secret_)) { | 155 if (validate_client_ && (it.NextInt() != client_secret_)) { |
| 154 NOTREACHED(); | 156 NOTREACHED(); |
| 155 // Something went wrong. Abort connection. | 157 // Something went wrong. Abort connection. |
| 156 Close(); | 158 Close(); |
| 157 listener()->OnChannelError(); | 159 listener()->OnChannelError(); |
| 158 return; | 160 return; |
| 159 } | 161 } |
| 162 // validation completed. |
| 163 validate_client_ = false; |
| 160 listener()->OnChannelConnected(claimed_pid); | 164 listener()->OnChannelConnected(claimed_pid); |
| 161 } | 165 } |
| 162 | 166 |
| 163 bool Channel::ChannelImpl::DidEmptyInputBuffers() { | 167 bool Channel::ChannelImpl::DidEmptyInputBuffers() { |
| 164 // We don't need to do anything here. | 168 // We don't need to do anything here. |
| 165 return true; | 169 return true; |
| 166 } | 170 } |
| 167 | 171 |
| 168 // static | 172 // static |
| 169 const string16 Channel::ChannelImpl::PipeName( | 173 const string16 Channel::ChannelImpl::PipeName( |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 int secret; | 490 int secret; |
| 487 do { // Guarantee we get a non-zero value. | 491 do { // Guarantee we get a non-zero value. |
| 488 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 492 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
| 489 } while (secret == 0); | 493 } while (secret == 0); |
| 490 | 494 |
| 491 id.append(GenerateUniqueRandomChannelID()); | 495 id.append(GenerateUniqueRandomChannelID()); |
| 492 return id.append(base::StringPrintf("\\%d", secret)); | 496 return id.append(base::StringPrintf("\\%d", secret)); |
| 493 } | 497 } |
| 494 | 498 |
| 495 } // namespace IPC | 499 } // namespace IPC |
| OLD | NEW |