OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/system/raw_channel.h" | 5 #include "mojo/system/raw_channel.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 cancel_io_ex_ = reinterpret_cast<CancelIoExFunc>( | 63 cancel_io_ex_ = reinterpret_cast<CancelIoExFunc>( |
64 GetProcAddress(module, "CancelIoEx")); | 64 GetProcAddress(module, "CancelIoEx")); |
65 DCHECK(cancel_io_ex_); | 65 DCHECK(cancel_io_ex_); |
66 } | 66 } |
67 | 67 |
68 base::LazyInstance<VistaOrHigherFunctions> g_vista_or_higher_functions = | 68 base::LazyInstance<VistaOrHigherFunctions> g_vista_or_higher_functions = |
69 LAZY_INSTANCE_INITIALIZER; | 69 LAZY_INSTANCE_INITIALIZER; |
70 | 70 |
71 class RawChannelWin : public RawChannel { | 71 class RawChannelWin : public RawChannel { |
72 public: | 72 public: |
73 RawChannelWin(embedder::ScopedPlatformHandle handle, | 73 RawChannelWin(embedder::ScopedPlatformHandle handle); |
74 Delegate* delegate, | |
75 base::MessageLoopForIO* message_loop); | |
76 virtual ~RawChannelWin(); | 74 virtual ~RawChannelWin(); |
77 | 75 |
78 private: | 76 private: |
79 // RawChannelIOHandler receives OS notifications for I/O completion. It must | 77 // RawChannelIOHandler receives OS notifications for I/O completion. It must |
80 // be created on the I/O thread. | 78 // be created on the I/O thread. |
81 // | 79 // |
82 // It manages its own destruction. Destruction happens on the I/O thread when | 80 // It manages its own destruction. Destruction happens on the I/O thread when |
83 // all the following conditions are satisfied: | 81 // all the following conditions are satisfied: |
84 // - |DetachFromOwnerNoLock()| has been called; | 82 // - |DetachFromOwnerNoLock()| has been called; |
85 // - there is no pending read; | 83 // - there is no pending read; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 315 } |
318 | 316 |
319 if (error != ERROR_SUCCESS) { | 317 if (error != ERROR_SUCCESS) { |
320 LOG(ERROR) << "WriteFile failed: " << error; | 318 LOG(ERROR) << "WriteFile failed: " << error; |
321 owner_->OnWriteCompleted(false, 0); | 319 owner_->OnWriteCompleted(false, 0); |
322 } else { | 320 } else { |
323 owner_->OnWriteCompleted(true, bytes_written); | 321 owner_->OnWriteCompleted(true, bytes_written); |
324 } | 322 } |
325 } | 323 } |
326 | 324 |
327 RawChannelWin::RawChannelWin(embedder::ScopedPlatformHandle handle, | 325 RawChannelWin::RawChannelWin(embedder::ScopedPlatformHandle handle) |
328 Delegate* delegate, | 326 : handle_(handle.Pass()), |
329 base::MessageLoopForIO* message_loop) | |
330 : RawChannel(delegate, message_loop), | |
331 handle_(handle.Pass()), | |
332 io_handler_(NULL), | 327 io_handler_(NULL), |
333 skip_completion_port_on_success_( | 328 skip_completion_port_on_success_( |
334 g_vista_or_higher_functions.Get().is_vista_or_higher()) { | 329 g_vista_or_higher_functions.Get().is_vista_or_higher()) { |
335 DCHECK(handle_.is_valid()); | 330 DCHECK(handle_.is_valid()); |
336 } | 331 } |
337 | 332 |
338 RawChannelWin::~RawChannelWin() { | 333 RawChannelWin::~RawChannelWin() { |
339 DCHECK(!io_handler_); | 334 DCHECK(!io_handler_); |
340 } | 335 } |
341 | 336 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 io_handler_->DetachFromOwnerNoLock(read_buffer.Pass(), write_buffer.Pass()); | 509 io_handler_->DetachFromOwnerNoLock(read_buffer.Pass(), write_buffer.Pass()); |
515 io_handler_ = NULL; | 510 io_handler_ = NULL; |
516 } | 511 } |
517 | 512 |
518 } // namespace | 513 } // namespace |
519 | 514 |
520 // ----------------------------------------------------------------------------- | 515 // ----------------------------------------------------------------------------- |
521 | 516 |
522 // Static factory method declared in raw_channel.h. | 517 // Static factory method declared in raw_channel.h. |
523 // static | 518 // static |
524 RawChannel* RawChannel::Create(embedder::ScopedPlatformHandle handle, | 519 scoped_ptr<RawChannel> RawChannel::Create( |
525 Delegate* delegate, | 520 embedder::ScopedPlatformHandle handle) { |
526 base::MessageLoopForIO* message_loop) { | 521 return scoped_ptr<RawChannel>(new RawChannelWin(handle.Pass())); |
527 return new RawChannelWin(handle.Pass(), delegate, message_loop); | |
528 } | 522 } |
529 | 523 |
530 } // namespace system | 524 } // namespace system |
531 } // namespace mojo | 525 } // namespace mojo |
OLD | NEW |