Chromium Code Reviews| Index: Source/modules/fetch/CompositeDataConsumerHandle.h |
| diff --git a/Source/modules/fetch/CompositeDataConsumerHandle.h b/Source/modules/fetch/CompositeDataConsumerHandle.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..94a7692e50d76fb4aa5421d15c3b0f4c24b4061e |
| --- /dev/null |
| +++ b/Source/modules/fetch/CompositeDataConsumerHandle.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CompositeDataConsumerHandle_h |
| +#define CompositeDataConsumerHandle_h |
| + |
| +#include "public/platform/WebDataConsumerHandle.h" |
| +#include "wtf/OwnPtr.h" |
| +#include "wtf/PassOwnPtr.h" |
| +#include "wtf/RefPtr.h" |
| + |
| +namespace blink { |
| + |
| +class WebThread; |
| + |
| +// This is a utility class to construct a composite data consumer handle. It |
| +// ownes a web data consumer handle and delegates methods. A user can update |
|
hiroshige
2015/06/03 08:45:05
nit: s/ownes/owns/
yhirano
2015/06/04 05:43:02
Done.
|
| +// the handle by using |update| method. |
| +class CompositeDataConsumerHandle final : public WebDataConsumerHandle { |
| +public: |
| + static PassOwnPtr<CompositeDataConsumerHandle> create(PassOwnPtr<WebDataConsumerHandle> handle) |
| + { |
| + return adoptPtr(new CompositeDataConsumerHandle(handle)); |
| + } |
| + ~CompositeDataConsumerHandle() override; |
| + |
| + Result read(void* data, size_t /* size */, Flags, size_t* readSize) override; |
| + Result beginRead(const void** buffer, Flags, size_t* available) override; |
| + Result endRead(size_t readSize) override; |
| + void registerClient(Client* /* client */) override; |
| + void unregisterClient() override; |
| + |
| + // This function should be called on the thread on which this object |
| + // was created. |
|
hiroshige
2015/06/03 08:45:05
Why does this thread restriction exist?
From the c
yhirano
2015/06/04 05:43:02
I would like to leave a future optimization opport
|
| + void update(PassOwnPtr<WebDataConsumerHandle>); |
| + |
| + // Returns a handle that returns ShouldWait for read / beginRead / endRead |
| + // operations. |
| + static PassOwnPtr<WebDataConsumerHandle> createWaitingHandle(); |
|
hiroshige
2015/06/03 08:45:05
It would be better to add a comment explaining why
yhirano
2015/06/04 05:43:02
Done.
|
| + |
| + // Returns a handle that returns Done for read / beginRead / endRead |
| + // operations. |
| + static PassOwnPtr<WebDataConsumerHandle> createDoneHandle(); |
| + |
| +private: |
| + explicit CompositeDataConsumerHandle(PassOwnPtr<WebDataConsumerHandle>); |
| + |
| + class MutexHolder; |
| + void updateInternal(PassOwnPtr<WebDataConsumerHandle>); |
| + static void updateOnTheRightThread(CompositeDataConsumerHandle*, PassOwnPtr<WebDataConsumerHandle>, PassRefPtr<MutexHolder>); |
| + |
| + // TODO(yhirano): Consider using atomic operations instead of mutex if |
| + // possible. |
| + OwnPtr<WebDataConsumerHandle> m_handle; |
| + RefPtr<MutexHolder> m_mutex; |
| + Client* m_client; |
| + WebThread* m_clientThread; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // CompositeDataConsumerHandle_h |