| 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 "content/child/web_data_consumer_handle_impl.h" | 5 #include "content/child/web_data_consumer_handle_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "components/scheduler/child/web_task_runner_impl.h" |
| 16 #include "mojo/public/c/system/types.h" | 17 #include "mojo/public/c/system/types.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 using Result = blink::WebDataConsumerHandle::Result; | 21 using Result = blink::WebDataConsumerHandle::Result; |
| 21 | 22 |
| 22 class WebDataConsumerHandleImpl::Context | 23 class WebDataConsumerHandleImpl::Context |
| 23 : public base::RefCountedThreadSafe<Context> { | 24 : public base::RefCountedThreadSafe<Context> { |
| 24 public: | 25 public: |
| 25 explicit Context(Handle handle) : handle_(std::move(handle)) {} | 26 explicit Context(Handle handle) : handle_(std::move(handle)) {} |
| 26 | 27 |
| 27 const Handle& handle() { return handle_; } | 28 const Handle& handle() { return handle_; } |
| 28 | 29 |
| 29 private: | 30 private: |
| 30 friend class base::RefCountedThreadSafe<Context>; | 31 friend class base::RefCountedThreadSafe<Context>; |
| 31 ~Context() {} | 32 ~Context() {} |
| 32 Handle handle_; | 33 Handle handle_; |
| 33 | 34 |
| 34 DISALLOW_COPY_AND_ASSIGN(Context); | 35 DISALLOW_COPY_AND_ASSIGN(Context); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 WebDataConsumerHandleImpl::ReaderImpl::ReaderImpl( | 38 WebDataConsumerHandleImpl::ReaderImpl::ReaderImpl( |
| 38 scoped_refptr<Context> context, | 39 scoped_refptr<Context> context, |
| 39 Client* client) | 40 Client* client, |
| 40 : context_(context), client_(client) { | 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 42 : context_(context), |
| 43 handle_watcher_(std::move(task_runner)), |
| 44 client_(client) { |
| 41 if (client_) | 45 if (client_) |
| 42 StartWatching(); | 46 StartWatching(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 WebDataConsumerHandleImpl::ReaderImpl::~ReaderImpl() { | 49 WebDataConsumerHandleImpl::ReaderImpl::~ReaderImpl() { |
| 46 } | 50 } |
| 47 | 51 |
| 48 Result WebDataConsumerHandleImpl::ReaderImpl::read(void* data, | 52 Result WebDataConsumerHandleImpl::ReaderImpl::read(void* data, |
| 49 size_t size, | 53 size_t size, |
| 50 Flags flags, | 54 Flags flags, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 client_->didGetReadable(); | 124 client_->didGetReadable(); |
| 121 } | 125 } |
| 122 | 126 |
| 123 WebDataConsumerHandleImpl::WebDataConsumerHandleImpl(Handle handle) | 127 WebDataConsumerHandleImpl::WebDataConsumerHandleImpl(Handle handle) |
| 124 : context_(new Context(std::move(handle))) {} | 128 : context_(new Context(std::move(handle))) {} |
| 125 | 129 |
| 126 WebDataConsumerHandleImpl::~WebDataConsumerHandleImpl() { | 130 WebDataConsumerHandleImpl::~WebDataConsumerHandleImpl() { |
| 127 } | 131 } |
| 128 | 132 |
| 129 std::unique_ptr<blink::WebDataConsumerHandle::Reader> | 133 std::unique_ptr<blink::WebDataConsumerHandle::Reader> |
| 130 WebDataConsumerHandleImpl::obtainReader(Client* client) { | 134 WebDataConsumerHandleImpl::obtainReader( |
| 131 return base::WrapUnique(new ReaderImpl(context_, client)); | 135 Client* client, |
| 136 std::unique_ptr<blink::WebTaskRunner> reader_task_runner) { |
| 137 scoped_refptr<base::SingleThreadTaskRunner> task_runner; |
| 138 if (reader_task_runner) { |
| 139 task_runner = |
| 140 scheduler::WebTaskRunnerImpl::GetBaseTaskRunner(*reader_task_runner); |
| 141 } else { |
| 142 task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 143 } |
| 144 |
| 145 return base::WrapUnique(new ReaderImpl(context_, client, |
| 146 std::move(task_runner))); |
| 132 } | 147 } |
| 133 | 148 |
| 134 const char* WebDataConsumerHandleImpl::debugName() const { | 149 const char* WebDataConsumerHandleImpl::debugName() const { |
| 135 return "WebDataConsumerHandleImpl"; | 150 return "WebDataConsumerHandleImpl"; |
| 136 } | 151 } |
| 137 | 152 |
| 138 } // namespace content | 153 } // namespace content |
| OLD | NEW |