| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/child/shared_memory_data_consumer_handle.h" | 5 #include "content/child/shared_memory_data_consumer_handle.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 Result result() const { | 101 Result result() const { |
| 102 lock_.AssertAcquired(); | 102 lock_.AssertAcquired(); |
| 103 return result_; | 103 return result_; |
| 104 } | 104 } |
| 105 void set_result(Result r) { | 105 void set_result(Result r) { |
| 106 lock_.AssertAcquired(); | 106 lock_.AssertAcquired(); |
| 107 result_ = r; | 107 result_ = r; |
| 108 } | 108 } |
| 109 void AcquireReaderLock(Client* client) { | 109 void AcquireReaderLock(Client* client) { |
| 110 lock_.AssertAcquired(); | 110 lock_.AssertAcquired(); |
| 111 DCHECK(!notification_task_runner_); | 111 // TODO(yhirano): Turn these CHECKs to DCHECKs once the crash is fixed. |
| 112 DCHECK(!client_); | 112 CHECK(!notification_task_runner_); |
| 113 CHECK(!client_); |
| 113 notification_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 114 notification_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 114 client_ = client; | 115 client_ = client; |
| 115 if (client && !(IsEmpty() && result() == Ok)) { | 116 if (client && !(IsEmpty() && result() == Ok)) { |
| 116 // We cannot notify synchronously because the user doesn't have the reader | 117 // We cannot notify synchronously because the user doesn't have the reader |
| 117 // yet. | 118 // yet. |
| 118 notification_task_runner_->PostTask( | 119 notification_task_runner_->PostTask( |
| 119 FROM_HERE, base::Bind(&Context::NotifyInternal, this, false)); | 120 FROM_HERE, base::Bind(&Context::NotifyInternal, this, false)); |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 void ReleaseReaderLock() { | 123 void ReleaseReaderLock() { |
| 123 lock_.AssertAcquired(); | 124 lock_.AssertAcquired(); |
| 124 DCHECK(notification_task_runner_); | 125 // TODO(yhirano): Turn these CHECKs to DCHECKs once the crash is fixed. |
| 126 CHECK(notification_task_runner_); |
| 127 CHECK(notification_task_runner_->BelongsToCurrentThread()); |
| 125 notification_task_runner_ = nullptr; | 128 notification_task_runner_ = nullptr; |
| 126 client_ = nullptr; | 129 client_ = nullptr; |
| 127 } | 130 } |
| 128 void PostNotify() { | 131 void PostNotify() { |
| 129 lock_.AssertAcquired(); | 132 lock_.AssertAcquired(); |
| 130 auto runner = notification_task_runner_; | 133 auto runner = notification_task_runner_; |
| 131 if (!runner) | 134 if (!runner) |
| 132 return; | 135 return; |
| 133 // We don't re-post the task when the runner changes while waiting for | 136 // We don't re-post the task when the runner changes while waiting for |
| 134 // this task because in this case a new reader is obtained and | 137 // this task because in this case a new reader is obtained and |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 // We don't re-post the task when the runner changes while waiting for | 219 // We don't re-post the task when the runner changes while waiting for |
| 217 // this task because in this case a new reader is obtained and | 220 // this task because in this case a new reader is obtained and |
| 218 // notification is already done at the reader creation time if necessary. | 221 // notification is already done at the reader creation time if necessary. |
| 219 runner->PostTask(FROM_HERE, | 222 runner->PostTask(FROM_HERE, |
| 220 base::Bind(&Context::NotifyInternal, this, false)); | 223 base::Bind(&Context::NotifyInternal, this, false)); |
| 221 } | 224 } |
| 222 } | 225 } |
| 223 void Clear() { | 226 void Clear() { |
| 224 lock_.AssertAcquired(); | 227 lock_.AssertAcquired(); |
| 225 ClearQueue(); | 228 ClearQueue(); |
| 226 client_ = nullptr; | 229 // Turn this CHECK to DCHECK. |
| 230 CHECK(!client_); |
| 227 ResetOnReaderDetached(); | 231 ResetOnReaderDetached(); |
| 228 } | 232 } |
| 229 // Must be called with |lock_| not aquired. | 233 // Must be called with |lock_| not aquired. |
| 230 void ResetOnReaderDetachedWithLock() { | 234 void ResetOnReaderDetachedWithLock() { |
| 231 base::AutoLock lock(lock_); | 235 base::AutoLock lock(lock_); |
| 232 ResetOnReaderDetached(); | 236 ResetOnReaderDetached(); |
| 233 } | 237 } |
| 234 | 238 |
| 235 friend class base::RefCountedThreadSafe<Context>; | 239 friend class base::RefCountedThreadSafe<Context>; |
| 236 ~Context() = default; | 240 ~Context() = default; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 std::unique_ptr<blink::WebDataConsumerHandle::Reader> | 455 std::unique_ptr<blink::WebDataConsumerHandle::Reader> |
| 452 SharedMemoryDataConsumerHandle::obtainReader(Client* client) { | 456 SharedMemoryDataConsumerHandle::obtainReader(Client* client) { |
| 453 return base::WrapUnique(new ReaderImpl(context_, client)); | 457 return base::WrapUnique(new ReaderImpl(context_, client)); |
| 454 } | 458 } |
| 455 | 459 |
| 456 const char* SharedMemoryDataConsumerHandle::debugName() const { | 460 const char* SharedMemoryDataConsumerHandle::debugName() const { |
| 457 return "SharedMemoryDataConsumerHandle"; | 461 return "SharedMemoryDataConsumerHandle"; |
| 458 } | 462 } |
| 459 | 463 |
| 460 } // namespace content | 464 } // namespace content |
| OLD | NEW |