| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 LazyInitialize(); | 214 LazyInitialize(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void RawChannel::LazyInitialize() { | 217 void RawChannel::LazyInitialize() { |
| 218 read_lock_.AssertAcquired(); | 218 read_lock_.AssertAcquired(); |
| 219 write_lock_.AssertAcquired(); | 219 write_lock_.AssertAcquired(); |
| 220 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread()); | 220 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread()); |
| 221 if (initialized_) | 221 if (initialized_) |
| 222 return; | 222 return; |
| 223 initialized_ = true; | 223 initialized_ = true; |
| 224 internal::ChannelStarted(); | |
| 225 base::MessageLoop::current()->AddDestructionObserver(this); | 224 base::MessageLoop::current()->AddDestructionObserver(this); |
| 226 | 225 |
| 227 OnInit(); | 226 OnInit(); |
| 228 | 227 |
| 229 if (read_buffer_->num_valid_bytes_) { | 228 if (read_buffer_->num_valid_bytes_) { |
| 230 // We had serialized read buffer data through SetSerializedData call. | 229 // We had serialized read buffer data through SetSerializedData call. |
| 231 // Make sure we read messages out of it now, otherwise the delegate won't | 230 // Make sure we read messages out of it now, otherwise the delegate won't |
| 232 // get notified if no other data gets written to the pipe. | 231 // get notified if no other data gets written to the pipe. |
| 233 // Although this means that we can call back synchronously into the caller, | 232 // Although this means that we can call back synchronously into the caller, |
| 234 // that's easier than posting a task to do this. That is because if we post | 233 // that's easier than posting a task to do this. That is because if we post |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // 2) we have a read or write error before (doesn't matter which), or 3) when | 280 // 2) we have a read or write error before (doesn't matter which), or 3) when |
| 282 // there are no pending messages to be written. | 281 // there are no pending messages to be written. |
| 283 if (!IsHandleValid() || error_occurred_ || empty) { | 282 if (!IsHandleValid() || error_occurred_ || empty) { |
| 284 { | 283 { |
| 285 base::AutoLock read_locker(read_lock_); | 284 base::AutoLock read_locker(read_lock_); |
| 286 base::AutoLock locker(write_lock_); | 285 base::AutoLock locker(write_lock_); |
| 287 OnShutdownNoLock(read_buffer_.Pass(), write_buffer_.Pass()); | 286 OnShutdownNoLock(read_buffer_.Pass(), write_buffer_.Pass()); |
| 288 } | 287 } |
| 289 | 288 |
| 290 if (initialized_) { | 289 if (initialized_) { |
| 291 internal::ChannelShutdown(); | |
| 292 base::MessageLoop::current()->RemoveDestructionObserver(this); | 290 base::MessageLoop::current()->RemoveDestructionObserver(this); |
| 293 } | 291 } |
| 294 delete this; | 292 delete this; |
| 295 return; | 293 return; |
| 296 } | 294 } |
| 297 | 295 |
| 298 base::AutoLock read_locker(read_lock_); | 296 base::AutoLock read_locker(read_lock_); |
| 299 base::AutoLock locker(write_lock_); | 297 base::AutoLock locker(write_lock_); |
| 300 DCHECK(read_buffer_->IsEmpty()) << | 298 DCHECK(read_buffer_->IsEmpty()) << |
| 301 "RawChannel::Shutdown called but there is pending data to be read"; | 299 "RawChannel::Shutdown called but there is pending data to be read"; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 OnReadCompletedNoLock(io_result, bytes_read); | 720 OnReadCompletedNoLock(io_result, bytes_read); |
| 723 } | 721 } |
| 724 | 722 |
| 725 void RawChannel::WillDestroyCurrentMessageLoop() { | 723 void RawChannel::WillDestroyCurrentMessageLoop() { |
| 726 base::AutoLock locker(read_lock_); | 724 base::AutoLock locker(read_lock_); |
| 727 OnReadCompletedNoLock(IO_FAILED_SHUTDOWN, 0); | 725 OnReadCompletedNoLock(IO_FAILED_SHUTDOWN, 0); |
| 728 } | 726 } |
| 729 | 727 |
| 730 } // namespace edk | 728 } // namespace edk |
| 731 } // namespace mojo | 729 } // namespace mojo |
| OLD | NEW |