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 #ifndef CompositeDataConsumerHandle_h | 5 #ifndef CompositeDataConsumerHandle_h |
6 #define CompositeDataConsumerHandle_h | 6 #define CompositeDataConsumerHandle_h |
7 | 7 |
8 #include "modules/ModulesExport.h" | 8 #include "modules/ModulesExport.h" |
9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 #include "public/platform/WebDataConsumerHandle.h" | 10 #include "public/platform/WebDataConsumerHandle.h" |
11 #include "wtf/Allocator.h" | 11 #include "wtf/Allocator.h" |
12 #include "wtf/PtrUtil.h" | 12 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/PassOwnPtr.h" |
13 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
14 #include <memory> | |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 class WebThread; | 18 class WebThread; |
19 | 19 |
20 // This is a utility class to construct a composite data consumer handle. It | 20 // This is a utility class to construct a composite data consumer handle. It |
21 // owns a web data consumer handle and delegates methods. A user can update | 21 // owns a web data consumer handle and delegates methods. A user can update |
22 // the handle by using |update| method. | 22 // the handle by using |update| method. |
23 class MODULES_EXPORT CompositeDataConsumerHandle final : public WebDataConsumerH
andle { | 23 class MODULES_EXPORT CompositeDataConsumerHandle final : public WebDataConsumerH
andle { |
24 WTF_MAKE_NONCOPYABLE(CompositeDataConsumerHandle); | 24 WTF_MAKE_NONCOPYABLE(CompositeDataConsumerHandle); |
25 USING_FAST_MALLOC(CompositeDataConsumerHandle); | 25 USING_FAST_MALLOC(CompositeDataConsumerHandle); |
26 class Context; | 26 class Context; |
27 public: | 27 public: |
28 // An Updater is bound to the creator thread. | 28 // An Updater is bound to the creator thread. |
29 class MODULES_EXPORT Updater final : public GarbageCollectedFinalized<Update
r> { | 29 class MODULES_EXPORT Updater final : public GarbageCollectedFinalized<Update
r> { |
30 public: | 30 public: |
31 explicit Updater(PassRefPtr<Context>); | 31 explicit Updater(PassRefPtr<Context>); |
32 ~Updater(); | 32 ~Updater(); |
33 | 33 |
34 // |handle| must not be null and must not be locked. | 34 // |handle| must not be null and must not be locked. |
35 void update(std::unique_ptr<WebDataConsumerHandle> /* handle */); | 35 void update(PassOwnPtr<WebDataConsumerHandle> /* handle */); |
36 DEFINE_INLINE_TRACE() { } | 36 DEFINE_INLINE_TRACE() { } |
37 | 37 |
38 private: | 38 private: |
39 RefPtr<Context> m_context; | 39 RefPtr<Context> m_context; |
40 #if ENABLE(ASSERT) | 40 #if ENABLE(ASSERT) |
41 WebThread* const m_thread; | 41 WebThread* const m_thread; |
42 #endif | 42 #endif |
43 }; | 43 }; |
44 | 44 |
45 // Returns a handle and stores the associated updater to |*updater|. The | 45 // Returns a handle and stores the associated updater to |*updater|. The |
46 // associated updater will be bound to the calling thread. | 46 // associated updater will be bound to the calling thread. |
47 // |handle| must not be null and must not be locked. | 47 // |handle| must not be null and must not be locked. |
48 template<typename T> | 48 template<typename T> |
49 static std::unique_ptr<WebDataConsumerHandle> create(std::unique_ptr<WebData
ConsumerHandle> handle, T* updater) | 49 static PassOwnPtr<WebDataConsumerHandle> create(PassOwnPtr<WebDataConsumerHa
ndle> handle, T* updater) |
50 { | 50 { |
51 ASSERT(handle); | 51 ASSERT(handle); |
52 Updater* u = nullptr; | 52 Updater* u = nullptr; |
53 std::unique_ptr<CompositeDataConsumerHandle> p = wrapUnique(new Composit
eDataConsumerHandle(std::move(handle), &u)); | 53 OwnPtr<CompositeDataConsumerHandle> p = adoptPtr(new CompositeDataConsum
erHandle(std::move(handle), &u)); |
54 *updater = u; | 54 *updater = u; |
55 return std::move(p); | 55 return std::move(p); |
56 } | 56 } |
57 ~CompositeDataConsumerHandle() override; | 57 ~CompositeDataConsumerHandle() override; |
58 | 58 |
59 private: | 59 private: |
60 class ReaderImpl; | 60 class ReaderImpl; |
61 Reader* obtainReaderInternal(Client*) override; | 61 Reader* obtainReaderInternal(Client*) override; |
62 | 62 |
63 const char* debugName() const override { return "CompositeDataConsumerHandle
"; } | 63 const char* debugName() const override { return "CompositeDataConsumerHandle
"; } |
64 | 64 |
65 CompositeDataConsumerHandle(std::unique_ptr<WebDataConsumerHandle>, Updater*
*); | 65 CompositeDataConsumerHandle(PassOwnPtr<WebDataConsumerHandle>, Updater**); |
66 | 66 |
67 RefPtr<Context> m_context; | 67 RefPtr<Context> m_context; |
68 }; | 68 }; |
69 | 69 |
70 } // namespace blink | 70 } // namespace blink |
71 | 71 |
72 #endif // CompositeDataConsumerHandle_h | 72 #endif // CompositeDataConsumerHandle_h |
OLD | NEW |