| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 // static | 185 // static |
| 186 const base::string16 Channel::ChannelImpl::PipeName( | 186 const base::string16 Channel::ChannelImpl::PipeName( |
| 187 const std::string& channel_id, int32* secret) { | 187 const std::string& channel_id, int32* secret) { |
| 188 std::string name("\\\\.\\pipe\\chrome."); | 188 std::string name("\\\\.\\pipe\\chrome."); |
| 189 | 189 |
| 190 // Prevent the shared secret from ending up in the pipe name. | 190 // Prevent the shared secret from ending up in the pipe name. |
| 191 size_t index = channel_id.find_first_of('\\'); | 191 size_t index = channel_id.find_first_of('\\'); |
| 192 if (index != std::string::npos) { | 192 if (index != std::string::npos) { |
| 193 if (secret) // Retrieve the secret if asked for. | 193 if (secret) // Retrieve the secret if asked for. |
| 194 base::StringToInt(channel_id.substr(index + 1), secret); | 194 base::StringToInt(channel_id.substr(index + 1), secret); |
| 195 return ASCIIToWide(name.append(channel_id.substr(0, index - 1))); | 195 return base::ASCIIToWide(name.append(channel_id.substr(0, index - 1))); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // This case is here to support predictable named pipes in tests. | 198 // This case is here to support predictable named pipes in tests. |
| 199 if (secret) | 199 if (secret) |
| 200 *secret = 0; | 200 *secret = 0; |
| 201 return ASCIIToWide(name.append(channel_id)); | 201 return base::ASCIIToWide(name.append(channel_id)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, | 204 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, |
| 205 Mode mode) { | 205 Mode mode) { |
| 206 DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_); | 206 DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_); |
| 207 base::string16 pipe_name; | 207 base::string16 pipe_name; |
| 208 // If we already have a valid pipe for channel just copy it. | 208 // If we already have a valid pipe for channel just copy it. |
| 209 if (channel_handle.pipe.handle) { | 209 if (channel_handle.pipe.handle) { |
| 210 DCHECK(channel_handle.name.empty()); | 210 DCHECK(channel_handle.name.empty()); |
| 211 pipe_name = L"Not Available"; // Just used for LOG | 211 pipe_name = L"Not Available"; // Just used for LOG |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 int secret; | 509 int secret; |
| 510 do { // Guarantee we get a non-zero value. | 510 do { // Guarantee we get a non-zero value. |
| 511 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 511 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
| 512 } while (secret == 0); | 512 } while (secret == 0); |
| 513 | 513 |
| 514 id.append(GenerateUniqueRandomChannelID()); | 514 id.append(GenerateUniqueRandomChannelID()); |
| 515 return id.append(base::StringPrintf("\\%d", secret)); | 515 return id.append(base::StringPrintf("\\%d", secret)); |
| 516 } | 516 } |
| 517 | 517 |
| 518 } // namespace IPC | 518 } // namespace IPC |
| OLD | NEW |