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

Side by Side Diff: content/browser/in_process_webkit/indexed_db_callbacks.cc

Issue 17840006: Move IndexedDB files out of in_process_webkit (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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/in_process_webkit/indexed_db_callbacks.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "content/browser/indexed_db/indexed_db_metadata.h"
11 #include "content/browser/indexed_db/webidbdatabase_impl.h"
12 #include "content/common/indexed_db/indexed_db_messages.h"
13 #include "webkit/browser/quota/quota_manager.h"
14
15 using WebKit::WebData;
16 using WebKit::WebIDBCallbacks;
17 using WebKit::WebString;
18
19 namespace content {
20
21 namespace {
22 const int32 kDatabaseNotAdded = -1;
23 }
24
25 IndexedDBCallbacksBase::IndexedDBCallbacksBase(
26 IndexedDBDispatcherHost* dispatcher_host,
27 int32 ipc_thread_id,
28 int32 ipc_callbacks_id)
29 : dispatcher_host_(dispatcher_host),
30 ipc_callbacks_id_(ipc_callbacks_id),
31 ipc_thread_id_(ipc_thread_id) {}
32
33 IndexedDBCallbacksBase::~IndexedDBCallbacksBase() {}
34
35 void IndexedDBCallbacksBase::onError(const WebKit::WebIDBDatabaseError& error) {
36 dispatcher_host_->Send(new IndexedDBMsg_CallbacksError(
37 ipc_thread_id_, ipc_callbacks_id_, error.code(), error.message()));
38 }
39
40 void IndexedDBCallbacksBase::onBlocked(long long old_version) {
41 dispatcher_host_->Send(new IndexedDBMsg_CallbacksIntBlocked(
42 ipc_thread_id_, ipc_callbacks_id_, old_version));
43 }
44
45 void IndexedDBCallbacksBase::onSuccess(const std::vector<string16>& value) {
46 NOTREACHED();
47 }
48
49 void IndexedDBCallbacksBase::onSuccess(
50 WebIDBDatabaseImpl* idb_object,
51 const IndexedDBDatabaseMetadata& metadata) {
52 NOTREACHED();
53 }
54
55 void IndexedDBCallbacksBase::onUpgradeNeeded(
56 long long old_version,
57 WebIDBDatabaseImpl* database,
58 const IndexedDBDatabaseMetadata& /*metadata*/,
59 WebKit::WebIDBCallbacks::DataLoss data_loss) {
60 NOTREACHED();
61 }
62
63 void IndexedDBCallbacksBase::onSuccess(WebIDBCursorImpl* idb_object,
64 const IndexedDBKey& key,
65 const IndexedDBKey& primaryKey,
66 std::vector<char>* value) {
67 NOTREACHED();
68 }
69
70 void IndexedDBCallbacksBase::onSuccess(const IndexedDBKey& key,
71 const IndexedDBKey& primaryKey,
72 std::vector<char>* value) {
73 NOTREACHED();
74 }
75
76 void IndexedDBCallbacksBase::onSuccess(std::vector<char>* value) {
77 NOTREACHED();
78 }
79
80 void IndexedDBCallbacksBase::onSuccessWithPrefetch(
81 const std::vector<IndexedDBKey>& keys,
82 const std::vector<IndexedDBKey>& primaryKeys,
83 const std::vector<std::vector<char> >& values) {
84 NOTREACHED();
85 }
86
87 void IndexedDBCallbacksBase::onSuccess(const IndexedDBKey& value) {
88 NOTREACHED();
89 }
90
91 void IndexedDBCallbacksBase::onSuccess(std::vector<char>* value,
92 const IndexedDBKey& key,
93 const IndexedDBKeyPath& keyPath) {
94 NOTREACHED();
95 }
96
97 void IndexedDBCallbacksBase::onSuccess(long long value) { NOTREACHED(); }
98
99 void IndexedDBCallbacksBase::onSuccess() { NOTREACHED(); }
100
101 IndexedDBCallbacksDatabase::IndexedDBCallbacksDatabase(
102 IndexedDBDispatcherHost* dispatcher_host,
103 int32 ipc_thread_id,
104 int32 ipc_callbacks_id,
105 int32 ipc_database_callbacks_id,
106 int64 host_transaction_id,
107 const GURL& origin_url)
108 : IndexedDBCallbacksBase(dispatcher_host, ipc_thread_id, ipc_callbacks_id),
109 host_transaction_id_(host_transaction_id),
110 origin_url_(origin_url),
111 ipc_database_id_(kDatabaseNotAdded),
112 ipc_database_callbacks_id_(ipc_database_callbacks_id) {}
113
114 void IndexedDBCallbacksDatabase::onSuccess(
115 WebIDBDatabaseImpl* idb_object,
116 const IndexedDBDatabaseMetadata& metadata) {
117 int32 ipc_object_id = ipc_database_id_;
118 if (ipc_object_id == kDatabaseNotAdded) {
119 ipc_object_id =
120 dispatcher_host()->Add(idb_object, ipc_thread_id(), origin_url_);
121 } else {
122 // We already have this database and don't need a new copy of it.
123 delete idb_object;
124 }
125 const ::IndexedDBDatabaseMetadata idb_metadata =
126 IndexedDBDispatcherHost::ConvertMetadata(metadata);
127
128 dispatcher_host()->Send(
129 new IndexedDBMsg_CallbacksSuccessIDBDatabase(ipc_thread_id(),
130 ipc_callbacks_id(),
131 ipc_database_callbacks_id_,
132 ipc_object_id,
133 idb_metadata));
134 }
135
136 void IndexedDBCallbacksDatabase::onUpgradeNeeded(
137 long long old_version,
138 WebIDBDatabaseImpl* database,
139 const IndexedDBDatabaseMetadata& metadata,
140 WebIDBCallbacks::DataLoss data_loss) {
141 dispatcher_host()->RegisterTransactionId(host_transaction_id_, origin_url_);
142 int32 ipc_database_id =
143 dispatcher_host()->Add(database, ipc_thread_id(), origin_url_);
144 ipc_database_id_ = ipc_database_id;
145 IndexedDBMsg_CallbacksUpgradeNeeded_Params params;
146 params.ipc_thread_id = ipc_thread_id();
147 params.ipc_callbacks_id = ipc_callbacks_id();
148 params.ipc_database_id = ipc_database_id;
149 params.ipc_database_callbacks_id = ipc_database_callbacks_id_;
150 params.old_version = old_version;
151 params.idb_metadata = IndexedDBDispatcherHost::ConvertMetadata(metadata);
152 params.data_loss = data_loss;
153 dispatcher_host()->Send(new IndexedDBMsg_CallbacksUpgradeNeeded(params));
154 }
155
156 void IndexedDBCallbacks<WebIDBCursorImpl>::onSuccess(
157 WebIDBCursorImpl* idb_cursor,
158 const IndexedDBKey& key,
159 const IndexedDBKey& primaryKey,
160 std::vector<char>* value) {
161 int32 ipc_object_id = dispatcher_host()->Add(idb_cursor);
162 IndexedDBMsg_CallbacksSuccessIDBCursor_Params params;
163 params.ipc_thread_id = ipc_thread_id();
164 params.ipc_callbacks_id = ipc_callbacks_id();
165 params.ipc_cursor_id = ipc_object_id;
166 params.key = key;
167 params.primary_key = primaryKey;
168 if (value && !value->empty())
169 std::swap(params.value, *value);
170 // TODO(alecflett): Avoid a copy here: the whole params object is
171 // being copied into the message.
172 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessIDBCursor(params));
173 }
174
175 void IndexedDBCallbacks<WebIDBCursorImpl>::onSuccess(std::vector<char>* value) {
176 std::vector<char> value_copy;
177 if (value && !value->empty())
178 std::swap(value_copy, *value);
179 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessValue(
180 ipc_thread_id(),
181 ipc_callbacks_id(),
182 // TODO(alecflett): avoid a copy here.
183 value_copy));
184 }
185
186 void IndexedDBCallbacks<WebIDBCursorImpl>::onSuccess(
187 const IndexedDBKey& key,
188 const IndexedDBKey& primaryKey,
189 std::vector<char>* value) {
190 DCHECK_NE(ipc_cursor_id_, -1);
191 WebIDBCursorImpl* idb_cursor =
192 dispatcher_host()->GetCursorFromId(ipc_cursor_id_);
193
194 DCHECK(idb_cursor);
195 if (!idb_cursor)
196 return;
197 IndexedDBMsg_CallbacksSuccessCursorContinue_Params params;
198 params.ipc_thread_id = ipc_thread_id();
199 params.ipc_callbacks_id = ipc_callbacks_id();
200 params.ipc_cursor_id = ipc_cursor_id_;
201 params.key = key;
202 params.primary_key = primaryKey;
203 if (value && !value->empty())
204 std::swap(params.value, *value);
205 // TODO(alecflett): Avoid a copy here: the whole params object is
206 // being copied into the message.
207 dispatcher_host()->Send(
208 new IndexedDBMsg_CallbacksSuccessCursorContinue(params));
209 }
210
211 void IndexedDBCallbacks<WebIDBCursorImpl>::onSuccessWithPrefetch(
212 const std::vector<IndexedDBKey>& keys,
213 const std::vector<IndexedDBKey>& primaryKeys,
214 const std::vector<std::vector<char> >& values) {
215 DCHECK_NE(ipc_cursor_id_, -1);
216
217 std::vector<IndexedDBKey> msgKeys;
218 std::vector<IndexedDBKey> msgPrimaryKeys;
219
220 for (size_t i = 0; i < keys.size(); ++i) {
221 msgKeys.push_back(keys[i]);
222 msgPrimaryKeys.push_back(primaryKeys[i]);
223 }
224
225 IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params params;
226 params.ipc_thread_id = ipc_thread_id();
227 params.ipc_callbacks_id = ipc_callbacks_id();
228 params.ipc_cursor_id = ipc_cursor_id_;
229 params.keys = msgKeys;
230 params.primary_keys = msgPrimaryKeys;
231 params.values = values;
232 dispatcher_host()->Send(
233 new IndexedDBMsg_CallbacksSuccessCursorPrefetch(params));
234 }
235
236 void IndexedDBCallbacks<IndexedDBKey>::onSuccess(const IndexedDBKey& value) {
237 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
238 ipc_thread_id(), ipc_callbacks_id(), IndexedDBKey(value)));
239 }
240
241 void IndexedDBCallbacks<std::vector<string16> >::onSuccess(
242 const std::vector<string16>& value) {
243
244 std::vector<string16> list;
245 for (unsigned i = 0; i < value.size(); ++i)
246 list.push_back(value[i]);
247
248 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessStringList(
249 ipc_thread_id(), ipc_callbacks_id(), list));
250 }
251
252 void IndexedDBCallbacks<std::vector<char> >::onSuccess(
253 std::vector<char>* value) {
254 std::vector<char> value_copy;
255 if (value && !value->empty())
256 std::swap(value_copy, *value);
257 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessValue(
258 ipc_thread_id(),
259 ipc_callbacks_id(),
260 // TODO(alecflett): avoid a copy here
261 value_copy));
262 }
263
264 void IndexedDBCallbacks<std::vector<char> >::onSuccess(
265 std::vector<char>* value,
266 const IndexedDBKey& primaryKey,
267 const IndexedDBKeyPath& keyPath) {
268 std::vector<char> value_copy;
269 if (value && !value->empty())
270 std::swap(value_copy, *value);
271 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessValueWithKey(
272 ipc_thread_id(),
273 ipc_callbacks_id(),
274 // TODO(alecflett): Avoid a copy here.
275 value_copy,
276 IndexedDBKey(primaryKey),
277 IndexedDBKeyPath(keyPath)));
278 }
279
280 void IndexedDBCallbacks<std::vector<char> >::onSuccess(long long value) {
281 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessInteger(
282 ipc_thread_id(), ipc_callbacks_id(), value));
283 }
284
285 void IndexedDBCallbacks<std::vector<char> >::onSuccess() {
286 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessUndefined(
287 ipc_thread_id(), ipc_callbacks_id()));
288 }
289
290 void IndexedDBCallbacks<std::vector<char> >::onSuccess(
291 const IndexedDBKey& value) {
292 dispatcher_host()->Send(new IndexedDBMsg_CallbacksSuccessIndexedDBKey(
293 ipc_thread_id(), ipc_callbacks_id(), value));
294 }
295
296 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698