OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_CHILD_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ | 5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ |
6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ | 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ |
7 | 7 |
8 #include "content/common/indexed_db/indexed_db.mojom.h" | 8 #include "content/common/indexed_db/indexed_db.mojom.h" |
9 #include "mojo/public/cpp/bindings/associated_binding.h" | 9 #include "mojo/public/cpp/bindings/associated_binding.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 class WebIDBCallbacks; | 12 class WebIDBCallbacks; |
13 } | 13 } |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 class ThreadSafeSender; | 17 class WebIDBCursorImpl; |
18 | 18 |
19 // Implements the child-process end of the pipe used to deliver callbacks. It | 19 // Implements the child-process end of the pipe used to deliver callbacks. It |
20 // is owned by the IO thread. |callback_runner_| is used to post tasks back to | 20 // is owned by the IO thread. |callback_runner_| is used to post tasks back to |
21 // the thread which owns the blink::WebIDBCallbacks. | 21 // the thread which owns the blink::WebIDBCallbacks. |
22 class IndexedDBCallbacksImpl : public indexed_db::mojom::Callbacks { | 22 class IndexedDBCallbacksImpl : public indexed_db::mojom::Callbacks { |
23 public: | 23 public: |
24 enum : int64_t { kNoTransaction = -1 }; | 24 enum : int64_t { kNoTransaction = -1 }; |
25 | 25 |
26 // This class holds the parts of the internal state of IndexedDBCallbacksImpl | 26 // This class holds the parts of the internal state of IndexedDBCallbacksImpl |
27 // that must live on whatever renderer or worker thread the API is used from. | 27 // that must live on whatever renderer or worker thread the API is used from. |
28 class InternalState { | 28 class InternalState { |
29 public: | 29 public: |
30 InternalState(std::unique_ptr<blink::WebIDBCallbacks> callbacks, | 30 InternalState(std::unique_ptr<blink::WebIDBCallbacks> callbacks, |
31 int64_t transaction_id, | 31 int64_t transaction_id, |
32 scoped_refptr<base::SingleThreadTaskRunner> io_runner, | 32 base::WeakPtr<WebIDBCursorImpl> cursor_, |
dcheng
2016/11/17 03:46:23
Nit: cursor. Also const base::WeakPtr<>& (in theor
Reilly Grant (use Gerrit)
2016/11/17 20:04:52
Done.
| |
33 scoped_refptr<ThreadSafeSender> thread_safe_sender); | 33 scoped_refptr<base::SingleThreadTaskRunner> io_runner); |
34 ~InternalState(); | 34 ~InternalState(); |
35 | 35 |
36 void Error(int32_t code, const base::string16& message); | 36 void Error(int32_t code, const base::string16& message); |
37 void SuccessStringList(const std::vector<base::string16>& value); | 37 void SuccessStringList(const std::vector<base::string16>& value); |
38 void Blocked(int64_t existing_version); | 38 void Blocked(int64_t existing_version); |
39 void UpgradeNeeded(indexed_db::mojom::DatabaseAssociatedPtrInfo database, | 39 void UpgradeNeeded(indexed_db::mojom::DatabaseAssociatedPtrInfo database, |
40 int64_t old_version, | 40 int64_t old_version, |
41 blink::WebIDBDataLoss data_loss, | 41 blink::WebIDBDataLoss data_loss, |
42 const std::string& data_loss_message, | 42 const std::string& data_loss_message, |
43 const content::IndexedDBDatabaseMetadata& metadata); | 43 const content::IndexedDBDatabaseMetadata& metadata); |
44 void SuccessDatabase(indexed_db::mojom::DatabaseAssociatedPtrInfo database, | 44 void SuccessDatabase(indexed_db::mojom::DatabaseAssociatedPtrInfo database, |
45 const content::IndexedDBDatabaseMetadata& metadata); | 45 const content::IndexedDBDatabaseMetadata& metadata); |
46 void SuccessCursor(int32_t cursor_id, | 46 void SuccessCursor(indexed_db::mojom::CursorAssociatedPtrInfo cursor, |
47 const IndexedDBKey& key, | 47 const IndexedDBKey& key, |
48 const IndexedDBKey& primary_key, | 48 const IndexedDBKey& primary_key, |
49 indexed_db::mojom::ValuePtr value); | 49 indexed_db::mojom::ValuePtr value); |
50 void SuccessValue(indexed_db::mojom::ReturnValuePtr value); | 50 void SuccessValue(indexed_db::mojom::ReturnValuePtr value); |
51 void SuccessCursorContinue(const IndexedDBKey& key, | |
52 const IndexedDBKey& primary_key, | |
53 indexed_db::mojom::ValuePtr value); | |
54 void SuccessCursorPrefetch(const std::vector<IndexedDBKey>& keys, | |
55 const std::vector<IndexedDBKey>& primary_keys, | |
56 std::vector<indexed_db::mojom::ValuePtr> values); | |
51 void SuccessArray(std::vector<indexed_db::mojom::ReturnValuePtr> values); | 57 void SuccessArray(std::vector<indexed_db::mojom::ReturnValuePtr> values); |
52 void SuccessKey(const IndexedDBKey& key); | 58 void SuccessKey(const IndexedDBKey& key); |
53 void SuccessInteger(int64_t value); | 59 void SuccessInteger(int64_t value); |
54 void Success(); | 60 void Success(); |
55 | 61 |
56 private: | 62 private: |
57 std::unique_ptr<blink::WebIDBCallbacks> callbacks_; | 63 std::unique_ptr<blink::WebIDBCallbacks> callbacks_; |
58 int64_t transaction_id_; | 64 int64_t transaction_id_; |
65 base::WeakPtr<WebIDBCursorImpl> cursor_; | |
59 scoped_refptr<base::SingleThreadTaskRunner> io_runner_; | 66 scoped_refptr<base::SingleThreadTaskRunner> io_runner_; |
60 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
61 | 67 |
62 DISALLOW_COPY_AND_ASSIGN(InternalState); | 68 DISALLOW_COPY_AND_ASSIGN(InternalState); |
63 }; | 69 }; |
64 | 70 |
65 IndexedDBCallbacksImpl(std::unique_ptr<blink::WebIDBCallbacks> callbacks, | 71 IndexedDBCallbacksImpl(std::unique_ptr<blink::WebIDBCallbacks> callbacks, |
66 int64_t transaction_id, | 72 int64_t transaction_id, |
67 scoped_refptr<base::SingleThreadTaskRunner> io_runner, | 73 base::WeakPtr<WebIDBCursorImpl> cursor, |
68 scoped_refptr<ThreadSafeSender> thread_safe_sender); | 74 scoped_refptr<base::SingleThreadTaskRunner> io_runner); |
69 ~IndexedDBCallbacksImpl() override; | 75 ~IndexedDBCallbacksImpl() override; |
70 | 76 |
71 // indexed_db::mojom::Callbacks implementation: | 77 // indexed_db::mojom::Callbacks implementation: |
72 void Error(int32_t code, const base::string16& message) override; | 78 void Error(int32_t code, const base::string16& message) override; |
73 void SuccessStringList(const std::vector<base::string16>& value) override; | 79 void SuccessStringList(const std::vector<base::string16>& value) override; |
74 void Blocked(int64_t existing_version) override; | 80 void Blocked(int64_t existing_version) override; |
75 void UpgradeNeeded( | 81 void UpgradeNeeded( |
76 indexed_db::mojom::DatabaseAssociatedPtrInfo database_info, | 82 indexed_db::mojom::DatabaseAssociatedPtrInfo database_info, |
77 int64_t old_version, | 83 int64_t old_version, |
78 blink::WebIDBDataLoss data_loss, | 84 blink::WebIDBDataLoss data_loss, |
79 const std::string& data_loss_message, | 85 const std::string& data_loss_message, |
80 const content::IndexedDBDatabaseMetadata& metadata) override; | 86 const content::IndexedDBDatabaseMetadata& metadata) override; |
81 void SuccessDatabase( | 87 void SuccessDatabase( |
82 indexed_db::mojom::DatabaseAssociatedPtrInfo database_info, | 88 indexed_db::mojom::DatabaseAssociatedPtrInfo database_info, |
83 const content::IndexedDBDatabaseMetadata& metadata) override; | 89 const content::IndexedDBDatabaseMetadata& metadata) override; |
84 void SuccessCursor(int32_t cursor_id, | 90 void SuccessCursor(indexed_db::mojom::CursorAssociatedPtrInfo cursor, |
85 const IndexedDBKey& key, | 91 const IndexedDBKey& key, |
86 const IndexedDBKey& primary_key, | 92 const IndexedDBKey& primary_key, |
87 indexed_db::mojom::ValuePtr value) override; | 93 indexed_db::mojom::ValuePtr value) override; |
88 void SuccessValue(indexed_db::mojom::ReturnValuePtr value) override; | 94 void SuccessValue(indexed_db::mojom::ReturnValuePtr value) override; |
95 void SuccessCursorContinue(const IndexedDBKey& key, | |
96 const IndexedDBKey& primary_key, | |
97 indexed_db::mojom::ValuePtr value) override; | |
98 void SuccessCursorPrefetch( | |
99 const std::vector<IndexedDBKey>& keys, | |
100 const std::vector<IndexedDBKey>& primary_keys, | |
101 std::vector<indexed_db::mojom::ValuePtr> values) override; | |
89 void SuccessArray( | 102 void SuccessArray( |
90 std::vector<indexed_db::mojom::ReturnValuePtr> values) override; | 103 std::vector<indexed_db::mojom::ReturnValuePtr> values) override; |
91 void SuccessKey(const IndexedDBKey& key) override; | 104 void SuccessKey(const IndexedDBKey& key) override; |
92 void SuccessInteger(int64_t value) override; | 105 void SuccessInteger(int64_t value) override; |
93 void Success() override; | 106 void Success() override; |
94 | 107 |
95 private: | 108 private: |
96 // |internal_state_| is owned by the thread on which |callback_runner_| | 109 // |internal_state_| is owned by the thread on which |callback_runner_| |
97 // executes tasks and must be destroyed there. | 110 // executes tasks and must be destroyed there. |
98 InternalState* internal_state_; | 111 InternalState* internal_state_; |
99 scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; | 112 scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; |
100 | 113 |
101 DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacksImpl); | 114 DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacksImpl); |
102 }; | 115 }; |
103 | 116 |
104 } // namespace content | 117 } // namespace content |
105 | 118 |
106 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ | 119 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_CALLBACKS_IMPL_H_ |
OLD | NEW |