Chromium Code Reviews| 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 "modules/fetch/ReadableStreamDataConsumerHandle.h" | 5 #include "modules/fetch/ReadableStreamDataConsumerHandle.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
| 9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 OnRejected(ScriptState* scriptState, PassRefPtr<ReadingContext> context) | 110 OnRejected(ScriptState* scriptState, PassRefPtr<ReadingContext> context) |
| 111 : ScriptFunction(scriptState), m_readingContext(context) {} | 111 : ScriptFunction(scriptState), m_readingContext(context) {} |
| 112 | 112 |
| 113 RefPtr<ReadingContext> m_readingContext; | 113 RefPtr<ReadingContext> m_readingContext; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 class ReaderImpl final : public FetchDataConsumerHandle::Reader { | 116 class ReaderImpl final : public FetchDataConsumerHandle::Reader { |
| 117 public: | 117 public: |
| 118 ReaderImpl(PassRefPtr<ReadingContext> context, Client* client) | 118 ReaderImpl(PassRefPtr<ReadingContext> context, Client* client, std::uniq ue_ptr<WebTaskRunner> readerTaskRunner) |
| 119 : m_readingContext(context) | 119 : m_readingContext(context) |
| 120 { | 120 { |
| 121 m_readingContext->attachReader(client); | 121 m_readingContext->attachReader(client, std::move(readerTaskRunner)); |
| 122 } | 122 } |
| 123 ~ReaderImpl() override | 123 ~ReaderImpl() override |
| 124 { | 124 { |
| 125 m_readingContext->detachReader(); | 125 m_readingContext->detachReader(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 Result beginRead(const void** buffer, Flags, size_t* available) override | 128 Result beginRead(const void** buffer, Flags, size_t* available) override |
| 129 { | 129 { |
| 130 return m_readingContext->beginRead(buffer, available); | 130 return m_readingContext->beginRead(buffer, available); |
| 131 } | 131 } |
| 132 | 132 |
| 133 Result endRead(size_t readSize) override | 133 Result endRead(size_t readSize) override |
| 134 { | 134 { |
| 135 return m_readingContext->endRead(readSize); | 135 return m_readingContext->endRead(readSize); |
| 136 } | 136 } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 RefPtr<ReadingContext> m_readingContext; | 139 RefPtr<ReadingContext> m_readingContext; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 static PassRefPtr<ReadingContext> create(ScriptState* scriptState, ScriptVal ue streamReader) | 142 static PassRefPtr<ReadingContext> create(ScriptState* scriptState, ScriptVal ue streamReader) |
| 143 { | 143 { |
| 144 return adoptRef(new ReadingContext(scriptState, streamReader)); | 144 return adoptRef(new ReadingContext(scriptState, streamReader)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void attachReader(WebDataConsumerHandle::Client* client) | 147 void attachReader(WebDataConsumerHandle::Client* client, std::unique_ptr<Web TaskRunner> readerTaskRunner) |
| 148 { | 148 { |
| 149 m_client = client; | 149 m_client = client; |
| 150 m_readerTaskRunner = std::move(readerTaskRunner); | |
| 150 notifyLater(); | 151 notifyLater(); |
| 151 } | 152 } |
| 152 | 153 |
| 153 void detachReader() | 154 void detachReader() |
| 154 { | 155 { |
| 155 m_client = nullptr; | 156 m_client = nullptr; |
| 156 } | 157 } |
| 157 | 158 |
| 158 Result beginRead(const void** buffer, size_t* available) | 159 Result beginRead(const void** buffer, size_t* available) |
| 159 { | 160 { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 void notify() | 236 void notify() |
| 236 { | 237 { |
| 237 if (!m_client) | 238 if (!m_client) |
| 238 return; | 239 return; |
| 239 m_client->didGetReadable(); | 240 m_client->didGetReadable(); |
| 240 } | 241 } |
| 241 | 242 |
| 242 void notifyLater() | 243 void notifyLater() |
| 243 { | 244 { |
| 244 ASSERT(m_client); | 245 ASSERT(m_client); |
| 245 Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK _FROM_HERE, WTF::bind(&ReadingContext::notify, PassRefPtr<ReadingContext>(this)) ); | 246 m_readerTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(&ReadingContext: :notify, PassRefPtr<ReadingContext>(this))); |
|
haraken
2016/07/27 11:05:25
For example, you can avoid adding m_readerTaskRunn
tzik
2016/07/27 14:59:41
Done.
Frame/Document/ScriptState seem not availabl
| |
| 246 } | 247 } |
| 247 | 248 |
| 248 private: | 249 private: |
| 249 ReadingContext(ScriptState* scriptState, ScriptValue streamReader) | 250 ReadingContext(ScriptState* scriptState, ScriptValue streamReader) |
| 250 : m_reader(scriptState->isolate(), streamReader.v8Value()) | 251 : m_reader(scriptState->isolate(), streamReader.v8Value()) |
| 251 , m_scriptState(scriptState) | 252 , m_scriptState(scriptState) |
| 252 , m_client(nullptr) | 253 , m_client(nullptr) |
| 253 , m_pendingOffset(0) | 254 , m_pendingOffset(0) |
| 254 , m_isReading(false) | 255 , m_isReading(false) |
| 255 , m_isDone(false) | 256 , m_isDone(false) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 273 data.GetParameter()->onCollected(); | 274 data.GetParameter()->onCollected(); |
| 274 } | 275 } |
| 275 | 276 |
| 276 // |m_reader| is a weak persistent. It should be kept alive by someone | 277 // |m_reader| is a weak persistent. It should be kept alive by someone |
| 277 // outside of ReadableStreamDataConsumerHandle. | 278 // outside of ReadableStreamDataConsumerHandle. |
| 278 // Holding a ScopedPersistent here is safe in terms of cross-world wrapper | 279 // Holding a ScopedPersistent here is safe in terms of cross-world wrapper |
| 279 // leakage because we read only Uint8Array chunks from the reader. | 280 // leakage because we read only Uint8Array chunks from the reader. |
| 280 ScopedPersistent<v8::Value> m_reader; | 281 ScopedPersistent<v8::Value> m_reader; |
| 281 RefPtr<ScriptState> m_scriptState; | 282 RefPtr<ScriptState> m_scriptState; |
| 282 WebDataConsumerHandle::Client* m_client; | 283 WebDataConsumerHandle::Client* m_client; |
| 284 std::unique_ptr<WebTaskRunner> m_readerTaskRunner; | |
| 283 Persistent<DOMUint8Array> m_pendingBuffer; | 285 Persistent<DOMUint8Array> m_pendingBuffer; |
| 284 size_t m_pendingOffset; | 286 size_t m_pendingOffset; |
| 285 bool m_isReading; | 287 bool m_isReading; |
| 286 bool m_isDone; | 288 bool m_isDone; |
| 287 bool m_hasError; | 289 bool m_hasError; |
| 288 }; | 290 }; |
| 289 | 291 |
| 290 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState* scriptState, ScriptValue streamReader) | 292 ReadableStreamDataConsumerHandle::ReadableStreamDataConsumerHandle(ScriptState* scriptState, ScriptValue streamReader) |
| 291 : m_readingContext(ReadingContext::create(scriptState, streamReader)) | 293 : m_readingContext(ReadingContext::create(scriptState, streamReader)) |
| 292 { | 294 { |
| 293 } | 295 } |
| 294 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; | 296 ReadableStreamDataConsumerHandle::~ReadableStreamDataConsumerHandle() = default; |
| 295 | 297 |
| 296 std::unique_ptr<FetchDataConsumerHandle::Reader> ReadableStreamDataConsumerHandl e::obtainFetchDataReader(Client* client) | 298 std::unique_ptr<FetchDataConsumerHandle::Reader> ReadableStreamDataConsumerHandl e::obtainFetchDataReader(Client* client, std::unique_ptr<WebTaskRunner> readerTa skRunner) |
| 297 { | 299 { |
| 298 return WTF::wrapUnique(new ReadingContext::ReaderImpl(m_readingContext, clie nt)); | 300 return WTF::wrapUnique(new ReadingContext::ReaderImpl(m_readingContext, clie nt, std::move(readerTaskRunner))); |
| 299 } | 301 } |
| 300 | 302 |
| 301 } // namespace blink | 303 } // namespace blink |
| OLD | NEW |