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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/CompositeDataConsumerHandle.h" | 6 #include "modules/fetch/CompositeDataConsumerHandle.h" |
| 7 | 7 |
| 8 #include "platform/Task.h" | 8 #include "platform/Task.h" |
| 9 #include "platform/ThreadSafeFunctional.h" | 9 #include "platform/ThreadSafeFunctional.h" |
| 10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebThread.h" | 11 #include "public/platform/WebThread.h" |
| 12 #include "public/platform/WebTraceLocation.h" | 12 #include "public/platform/WebTraceLocation.h" |
| 13 #include "wtf/Functional.h" | 13 #include "wtf/Functional.h" |
|
yhirano
2015/06/17 04:13:34
You don't need this since bind is gone.
hiroshige
2015/06/17 08:30:23
Done.
| |
| 14 #include "wtf/Locker.h" | 14 #include "wtf/Locker.h" |
| 15 #include "wtf/ThreadSafeRefCounted.h" | 15 #include "wtf/ThreadSafeRefCounted.h" |
| 16 #include "wtf/ThreadingPrimitives.h" | 16 #include "wtf/ThreadingPrimitives.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 using Result = WebDataConsumerHandle::Result; | 20 using Result = WebDataConsumerHandle::Result; |
| 21 | 21 |
| 22 namespace { | |
| 23 | |
| 24 class WaitingHandle final : public WebDataConsumerHandle { | |
| 25 private: | |
| 26 class ReaderImpl final : public WebDataConsumerHandle::Reader { | |
| 27 public: | |
| 28 Result read(void*, size_t, WebDataConsumerHandle::Flags, size_t *readSiz e) override | |
| 29 { | |
| 30 *readSize = 0; | |
| 31 return ShouldWait; | |
| 32 } | |
| 33 Result beginRead(const void** buffer, WebDataConsumerHandle::Flags, size _t *available) override | |
| 34 { | |
| 35 *available = 0; | |
| 36 *buffer = nullptr; | |
| 37 return ShouldWait; | |
| 38 } | |
| 39 Result endRead(size_t) override | |
| 40 { | |
| 41 return UnexpectedError; | |
| 42 } | |
| 43 }; | |
| 44 Reader* obtainReaderInternal(Client*) override { return new ReaderImpl; } | |
| 45 }; | |
| 46 | |
| 47 class DoneHandle final : public WebDataConsumerHandle { | |
| 48 private: | |
| 49 class ReaderImpl final : public WebDataConsumerHandle::Reader { | |
| 50 public: | |
| 51 explicit ReaderImpl(Client* client) : m_factory(this) | |
| 52 { | |
| 53 if (!client) | |
| 54 return; | |
| 55 // Note we don't need thread safety here because this object is | |
| 56 // bound to the current thread. | |
| 57 Platform::current()->currentThread()->postTask(FROM_HERE, new Task(b ind(&ReaderImpl::notify, m_factory.createWeakPtr(), client))); | |
| 58 } | |
| 59 Result read(void*, size_t, WebDataConsumerHandle::Flags, size_t *readSiz e) override | |
| 60 { | |
| 61 *readSize = 0; | |
| 62 return Done; | |
| 63 } | |
| 64 Result beginRead(const void** buffer, WebDataConsumerHandle::Flags, size _t *available) override | |
| 65 { | |
| 66 *available = 0; | |
| 67 *buffer = nullptr; | |
| 68 return Done; | |
| 69 } | |
| 70 Result endRead(size_t) override | |
| 71 { | |
| 72 return UnexpectedError; | |
| 73 } | |
| 74 | |
| 75 private: | |
| 76 void notify(Client* client) | |
| 77 { | |
| 78 client->didGetReadable(); | |
| 79 } | |
| 80 | |
| 81 WeakPtrFactory<ReaderImpl> m_factory; | |
| 82 }; | |
| 83 | |
| 84 Reader* obtainReaderInternal(Client* client) override { return new ReaderImp l(client); } | |
| 85 }; | |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 89 class CompositeDataConsumerHandle::ReaderImpl final : public WebDataConsumerHand le::Reader { | 22 class CompositeDataConsumerHandle::ReaderImpl final : public WebDataConsumerHand le::Reader { |
| 90 public: | 23 public: |
| 91 explicit ReaderImpl(PassRefPtr<Context>); | 24 explicit ReaderImpl(PassRefPtr<Context>); |
| 92 ~ReaderImpl() override; | 25 ~ReaderImpl() override; |
| 93 Result read(void* data, size_t /* size */, Flags, size_t* readSize) override ; | 26 Result read(void* data, size_t /* size */, Flags, size_t* readSize) override ; |
| 94 Result beginRead(const void** buffer, Flags, size_t* available) override; | 27 Result beginRead(const void** buffer, Flags, size_t* available) override; |
| 95 Result endRead(size_t readSize) override; | 28 Result endRead(size_t readSize) override; |
| 96 | 29 |
| 97 private: | 30 private: |
| 98 RefPtr<Context> m_context; | 31 RefPtr<Context> m_context; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 { | 193 { |
| 261 return m_context->obtainReader(client).leakPtr(); | 194 return m_context->obtainReader(client).leakPtr(); |
| 262 } | 195 } |
| 263 | 196 |
| 264 void CompositeDataConsumerHandle::update(PassOwnPtr<WebDataConsumerHandle> handl e) | 197 void CompositeDataConsumerHandle::update(PassOwnPtr<WebDataConsumerHandle> handl e) |
| 265 { | 198 { |
| 266 ASSERT(handle); | 199 ASSERT(handle); |
| 267 m_context->update(handle); | 200 m_context->update(handle); |
| 268 } | 201 } |
| 269 | 202 |
| 270 PassOwnPtr<WebDataConsumerHandle> CompositeDataConsumerHandle::createWaitingHand le() | |
| 271 { | |
| 272 return adoptPtr(new WaitingHandle); | |
| 273 } | |
| 274 | |
| 275 PassOwnPtr<WebDataConsumerHandle> CompositeDataConsumerHandle::createDoneHandle( ) | |
| 276 { | |
| 277 return adoptPtr(new DoneHandle); | |
| 278 } | |
| 279 | |
| 280 } // namespace blink | 203 } // namespace blink |
| OLD | NEW |