| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/edk/system/channel.h" | 5 #include "mojo/edk/system/channel.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 reject_writes_ = write_error = true; | 109 reject_writes_ = write_error = true; |
| 110 } | 110 } |
| 111 if (write_error) { | 111 if (write_error) { |
| 112 // Do not synchronously invoke OnError(). Write() may have been called by | 112 // Do not synchronously invoke OnError(). Write() may have been called by |
| 113 // the delegate and we don't want to re-enter it. | 113 // the delegate and we don't want to re-enter it. |
| 114 io_task_runner_->PostTask(FROM_HERE, | 114 io_task_runner_->PostTask(FROM_HERE, |
| 115 base::Bind(&ChannelWin::OnError, this)); | 115 base::Bind(&ChannelWin::OnError, this)); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 void LeakHandle() override { |
| 120 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 121 leak_handle_ = true; |
| 122 } |
| 123 |
| 119 bool GetReadPlatformHandles( | 124 bool GetReadPlatformHandles( |
| 120 size_t num_handles, | 125 size_t num_handles, |
| 121 const void* extra_header, | 126 const void* extra_header, |
| 122 size_t extra_header_size, | 127 size_t extra_header_size, |
| 123 ScopedPlatformHandleVectorPtr* handles) override { | 128 ScopedPlatformHandleVectorPtr* handles) override { |
| 124 if (num_handles > std::numeric_limits<uint16_t>::max()) | 129 if (num_handles > std::numeric_limits<uint16_t>::max()) |
| 125 return false; | 130 return false; |
| 126 using HandleEntry = Channel::Message::HandleEntry; | 131 using HandleEntry = Channel::Message::HandleEntry; |
| 127 size_t handles_size = sizeof(HandleEntry) * num_handles; | 132 size_t handles_size = sizeof(HandleEntry) * num_handles; |
| 128 if (handles_size > extra_header_size) | 133 if (handles_size > extra_header_size) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 ReadMore(0); | 189 ReadMore(0); |
| 185 } | 190 } |
| 186 | 191 |
| 187 void ShutDownOnIOThread() { | 192 void ShutDownOnIOThread() { |
| 188 base::MessageLoop::current()->RemoveDestructionObserver(this); | 193 base::MessageLoop::current()->RemoveDestructionObserver(this); |
| 189 | 194 |
| 190 // BUG(crbug.com/583525): This function is expected to be called once, and | 195 // BUG(crbug.com/583525): This function is expected to be called once, and |
| 191 // |handle_| should be valid at this point. | 196 // |handle_| should be valid at this point. |
| 192 CHECK(handle_.is_valid()); | 197 CHECK(handle_.is_valid()); |
| 193 CancelIo(handle_.get().handle); | 198 CancelIo(handle_.get().handle); |
| 199 if (leak_handle_) |
| 200 ignore_result(handle_.release()); |
| 194 handle_.reset(); | 201 handle_.reset(); |
| 195 | 202 |
| 196 // May destroy the |this| if it was the last reference. | 203 // May destroy the |this| if it was the last reference. |
| 197 self_ = nullptr; | 204 self_ = nullptr; |
| 198 } | 205 } |
| 199 | 206 |
| 200 // base::MessageLoop::DestructionObserver: | 207 // base::MessageLoop::DestructionObserver: |
| 201 void WillDestroyCurrentMessageLoop() override { | 208 void WillDestroyCurrentMessageLoop() override { |
| 202 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 209 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 203 if (self_) | 210 if (self_) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 // Protects |reject_writes_| and |outgoing_messages_|. | 332 // Protects |reject_writes_| and |outgoing_messages_|. |
| 326 base::Lock write_lock_; | 333 base::Lock write_lock_; |
| 327 | 334 |
| 328 bool delay_writes_ = true; | 335 bool delay_writes_ = true; |
| 329 | 336 |
| 330 bool reject_writes_ = false; | 337 bool reject_writes_ = false; |
| 331 std::deque<MessageView> outgoing_messages_; | 338 std::deque<MessageView> outgoing_messages_; |
| 332 | 339 |
| 333 bool wait_for_connect_; | 340 bool wait_for_connect_; |
| 334 | 341 |
| 342 bool leak_handle_ = false; |
| 343 |
| 335 DISALLOW_COPY_AND_ASSIGN(ChannelWin); | 344 DISALLOW_COPY_AND_ASSIGN(ChannelWin); |
| 336 }; | 345 }; |
| 337 | 346 |
| 338 } // namespace | 347 } // namespace |
| 339 | 348 |
| 340 // static | 349 // static |
| 341 scoped_refptr<Channel> Channel::Create( | 350 scoped_refptr<Channel> Channel::Create( |
| 342 Delegate* delegate, | 351 Delegate* delegate, |
| 343 ScopedPlatformHandle platform_handle, | 352 ScopedPlatformHandle platform_handle, |
| 344 scoped_refptr<base::TaskRunner> io_task_runner) { | 353 scoped_refptr<base::TaskRunner> io_task_runner) { |
| 345 return new ChannelWin(delegate, std::move(platform_handle), io_task_runner); | 354 return new ChannelWin(delegate, std::move(platform_handle), io_task_runner); |
| 346 } | 355 } |
| 347 | 356 |
| 348 } // namespace edk | 357 } // namespace edk |
| 349 } // namespace mojo | 358 } // namespace mojo |
| OLD | NEW |