OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <memory> |
9 | 9 |
10 #include <memory> | 10 #include "base/callback.h" |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 #include "base/logging.h" | |
15 #include "base/macros.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "base/strings/string16.h" | |
18 #include "content/browser/indexed_db/indexed_db_database_error.h" | |
19 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | |
20 #include "content/common/indexed_db/indexed_db_key.h" | |
21 #include "content/common/indexed_db/indexed_db_key_path.h" | |
22 #include "url/origin.h" | |
23 | 11 |
24 namespace content { | 12 namespace content { |
25 class IndexedDBBlobInfo; | 13 |
26 class IndexedDBConnection; | 14 class IndexedDBConnection; |
27 class IndexedDBCursor; | 15 class IndexedDBDatabaseError; |
28 class IndexedDBDatabase; | |
29 class IndexedDBDatabaseCallbacks; | |
30 struct IndexedDBDataLossInfo; | |
31 struct IndexedDBDatabaseMetadata; | 16 struct IndexedDBDatabaseMetadata; |
32 struct IndexedDBReturnValue; | |
33 struct IndexedDBValue; | |
34 | 17 |
35 class CONTENT_EXPORT IndexedDBCallbacks | 18 typedef base::Callback<void(std::unique_ptr<IndexedDBConnection> connection, |
36 : public base::RefCounted<IndexedDBCallbacks> { | 19 const content::IndexedDBDatabaseMetadata& metadata, |
37 public: | 20 const content::IndexedDBDatabaseError&)> |
38 // Simple payload responses | 21 OpenResultCallback; |
39 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | |
40 int32_t ipc_thread_id, | |
41 int32_t ipc_callbacks_id); | |
42 | 22 |
43 // IndexedDBCursor responses | 23 using DeleteResultCallback = |
44 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | 24 base::Callback<void(int64_t version, |
45 int32_t ipc_thread_id, | 25 const content::IndexedDBDatabaseError&)>; |
46 int32_t ipc_callbacks_id, | |
47 int32_t ipc_cursor_id); | |
48 | |
49 // IndexedDBDatabase responses | |
50 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host, | |
51 int32_t ipc_thread_id, | |
52 int32_t ipc_callbacks_id, | |
53 int32_t ipc_database_callbacks_id, | |
54 int64_t host_transaction_id, | |
55 const url::Origin& origin); | |
56 | |
57 virtual void OnError(const IndexedDBDatabaseError& error); | |
58 | |
59 // IndexedDBFactory::GetDatabaseNames | |
60 virtual void OnSuccess(const std::vector<base::string16>& string); | |
61 | |
62 // IndexedDBFactory::Open / DeleteDatabase | |
63 virtual void OnBlocked(int64_t existing_version); | |
64 | |
65 // IndexedDBFactory::Open | |
66 virtual void OnUpgradeNeeded( | |
67 int64_t old_version, | |
68 std::unique_ptr<IndexedDBConnection> connection, | |
69 const content::IndexedDBDatabaseMetadata& metadata, | |
70 const IndexedDBDataLossInfo& data_loss_info); | |
71 virtual void OnSuccess(std::unique_ptr<IndexedDBConnection> connection, | |
72 const content::IndexedDBDatabaseMetadata& metadata); | |
73 | |
74 // IndexedDBDatabase::OpenCursor | |
75 virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor, | |
76 const IndexedDBKey& key, | |
77 const IndexedDBKey& primary_key, | |
78 IndexedDBValue* value); | |
79 | |
80 // IndexedDBCursor::Continue / Advance | |
81 virtual void OnSuccess(const IndexedDBKey& key, | |
82 const IndexedDBKey& primary_key, | |
83 IndexedDBValue* value); | |
84 | |
85 // IndexedDBCursor::PrefetchContinue | |
86 virtual void OnSuccessWithPrefetch( | |
87 const std::vector<IndexedDBKey>& keys, | |
88 const std::vector<IndexedDBKey>& primary_keys, | |
89 std::vector<IndexedDBValue>* values); | |
90 | |
91 // IndexedDBDatabase::Get | |
92 // IndexedDBCursor::Advance | |
93 virtual void OnSuccess(IndexedDBReturnValue* value); | |
94 | |
95 // IndexedDBDatabase::GetAll | |
96 virtual void OnSuccessArray(std::vector<IndexedDBReturnValue>* values, | |
97 const IndexedDBKeyPath& key_path); | |
98 | |
99 // IndexedDBDatabase::Put / IndexedDBCursor::Update | |
100 virtual void OnSuccess(const IndexedDBKey& key); | |
101 | |
102 // IndexedDBDatabase::Count | |
103 // IndexedDBFactory::DeleteDatabase | |
104 // IndexedDBDatabase::DeleteRange | |
105 virtual void OnSuccess(int64_t value); | |
106 | |
107 // IndexedDBCursor::Continue / Advance (when complete) | |
108 virtual void OnSuccess(); | |
109 | |
110 void SetConnectionOpenStartTime(const base::TimeTicks& start_time); | |
111 | |
112 protected: | |
113 virtual ~IndexedDBCallbacks(); | |
114 | |
115 private: | |
116 void RegisterBlobsAndSend(const std::vector<IndexedDBBlobInfo>& blob_info, | |
117 const base::Closure& callback); | |
118 | |
119 friend class base::RefCounted<IndexedDBCallbacks>; | |
120 | |
121 // Originally from IndexedDBCallbacks: | |
122 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | |
123 int32_t ipc_callbacks_id_; | |
124 int32_t ipc_thread_id_; | |
125 | |
126 // IndexedDBCursor callbacks ------------------------ | |
127 int32_t ipc_cursor_id_; | |
128 | |
129 // IndexedDBDatabase callbacks ------------------------ | |
130 int64_t host_transaction_id_; | |
131 url::Origin origin_; | |
132 int32_t ipc_database_id_; | |
133 int32_t ipc_database_callbacks_id_; | |
134 | |
135 // Used to assert that OnSuccess is only called if there was no data loss. | |
136 blink::WebIDBDataLoss data_loss_; | |
137 | |
138 // The "blocked" event should be sent at most once per request. | |
139 bool sent_blocked_; | |
140 base::TimeTicks connection_open_start_time_; | |
141 DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacks); | |
142 }; | |
143 | 26 |
144 } // namespace content | 27 } // namespace content |
145 | 28 |
146 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ | 29 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ |
OLD | NEW |