OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (!waiting_connect_) { | 86 if (!waiting_connect_) { |
87 if (!output_state_.is_pending) { | 87 if (!output_state_.is_pending) { |
88 if (!ProcessOutgoingMessages(NULL, 0)) | 88 if (!ProcessOutgoingMessages(NULL, 0)) |
89 return false; | 89 return false; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
96 const std::wstring Channel::ChannelImpl::PipeName( | |
97 const std::string& channel_id) const { | |
98 std::string name("\\\\.\\pipe\\chrome."); | |
99 return ASCIIToWide(name.append(channel_id)); | |
100 } | |
101 | |
102 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, | 96 bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, |
103 Mode mode) { | 97 Mode mode) { |
104 DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_); | 98 DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_); |
105 const std::wstring pipe_name = PipeName(channel_handle.name); | 99 const std::wstring pipe_name = PipeNameFromChannelId(channel_handle.name); |
106 if (mode & MODE_SERVER_FLAG) { | 100 if (mode & MODE_SERVER_FLAG) { |
107 pipe_ = CreateNamedPipeW(pipe_name.c_str(), | 101 pipe_ = CreateNamedPipeW(pipe_name.c_str(), |
108 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | | 102 PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | |
109 FILE_FLAG_FIRST_PIPE_INSTANCE, | 103 FILE_FLAG_FIRST_PIPE_INSTANCE, |
110 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, | 104 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, |
111 1, | 105 1, |
112 Channel::kReadBufferSize, | 106 Channel::kReadBufferSize, |
113 Channel::kReadBufferSize, | 107 Channel::kReadBufferSize, |
114 5000, | 108 5000, |
115 NULL); | 109 NULL); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 DCHECK(context == &output_state_.context); | 371 DCHECK(context == &output_state_.context); |
378 ok = ProcessOutgoingMessages(context, bytes_transfered); | 372 ok = ProcessOutgoingMessages(context, bytes_transfered); |
379 } | 373 } |
380 if (!ok && INVALID_HANDLE_VALUE != pipe_) { | 374 if (!ok && INVALID_HANDLE_VALUE != pipe_) { |
381 // We don't want to re-enter Close(). | 375 // We don't want to re-enter Close(). |
382 Close(); | 376 Close(); |
383 listener_->OnChannelError(); | 377 listener_->OnChannelError(); |
384 } | 378 } |
385 } | 379 } |
386 | 380 |
| 381 const std::wstring PipeNameFromChannelId(const std::string& channel_id) { |
| 382 std::string name("\\\\.\\pipe\\chrome."); |
| 383 return ASCIIToWide(name.append(channel_id)); |
| 384 } |
| 385 |
387 //------------------------------------------------------------------------------ | 386 //------------------------------------------------------------------------------ |
388 // Channel's methods simply call through to ChannelImpl. | 387 // Channel's methods simply call through to ChannelImpl. |
389 Channel::Channel(const IPC::ChannelHandle &channel_handle, Mode mode, | 388 Channel::Channel(const IPC::ChannelHandle &channel_handle, Mode mode, |
390 Listener* listener) | 389 Listener* listener) |
391 : channel_impl_(new ChannelImpl(channel_handle, mode, listener)) { | 390 : channel_impl_(new ChannelImpl(channel_handle, mode, listener)) { |
392 } | 391 } |
393 | 392 |
394 Channel::~Channel() { | 393 Channel::~Channel() { |
395 delete channel_impl_; | 394 delete channel_impl_; |
396 } | 395 } |
397 | 396 |
398 bool Channel::Connect() { | 397 bool Channel::Connect() { |
399 return channel_impl_->Connect(); | 398 return channel_impl_->Connect(); |
400 } | 399 } |
401 | 400 |
402 void Channel::Close() { | 401 void Channel::Close() { |
403 channel_impl_->Close(); | 402 channel_impl_->Close(); |
404 } | 403 } |
405 | 404 |
406 void Channel::set_listener(Listener* listener) { | 405 void Channel::set_listener(Listener* listener) { |
407 channel_impl_->set_listener(listener); | 406 channel_impl_->set_listener(listener); |
408 } | 407 } |
409 | 408 |
410 bool Channel::Send(Message* message) { | 409 bool Channel::Send(Message* message) { |
411 return channel_impl_->Send(message); | 410 return channel_impl_->Send(message); |
412 } | 411 } |
413 | 412 |
414 } // namespace IPC | 413 } // namespace IPC |
OLD | NEW |