Chromium Code Reviews| 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 |
| 23 namespace { | |
| 24 | |
| 25 scoped_refptr<base::SingleThreadTaskRunner> | |
| 26 GetTaskRunnerForDataConsumerHandleClient( | |
| 27 blink::WebDataConsumerHandle::Client* client) { | |
| 28 blink::WebTaskRunner* task_runner = | |
| 29 client ? client->getTaskRunner() : nullptr; | |
| 30 if (task_runner) | |
| 31 return scheduler::WebTaskRunnerImpl::GetBaseTaskRunner(*task_runner); | |
| 32 return base::ThreadTaskRunnerHandle::Get(); | |
|
kinuko
2016/07/28 15:41:31
ditto.
| |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 22 class WebDataConsumerHandleImpl::Context | 37 class WebDataConsumerHandleImpl::Context |
| 23 : public base::RefCountedThreadSafe<Context> { | 38 : public base::RefCountedThreadSafe<Context> { |
| 24 public: | 39 public: |
| 25 explicit Context(Handle handle) : handle_(std::move(handle)) {} | 40 explicit Context(Handle handle) : handle_(std::move(handle)) {} |
| 26 | 41 |
| 27 const Handle& handle() { return handle_; } | 42 const Handle& handle() { return handle_; } |
| 28 | 43 |
| 29 private: | 44 private: |
| 30 friend class base::RefCountedThreadSafe<Context>; | 45 friend class base::RefCountedThreadSafe<Context>; |
| 31 ~Context() {} | 46 ~Context() {} |
| 32 Handle handle_; | 47 Handle handle_; |
| 33 | 48 |
| 34 DISALLOW_COPY_AND_ASSIGN(Context); | 49 DISALLOW_COPY_AND_ASSIGN(Context); |
| 35 }; | 50 }; |
| 36 | 51 |
| 37 WebDataConsumerHandleImpl::ReaderImpl::ReaderImpl( | 52 WebDataConsumerHandleImpl::ReaderImpl::ReaderImpl( |
| 38 scoped_refptr<Context> context, | 53 scoped_refptr<Context> context, |
| 39 Client* client) | 54 Client* client) |
| 40 : context_(context), client_(client) { | 55 : context_(context), |
| 56 handle_watcher_(GetTaskRunnerForDataConsumerHandleClient(client)), | |
| 57 client_(client) { | |
| 41 if (client_) | 58 if (client_) |
| 42 StartWatching(); | 59 StartWatching(); |
| 43 } | 60 } |
| 44 | 61 |
| 45 WebDataConsumerHandleImpl::ReaderImpl::~ReaderImpl() { | 62 WebDataConsumerHandleImpl::ReaderImpl::~ReaderImpl() { |
| 46 } | 63 } |
| 47 | 64 |
| 48 Result WebDataConsumerHandleImpl::ReaderImpl::read(void* data, | 65 Result WebDataConsumerHandleImpl::ReaderImpl::read(void* data, |
| 49 size_t size, | 66 size_t size, |
| 50 Flags flags, | 67 Flags flags, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 std::unique_ptr<blink::WebDataConsumerHandle::Reader> | 146 std::unique_ptr<blink::WebDataConsumerHandle::Reader> |
| 130 WebDataConsumerHandleImpl::obtainReader(Client* client) { | 147 WebDataConsumerHandleImpl::obtainReader(Client* client) { |
| 131 return base::WrapUnique(new ReaderImpl(context_, client)); | 148 return base::WrapUnique(new ReaderImpl(context_, client)); |
| 132 } | 149 } |
| 133 | 150 |
| 134 const char* WebDataConsumerHandleImpl::debugName() const { | 151 const char* WebDataConsumerHandleImpl::debugName() const { |
| 135 return "WebDataConsumerHandleImpl"; | 152 return "WebDataConsumerHandleImpl"; |
| 136 } | 153 } |
| 137 | 154 |
| 138 } // namespace content | 155 } // namespace content |
| OLD | NEW |