| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "components/scheduler/child/web_task_runner_impl.h" |
| 18 #include "content/public/child/fixed_received_data.h" | 19 #include "content/public/child/fixed_received_data.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 class DelegateThreadSafeReceivedData final | 25 class DelegateThreadSafeReceivedData final |
| 25 : public RequestPeer::ThreadSafeReceivedData { | 26 : public RequestPeer::ThreadSafeReceivedData { |
| 26 public: | 27 public: |
| 27 explicit DelegateThreadSafeReceivedData( | 28 explicit DelegateThreadSafeReceivedData( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return first_offset_; | 109 return first_offset_; |
| 109 } | 110 } |
| 110 Result result() const { | 111 Result result() const { |
| 111 lock_.AssertAcquired(); | 112 lock_.AssertAcquired(); |
| 112 return result_; | 113 return result_; |
| 113 } | 114 } |
| 114 void set_result(Result r) { | 115 void set_result(Result r) { |
| 115 lock_.AssertAcquired(); | 116 lock_.AssertAcquired(); |
| 116 result_ = r; | 117 result_ = r; |
| 117 } | 118 } |
| 118 void AcquireReaderLock(Client* client) { | 119 void AcquireReaderLock( |
| 120 Client* client, |
| 121 scoped_refptr<base::SingleThreadTaskRunner> notification_task_runner) { |
| 119 lock_.AssertAcquired(); | 122 lock_.AssertAcquired(); |
| 120 DCHECK(!notification_task_runner_); | 123 DCHECK(!notification_task_runner_); |
| 121 DCHECK(!client_); | 124 DCHECK(!client_); |
| 122 notification_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 125 notification_task_runner_ = std::move(notification_task_runner); |
| 123 client_ = client; | 126 client_ = client; |
| 124 if (client && !(IsEmpty() && result() == Ok)) { | 127 if (client && !(IsEmpty() && result() == Ok)) { |
| 125 // We cannot notify synchronously because the user doesn't have the reader | 128 // We cannot notify synchronously because the user doesn't have the reader |
| 126 // yet. | 129 // yet. |
| 127 notification_task_runner_->PostTask( | 130 notification_task_runner_->PostTask( |
| 128 FROM_HERE, base::Bind(&Context::NotifyInternal, this, false)); | 131 FROM_HERE, base::Bind(&Context::NotifyInternal, this, false)); |
| 129 } | 132 } |
| 130 } | 133 } |
| 131 void ReleaseReaderLock() { | 134 void ReleaseReaderLock() { |
| 132 lock_.AssertAcquired(); | 135 lock_.AssertAcquired(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 358 |
| 356 context_->ResetOnReaderDetached(); | 359 context_->ResetOnReaderDetached(); |
| 357 // We cannot issue the notification synchronously because this function can | 360 // We cannot issue the notification synchronously because this function can |
| 358 // be called in the client's callback. | 361 // be called in the client's callback. |
| 359 context_->PostNotify(); | 362 context_->PostNotify(); |
| 360 } | 363 } |
| 361 } | 364 } |
| 362 | 365 |
| 363 SharedMemoryDataConsumerHandle::ReaderImpl::ReaderImpl( | 366 SharedMemoryDataConsumerHandle::ReaderImpl::ReaderImpl( |
| 364 scoped_refptr<Context> context, | 367 scoped_refptr<Context> context, |
| 365 Client* client) | 368 Client* client, |
| 369 scoped_refptr<base::SingleThreadTaskRunner> reader_task_runner) |
| 366 : context_(context) { | 370 : context_(context) { |
| 367 base::AutoLock lock(context_->lock()); | 371 base::AutoLock lock(context_->lock()); |
| 368 DCHECK(!context_->is_handle_locked()); | 372 DCHECK(!context_->is_handle_locked()); |
| 369 context_->AcquireReaderLock(client); | 373 context_->AcquireReaderLock(client, std::move(reader_task_runner)); |
| 370 } | 374 } |
| 371 | 375 |
| 372 SharedMemoryDataConsumerHandle::ReaderImpl::~ReaderImpl() { | 376 SharedMemoryDataConsumerHandle::ReaderImpl::~ReaderImpl() { |
| 373 base::AutoLock lock(context_->lock()); | 377 base::AutoLock lock(context_->lock()); |
| 374 context_->ReleaseReaderLock(); | 378 context_->ReleaseReaderLock(); |
| 375 context_->ClearIfNecessary(); | 379 context_->ClearIfNecessary(); |
| 376 } | 380 } |
| 377 | 381 |
| 378 Result SharedMemoryDataConsumerHandle::ReaderImpl::read( | 382 Result SharedMemoryDataConsumerHandle::ReaderImpl::read( |
| 379 void* data, | 383 void* data, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 writer->reset(new Writer(context_, mode)); | 470 writer->reset(new Writer(context_, mode)); |
| 467 } | 471 } |
| 468 | 472 |
| 469 SharedMemoryDataConsumerHandle::~SharedMemoryDataConsumerHandle() { | 473 SharedMemoryDataConsumerHandle::~SharedMemoryDataConsumerHandle() { |
| 470 base::AutoLock lock(context_->lock()); | 474 base::AutoLock lock(context_->lock()); |
| 471 context_->set_is_handle_active(false); | 475 context_->set_is_handle_active(false); |
| 472 context_->ClearIfNecessary(); | 476 context_->ClearIfNecessary(); |
| 473 } | 477 } |
| 474 | 478 |
| 475 std::unique_ptr<blink::WebDataConsumerHandle::Reader> | 479 std::unique_ptr<blink::WebDataConsumerHandle::Reader> |
| 476 SharedMemoryDataConsumerHandle::obtainReader(Client* client) { | 480 SharedMemoryDataConsumerHandle::obtainReader( |
| 477 return base::WrapUnique(new ReaderImpl(context_, client)); | 481 Client* client, |
| 482 std::unique_ptr<blink::WebTaskRunner> reader_task_runner) { |
| 483 scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
| 484 if (reader_task_runner) { |
| 485 task_runner = |
| 486 scheduler::WebTaskRunnerImpl::GetBaseTaskRunner(*reader_task_runner); |
| 487 } else { |
| 488 task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 489 } |
| 490 |
| 491 return base::WrapUnique(new ReaderImpl(context_, client, |
| 492 std::move(task_runner))); |
| 478 } | 493 } |
| 479 | 494 |
| 480 const char* SharedMemoryDataConsumerHandle::debugName() const { | 495 const char* SharedMemoryDataConsumerHandle::debugName() const { |
| 481 return "SharedMemoryDataConsumerHandle"; | 496 return "SharedMemoryDataConsumerHandle"; |
| 482 } | 497 } |
| 483 | 498 |
| 484 } // namespace content | 499 } // namespace content |
| OLD | NEW |