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/bind.h" |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "base/win/scoped_handle.h" | 15 #include "base/win/scoped_handle.h" |
15 #include "ipc/ipc_logging.h" | 16 #include "ipc/ipc_logging.h" |
16 #include "ipc/ipc_message_utils.h" | 17 #include "ipc/ipc_message_utils.h" |
17 | 18 |
18 namespace IPC { | 19 namespace IPC { |
19 | 20 |
20 Channel::ChannelImpl::State::State(ChannelImpl* channel) : is_pending(false) { | 21 Channel::ChannelImpl::State::State(ChannelImpl* channel) : is_pending(false) { |
21 memset(&context.overlapped, 0, sizeof(context.overlapped)); | 22 memset(&context.overlapped, 0, sizeof(context.overlapped)); |
22 context.handler = channel; | 23 context.handler = channel; |
23 } | 24 } |
24 | 25 |
25 Channel::ChannelImpl::State::~State() { | 26 Channel::ChannelImpl::State::~State() { |
26 COMPILE_ASSERT(!offsetof(Channel::ChannelImpl::State, context), | 27 COMPILE_ASSERT(!offsetof(Channel::ChannelImpl::State, context), |
27 starts_with_io_context); | 28 starts_with_io_context); |
28 } | 29 } |
29 | 30 |
30 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, | 31 Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, |
31 Mode mode, Listener* listener) | 32 Mode mode, Listener* listener) |
32 : ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)), | 33 : ALLOW_THIS_IN_INITIALIZER_LIST(input_state_(this)), |
33 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)), | 34 ALLOW_THIS_IN_INITIALIZER_LIST(output_state_(this)), |
34 pipe_(INVALID_HANDLE_VALUE), | 35 pipe_(INVALID_HANDLE_VALUE), |
35 listener_(listener), | 36 listener_(listener), |
36 waiting_connect_(mode & MODE_SERVER_FLAG), | 37 waiting_connect_(mode & MODE_SERVER_FLAG), |
37 processing_incoming_(false), | 38 processing_incoming_(false), |
38 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { | 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
39 CreatePipe(channel_handle, mode); | 40 CreatePipe(channel_handle, mode); |
40 } | 41 } |
41 | 42 |
42 Channel::ChannelImpl::~ChannelImpl() { | 43 Channel::ChannelImpl::~ChannelImpl() { |
43 Close(); | 44 Close(); |
44 } | 45 } |
45 | 46 |
46 void Channel::ChannelImpl::Close() { | 47 void Channel::ChannelImpl::Close() { |
47 if (thread_check_.get()) { | 48 if (thread_check_.get()) { |
48 DCHECK(thread_check_->CalledOnValidThread()); | 49 DCHECK(thread_check_->CalledOnValidThread()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 MessageLoopForIO::current()->RegisterIOHandler(pipe_, this); | 171 MessageLoopForIO::current()->RegisterIOHandler(pipe_, this); |
171 | 172 |
172 // Check to see if there is a client connected to our pipe... | 173 // Check to see if there is a client connected to our pipe... |
173 if (waiting_connect_) | 174 if (waiting_connect_) |
174 ProcessConnection(); | 175 ProcessConnection(); |
175 | 176 |
176 if (!input_state_.is_pending) { | 177 if (!input_state_.is_pending) { |
177 // Complete setup asynchronously. By not setting input_state_.is_pending | 178 // Complete setup asynchronously. By not setting input_state_.is_pending |
178 // to true, we indicate to OnIOCompleted that this is the special | 179 // to true, we indicate to OnIOCompleted that this is the special |
179 // initialization signal. | 180 // initialization signal. |
180 MessageLoopForIO::current()->PostTask(FROM_HERE, factory_.NewRunnableMethod( | 181 MessageLoopForIO::current()->PostTask( |
181 &Channel::ChannelImpl::OnIOCompleted, &input_state_.context, 0, 0)); | 182 FROM_HERE, base::Bind(&Channel::ChannelImpl::OnIOCompleted, |
| 183 weak_factory_.GetWeakPtr(), &input_state_.context, |
| 184 0, 0)); |
182 } | 185 } |
183 | 186 |
184 if (!waiting_connect_) | 187 if (!waiting_connect_) |
185 ProcessOutgoingMessages(NULL, 0); | 188 ProcessOutgoingMessages(NULL, 0); |
186 return true; | 189 return true; |
187 } | 190 } |
188 | 191 |
189 bool Channel::ChannelImpl::ProcessConnection() { | 192 bool Channel::ChannelImpl::ProcessConnection() { |
190 DCHECK(thread_check_->CalledOnValidThread()); | 193 DCHECK(thread_check_->CalledOnValidThread()); |
191 if (input_state_.is_pending) | 194 if (input_state_.is_pending) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 bool Channel::Send(Message* message) { | 424 bool Channel::Send(Message* message) { |
422 return channel_impl_->Send(message); | 425 return channel_impl_->Send(message); |
423 } | 426 } |
424 | 427 |
425 // static | 428 // static |
426 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { | 429 bool Channel::IsNamedServerInitialized(const std::string& channel_id) { |
427 return ChannelImpl::IsNamedServerInitialized(channel_id); | 430 return ChannelImpl::IsNamedServerInitialized(channel_id); |
428 } | 431 } |
429 | 432 |
430 } // namespace IPC | 433 } // namespace IPC |
OLD | NEW |