Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(811)

Side by Side Diff: content/browser/indexed_db/indexed_db_callbacks.h

Issue 18241003: IndexedDB: Remove IndexedDBCallbacksWrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string>
9 #include <vector>
10
8 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "content/browser/indexed_db/indexed_db_database_error.h"
10 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 17 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
18 #include "content/common/indexed_db/indexed_db_key.h"
19 #include "content/common/indexed_db/indexed_db_key_path.h"
11 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
12 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h" 21 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h"
13 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" 22 #include "third_party/WebKit/public/platform/WebIDBDatabase.h"
14 23
15 namespace content { 24 namespace content {
16 class IndexedDBCursor; 25 class IndexedDBCursor;
26 class IndexedDBDatabase;
27 class IndexedDBDatabaseCallbacks;
17 class IndexedDBDatabaseError; 28 class IndexedDBDatabaseError;
29 class IndexedDBDispatcherHost;
18 class WebIDBDatabaseImpl; 30 class WebIDBDatabaseImpl;
19 struct IndexedDBDatabaseMetadata; 31 struct IndexedDBDatabaseMetadata;
20 32
21 class IndexedDBCallbacksBase { 33 class CONTENT_EXPORT IndexedDBCallbacks
34 : public base::RefCounted<IndexedDBCallbacks> {
22 public: 35 public:
23 virtual ~IndexedDBCallbacksBase(); 36 // Simple payload responses
37 static scoped_refptr<IndexedDBCallbacks> Create(
38 IndexedDBDispatcherHost* dispatcher_host,
39 int32 ipc_thread_id,
40 int32 ipc_callbacks_id) {
41 return make_scoped_refptr(new IndexedDBCallbacks(
42 dispatcher_host, ipc_thread_id, ipc_callbacks_id));
43 }
24 44
25 virtual void onError(const IndexedDBDatabaseError& error); 45 // IndexedDBCursor responses
26 virtual void onBlocked(long long old_version); 46 static scoped_refptr<IndexedDBCallbacks> Create(
47 IndexedDBDispatcherHost* dispatcher_host,
48 int32 ipc_thread_id,
49 int32 ipc_callbacks_id,
50 int32 ipc_cursor_id) {
51 return make_scoped_refptr(new IndexedDBCallbacks(
52 dispatcher_host, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
53 }
54 // IndexedDBDatabase responses
55 static scoped_refptr<IndexedDBCallbacks> Create(
56 IndexedDBDispatcherHost* dispatcher_host,
57 int32 ipc_thread_id,
58 int32 ipc_callbacks_id,
59 int32 ipc_database_callbacks_id,
60 int64 host_transaction_id,
61 const GURL& origin_url) {
62 return make_scoped_refptr(new IndexedDBCallbacks(dispatcher_host,
63 ipc_thread_id,
64 ipc_callbacks_id,
65 ipc_database_callbacks_id,
66 host_transaction_id,
67 origin_url));
68 }
27 69
28 // implemented by subclasses, but need to be called later 70 virtual void OnError(const IndexedDBDatabaseError& error);
29 virtual void onSuccess(const std::vector<string16>& value); 71
30 virtual void onSuccess(WebIDBDatabaseImpl* idb_object, 72 // IndexedDBFactory::GetDatabaseNames
31 const IndexedDBDatabaseMetadata& metadata); 73 virtual void OnSuccess(const std::vector<string16>& string);
32 virtual void onUpgradeNeeded(long long old_version, 74
33 WebIDBDatabaseImpl* database, 75 // IndexedDBFactory::Open / DeleteDatabase
34 const IndexedDBDatabaseMetadata&, 76 virtual void OnBlocked(int64 existing_version);
35 WebKit::WebIDBCallbacks::DataLoss data_loss); 77
36 virtual void onSuccess(IndexedDBCursor* idb_object, 78 // IndexedDBFactory::Open
79 virtual void OnUpgradeNeeded(
80 int64 old_version,
81 scoped_refptr<IndexedDBDatabase> db,
82 const content::IndexedDBDatabaseMetadata& metadata,
83 WebKit::WebIDBCallbacks::DataLoss data_loss);
84 virtual void OnSuccess(scoped_refptr<IndexedDBDatabase> db,
85 const content::IndexedDBDatabaseMetadata& metadata);
86 void SetDatabaseCallbacks(
87 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks);
88
89 // IndexedDBDatabase::OpenCursor
90 virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
37 const IndexedDBKey& key, 91 const IndexedDBKey& key,
38 const IndexedDBKey& primaryKey, 92 const IndexedDBKey& primary_key,
39 std::vector<char>* value); 93 std::vector<char>* value);
40 virtual void onSuccess(const IndexedDBKey& key, 94
41 const IndexedDBKey& primaryKey, 95 // IndexedDBCursor::Continue / Advance
96 virtual void OnSuccess(const IndexedDBKey& key,
97 const IndexedDBKey& primary_key,
42 std::vector<char>* value); 98 std::vector<char>* value);
43 virtual void onSuccess(std::vector<char>* value); 99
44 virtual void onSuccessWithPrefetch( 100 // IndexedDBCursor::PrefetchContinue
101 virtual void OnSuccessWithPrefetch(
45 const std::vector<IndexedDBKey>& keys, 102 const std::vector<IndexedDBKey>& keys,
46 const std::vector<IndexedDBKey>& primaryKeys, 103 const std::vector<IndexedDBKey>& primary_keys,
47 const std::vector<std::vector<char> >& values); 104 const std::vector<std::vector<char> >& values);
48 virtual void onSuccess(const IndexedDBKey& value); 105
49 virtual void onSuccess(std::vector<char>* value, 106 // IndexedDBDatabase::Get (with key injection)
107 virtual void OnSuccess(std::vector<char>* data,
50 const IndexedDBKey& key, 108 const IndexedDBKey& key,
51 const IndexedDBKeyPath& keyPath); 109 const IndexedDBKeyPath& key_path);
52 virtual void onSuccess(long long value); 110
53 virtual void onSuccess(); 111 // IndexedDBDatabase::Get
112 virtual void OnSuccess(std::vector<char>* value);
113
114 // IndexedDBDatabase::Put / IndexedDBCursor::Update
115 virtual void OnSuccess(const IndexedDBKey& value);
116
117 // IndexedDBDatabase::Count
118 virtual void OnSuccess(int64 value);
119
120 // IndexedDBDatabase::Delete
121 // IndexedDBCursor::Continue / Advance (when complete)
122 virtual void OnSuccess();
54 123
55 protected: 124 protected:
56 IndexedDBCallbacksBase(IndexedDBDispatcherHost* dispatcher_host, 125 virtual ~IndexedDBCallbacks();
57 int32 ipc_thread_id, 126
58 int32 ipc_callbacks_id); 127 // Simple payload responses
59 IndexedDBDispatcherHost* dispatcher_host() const { 128 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
60 return dispatcher_host_.get(); 129 int32 ipc_thread_id,
61 } 130 int32 ipc_callbacks_id);
62 int32 ipc_thread_id() const { return ipc_thread_id_; } 131
63 int32 ipc_callbacks_id() const { return ipc_callbacks_id_; } 132 // IndexedDBCursor responses
133 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
134 int32 ipc_thread_id,
135 int32 ipc_callbacks_id,
136 int32 ipc_cursor_id);
137
138 // IndexedDBDatabase responses
139 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
140 int32 ipc_thread_id,
141 int32 ipc_callbacks_id,
142 int32 ipc_database_callbacks_id,
143 int64 host_transaction_id,
144 const GURL& origin_url);
64 145
65 private: 146 private:
147 friend class base::RefCounted<IndexedDBCallbacks>;
148
149 scoped_ptr<WebIDBDatabaseImpl> web_database_impl_;
150 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
151 bool did_complete_;
152 bool did_create_proxy_;
153
154 // Originally from IndexedDBCallbacks:
66 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; 155 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
67 int32 ipc_callbacks_id_; 156 int32 ipc_callbacks_id_;
68 int32 ipc_thread_id_; 157 int32 ipc_thread_id_;
69 158
70 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase); 159 // IndexedDBCursor callbacks ------------------------
71 }; 160 int32 ipc_cursor_id_;
72 161
73 // TODO(dgrogan): Remove this class and change the remaining specializations 162 // IndexedDBDatabase callbacks ------------------------
74 // into subclasses of IndexedDBCallbacksBase.
75 template <class WebObjectType>
76 class IndexedDBCallbacks : public IndexedDBCallbacksBase {
77 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
78 };
79
80 class IndexedDBCallbacksDatabase : public IndexedDBCallbacksBase {
81 public:
82 IndexedDBCallbacksDatabase(IndexedDBDispatcherHost* dispatcher_host,
83 int32 ipc_thread_id,
84 int32 ipc_callbacks_id,
85 int32 ipc_database_callbacks_id,
86 int64 host_transaction_id,
87 const GURL& origin_url);
88
89 virtual void onSuccess(WebIDBDatabaseImpl* idb_object,
90 const IndexedDBDatabaseMetadata& metadata) OVERRIDE;
91 virtual void onUpgradeNeeded(long long old_version,
92 WebIDBDatabaseImpl* database,
93 const IndexedDBDatabaseMetadata&,
94 WebKit::WebIDBCallbacks::DataLoss data_loss)
95 OVERRIDE;
96
97 private:
98 int64 host_transaction_id_; 163 int64 host_transaction_id_;
99 GURL origin_url_; 164 GURL origin_url_;
100 int32 ipc_database_id_; 165 int32 ipc_database_id_;
101 int32 ipc_database_callbacks_id_; 166 int32 ipc_database_callbacks_id_;
102 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksDatabase);
103 };
104
105 // IndexedDBCursor uses:
106 // * onSuccess(IndexedDBCursor*, WebIDBKey, WebIDBKey, WebData)
107 // when an openCursor()/openKeyCursor() call has succeeded,
108 // * onSuccess(WebIDBKey, WebIDBKey, WebData)
109 // when an advance()/continue() call has succeeded, or
110 // * onSuccess()
111 // to indicate it does not contain any data, i.e., there is no key within
112 // the key range, or it has reached the end.
113 template <>
114 class IndexedDBCallbacks<IndexedDBCursor> : public IndexedDBCallbacksBase {
115 public:
116 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
117 int32 ipc_thread_id,
118 int32 ipc_callbacks_id,
119 int32 ipc_cursor_id)
120 : IndexedDBCallbacksBase(dispatcher_host,
121 ipc_thread_id,
122 ipc_callbacks_id),
123 ipc_cursor_id_(ipc_cursor_id) {}
124
125 virtual void onSuccess(IndexedDBCursor* idb_object,
126 const IndexedDBKey& key,
127 const IndexedDBKey& primaryKey,
128 std::vector<char>* value);
129 virtual void onSuccess(const IndexedDBKey& key,
130 const IndexedDBKey& primaryKey,
131 std::vector<char>* value);
132 virtual void onSuccess(std::vector<char>* value);
133 virtual void onSuccessWithPrefetch(
134 const std::vector<IndexedDBKey>& keys,
135 const std::vector<IndexedDBKey>& primaryKeys,
136 const std::vector<std::vector<char> >& values);
137
138 private:
139 // The id of the cursor this callback concerns, or -1 if the cursor
140 // does not exist yet.
141 int32 ipc_cursor_id_;
142
143 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
144 };
145
146 // WebIDBKey is implemented in WebKit as opposed to being an interface Chromium
147 // implements. Thus we pass a const ___& version and thus we need this
148 // specialization.
149 template <>
150 class IndexedDBCallbacks<IndexedDBKey> : public IndexedDBCallbacksBase {
151 public:
152 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
153 int32 ipc_thread_id,
154 int32 ipc_callbacks_id)
155 : IndexedDBCallbacksBase(dispatcher_host,
156 ipc_thread_id,
157 ipc_callbacks_id) {}
158
159 virtual void onSuccess(const IndexedDBKey& value);
160
161 private:
162 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
163 };
164
165 template <>
166 class IndexedDBCallbacks<
167 std::vector<string16> > : public IndexedDBCallbacksBase {
168 public:
169 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
170 int32 ipc_thread_id,
171 int32 ipc_callbacks_id)
172 : IndexedDBCallbacksBase(dispatcher_host,
173 ipc_thread_id,
174 ipc_callbacks_id) {}
175
176 virtual void onSuccess(const std::vector<string16>& value);
177
178 private:
179 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
180 };
181
182 // WebData is implemented in WebKit as opposed to being an interface
183 // Chromium implements. Thus we pass a const ___& version and thus we
184 // need this specialization.
185 template <>
186 class IndexedDBCallbacks<std::vector<char> > : public IndexedDBCallbacksBase {
187 public:
188 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
189 int32 ipc_thread_id,
190 int32 ipc_callbacks_id)
191 : IndexedDBCallbacksBase(dispatcher_host,
192 ipc_thread_id,
193 ipc_callbacks_id) {}
194
195 virtual void onSuccess(std::vector<char>* value);
196 virtual void onSuccess(std::vector<char>* value,
197 const IndexedDBKey& key,
198 const IndexedDBKeyPath& keyPath);
199 virtual void onSuccess(long long value);
200 virtual void onSuccess();
201 virtual void onSuccess(const IndexedDBKey& value);
202
203 private:
204 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacks);
205 }; 167 };
206 168
207 } // namespace content 169 } // namespace content
208 170
209 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ 171 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698