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

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: Include/Forward Declare tidying 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
« no previous file with comments | « no previous file | content/browser/indexed_db/indexed_db_callbacks.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
17 class IndexedDBDatabaseError; 26 class IndexedDBDatabase;
27 class IndexedDBDatabaseCallbacks;
18 class WebIDBDatabaseImpl; 28 class WebIDBDatabaseImpl;
19 struct IndexedDBDatabaseMetadata; 29 struct IndexedDBDatabaseMetadata;
20 30
21 class IndexedDBCallbacksBase { 31 class CONTENT_EXPORT IndexedDBCallbacks
32 : public base::RefCounted<IndexedDBCallbacks> {
22 public: 33 public:
23 virtual ~IndexedDBCallbacksBase(); 34 // Simple payload responses
35 static scoped_refptr<IndexedDBCallbacks> Create(
36 IndexedDBDispatcherHost* dispatcher_host,
37 int32 ipc_thread_id,
38 int32 ipc_callbacks_id) {
39 return make_scoped_refptr(new IndexedDBCallbacks(
40 dispatcher_host, ipc_thread_id, ipc_callbacks_id));
41 }
24 42
25 virtual void onError(const IndexedDBDatabaseError& error); 43 // IndexedDBCursor responses
26 virtual void onBlocked(long long old_version); 44 static scoped_refptr<IndexedDBCallbacks> Create(
45 IndexedDBDispatcherHost* dispatcher_host,
46 int32 ipc_thread_id,
47 int32 ipc_callbacks_id,
48 int32 ipc_cursor_id) {
49 return make_scoped_refptr(new IndexedDBCallbacks(
50 dispatcher_host, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
51 }
52 // IndexedDBDatabase responses
53 static scoped_refptr<IndexedDBCallbacks> Create(
54 IndexedDBDispatcherHost* dispatcher_host,
55 int32 ipc_thread_id,
56 int32 ipc_callbacks_id,
57 int32 ipc_database_callbacks_id,
58 int64 host_transaction_id,
59 const GURL& origin_url) {
60 return make_scoped_refptr(new IndexedDBCallbacks(dispatcher_host,
61 ipc_thread_id,
62 ipc_callbacks_id,
63 ipc_database_callbacks_id,
64 host_transaction_id,
65 origin_url));
66 }
27 67
28 // implemented by subclasses, but need to be called later 68 virtual void OnError(const IndexedDBDatabaseError& error);
29 virtual void onSuccess(const std::vector<string16>& value); 69
30 virtual void onSuccess(WebIDBDatabaseImpl* idb_object, 70 // IndexedDBFactory::GetDatabaseNames
31 const IndexedDBDatabaseMetadata& metadata); 71 virtual void OnSuccess(const std::vector<string16>& string);
32 virtual void onUpgradeNeeded(long long old_version, 72
33 WebIDBDatabaseImpl* database, 73 // IndexedDBFactory::Open / DeleteDatabase
34 const IndexedDBDatabaseMetadata&, 74 virtual void OnBlocked(int64 existing_version);
35 WebKit::WebIDBCallbacks::DataLoss data_loss); 75
36 virtual void onSuccess(IndexedDBCursor* idb_object, 76 // IndexedDBFactory::Open
77 virtual void OnUpgradeNeeded(
78 int64 old_version,
79 scoped_refptr<IndexedDBDatabase> db,
80 const content::IndexedDBDatabaseMetadata& metadata,
81 WebKit::WebIDBCallbacks::DataLoss data_loss);
82 virtual void OnSuccess(scoped_refptr<IndexedDBDatabase> db,
83 const content::IndexedDBDatabaseMetadata& metadata);
84 void SetDatabaseCallbacks(
85 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks);
86
87 // IndexedDBDatabase::OpenCursor
88 virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
37 const IndexedDBKey& key, 89 const IndexedDBKey& key,
38 const IndexedDBKey& primaryKey, 90 const IndexedDBKey& primary_key,
39 std::vector<char>* value); 91 std::vector<char>* value);
40 virtual void onSuccess(const IndexedDBKey& key, 92
41 const IndexedDBKey& primaryKey, 93 // IndexedDBCursor::Continue / Advance
94 virtual void OnSuccess(const IndexedDBKey& key,
95 const IndexedDBKey& primary_key,
42 std::vector<char>* value); 96 std::vector<char>* value);
43 virtual void onSuccess(std::vector<char>* value); 97
44 virtual void onSuccessWithPrefetch( 98 // IndexedDBCursor::PrefetchContinue
99 virtual void OnSuccessWithPrefetch(
45 const std::vector<IndexedDBKey>& keys, 100 const std::vector<IndexedDBKey>& keys,
46 const std::vector<IndexedDBKey>& primaryKeys, 101 const std::vector<IndexedDBKey>& primary_keys,
47 const std::vector<std::vector<char> >& values); 102 const std::vector<std::vector<char> >& values);
48 virtual void onSuccess(const IndexedDBKey& value); 103
49 virtual void onSuccess(std::vector<char>* value, 104 // IndexedDBDatabase::Get (with key injection)
105 virtual void OnSuccess(std::vector<char>* data,
50 const IndexedDBKey& key, 106 const IndexedDBKey& key,
51 const IndexedDBKeyPath& keyPath); 107 const IndexedDBKeyPath& key_path);
52 virtual void onSuccess(long long value); 108
53 virtual void onSuccess(); 109 // IndexedDBDatabase::Get
110 virtual void OnSuccess(std::vector<char>* value);
111
112 // IndexedDBDatabase::Put / IndexedDBCursor::Update
113 virtual void OnSuccess(const IndexedDBKey& value);
114
115 // IndexedDBDatabase::Count
116 virtual void OnSuccess(int64 value);
117
118 // IndexedDBDatabase::Delete
119 // IndexedDBCursor::Continue / Advance (when complete)
120 virtual void OnSuccess();
54 121
55 protected: 122 protected:
56 IndexedDBCallbacksBase(IndexedDBDispatcherHost* dispatcher_host, 123 virtual ~IndexedDBCallbacks();
57 int32 ipc_thread_id, 124
58 int32 ipc_callbacks_id); 125 // Simple payload responses
59 IndexedDBDispatcherHost* dispatcher_host() const { 126 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
60 return dispatcher_host_.get(); 127 int32 ipc_thread_id,
61 } 128 int32 ipc_callbacks_id);
62 int32 ipc_thread_id() const { return ipc_thread_id_; } 129
63 int32 ipc_callbacks_id() const { return ipc_callbacks_id_; } 130 // IndexedDBCursor responses
131 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
132 int32 ipc_thread_id,
133 int32 ipc_callbacks_id,
134 int32 ipc_cursor_id);
135
136 // IndexedDBDatabase responses
137 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
138 int32 ipc_thread_id,
139 int32 ipc_callbacks_id,
140 int32 ipc_database_callbacks_id,
141 int64 host_transaction_id,
142 const GURL& origin_url);
64 143
65 private: 144 private:
145 friend class base::RefCounted<IndexedDBCallbacks>;
146
147 scoped_ptr<WebIDBDatabaseImpl> web_database_impl_;
148 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
149 bool did_complete_;
150 bool did_create_proxy_;
151
152 // Originally from IndexedDBCallbacks:
66 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; 153 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
67 int32 ipc_callbacks_id_; 154 int32 ipc_callbacks_id_;
68 int32 ipc_thread_id_; 155 int32 ipc_thread_id_;
69 156
70 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBCallbacksBase); 157 // IndexedDBCursor callbacks ------------------------
71 }; 158 int32 ipc_cursor_id_;
72 159
73 // TODO(dgrogan): Remove this class and change the remaining specializations 160 // 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_; 161 int64 host_transaction_id_;
99 GURL origin_url_; 162 GURL origin_url_;
100 int32 ipc_database_id_; 163 int32 ipc_database_id_;
101 int32 ipc_database_callbacks_id_; 164 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 }; 165 };
206 166
207 } // namespace content 167 } // namespace content
208 168
209 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ 169 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/indexed_db/indexed_db_callbacks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698