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

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

Issue 15564008: Migrate the IndexedDB backend from Blink to Chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Coding style fixes Created 7 years, 7 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 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" 5 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 23 matching lines...) Expand all
34 #include "webkit/base/file_path_string_conversions.h" 34 #include "webkit/base/file_path_string_conversions.h"
35 #include "webkit/base/origin_url_conversions.h" 35 #include "webkit/base/origin_url_conversions.h"
36 #include "webkit/database/database_util.h" 36 #include "webkit/database/database_util.h"
37 37
38 using webkit_database::DatabaseUtil; 38 using webkit_database::DatabaseUtil;
39 using WebKit::WebData; 39 using WebKit::WebData;
40 using WebKit::WebIDBCallbacks; 40 using WebKit::WebIDBCallbacks;
41 using WebKit::WebIDBCursor; 41 using WebKit::WebIDBCursor;
42 using WebKit::WebIDBDatabase; 42 using WebKit::WebIDBDatabase;
43 using WebKit::WebIDBDatabaseError; 43 using WebKit::WebIDBDatabaseError;
44 using WebKit::WebIDBIndex;
45 using WebKit::WebIDBKey; 44 using WebKit::WebIDBKey;
46 using WebKit::WebIDBMetadata; 45 using WebKit::WebIDBMetadata;
47 using WebKit::WebIDBObjectStore;
48 using WebKit::WebString; 46 using WebKit::WebString;
49 using WebKit::WebVector; 47 using WebKit::WebVector;
50 48
51 namespace content { 49 namespace content {
52 namespace { 50 namespace {
53 51
54 template <class T> 52 template <class T> void DeleteOnWebKitThread(T* obj) {
55 void DeleteOnWebKitThread(T* obj) { 53 if (!BrowserThread::DeleteSoon(
56 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED, 54 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, obj))
57 FROM_HERE, obj))
58 delete obj; 55 delete obj;
59 } 56 }
60 } 57 }
61 58
62 IndexedDBDispatcherHost::IndexedDBDispatcherHost( 59 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
63 int ipc_process_id, IndexedDBContextImpl* indexed_db_context) 60 int ipc_process_id,
61 IndexedDBContextImpl* indexed_db_context)
64 : indexed_db_context_(indexed_db_context), 62 : indexed_db_context_(indexed_db_context),
65 database_dispatcher_host_(new DatabaseDispatcherHost(this)), 63 database_dispatcher_host_(new DatabaseDispatcherHost(this)),
66 cursor_dispatcher_host_(new CursorDispatcherHost(this)), 64 cursor_dispatcher_host_(new CursorDispatcherHost(this)),
67 ipc_process_id_(ipc_process_id) { 65 ipc_process_id_(ipc_process_id) {
68 DCHECK(indexed_db_context_.get()); 66 DCHECK(indexed_db_context_.get());
69 } 67 }
70 68
71 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { 69 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {}
72 }
73 70
74 void IndexedDBDispatcherHost::OnChannelClosing() { 71 void IndexedDBDispatcherHost::OnChannelClosing() {
75 BrowserMessageFilter::OnChannelClosing(); 72 BrowserMessageFilter::OnChannelClosing();
76 73
77 bool success = BrowserThread::PostTask( 74 bool success = BrowserThread::PostTask(
78 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 75 BrowserThread::WEBKIT_DEPRECATED,
76 FROM_HERE,
79 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); 77 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this));
80 78
81 if (!success) 79 if (!success)
82 ResetDispatcherHosts(); 80 ResetDispatcherHosts();
83 } 81 }
84 82
85 void IndexedDBDispatcherHost::ResetDispatcherHosts() { 83 void IndexedDBDispatcherHost::ResetDispatcherHosts() {
86 // It is important that the various *_dispatcher_host_ members are reset 84 // It is important that the various *_dispatcher_host_ members are reset
87 // on the WebKit thread, since there might be incoming messages on that 85 // on the WebKit thread, since there might be incoming messages on that
88 // thread, and we must not reset the dispatcher hosts until after those 86 // thread, and we must not reset the dispatcher hosts until after those
(...skipping 23 matching lines...) Expand all
112 110
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
114 112
115 bool handled = 113 bool handled =
116 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) || 114 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) ||
117 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok); 115 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok);
118 116
119 if (!handled) { 117 if (!handled) {
120 handled = true; 118 handled = true;
121 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok) 119 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok)
122 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames, 120 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames,
123 OnIDBFactoryGetDatabaseNames) 121 OnIDBFactoryGetDatabaseNames)
124 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen) 122 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen)
125 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase, 123 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase,
126 OnIDBFactoryDeleteDatabase) 124 OnIDBFactoryDeleteDatabase)
127 IPC_MESSAGE_UNHANDLED(handled = false) 125 IPC_MESSAGE_UNHANDLED(handled = false)
128 IPC_END_MESSAGE_MAP() 126 IPC_END_MESSAGE_MAP()
129 } 127 }
130 return handled; 128 return handled;
131 } 129 }
132 130
133 int32 IndexedDBDispatcherHost::Add(WebIDBCursor* idb_cursor) { 131 int32 IndexedDBDispatcherHost::Add(WebIDBCursor* idb_cursor) {
134 if (!cursor_dispatcher_host_) { 132 if (!cursor_dispatcher_host_) {
135 delete idb_cursor; 133 delete idb_cursor;
136 return 0; 134 return 0;
137 } 135 }
138 return cursor_dispatcher_host_->map_.Add(idb_cursor); 136 return cursor_dispatcher_host_->map_.Add(idb_cursor);
139 } 137 }
140 138
141 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database, 139 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database,
142 int32 ipc_thread_id, 140 int32 ipc_thread_id,
143 const GURL& origin_url) { 141 const GURL& origin_url) {
144 if (!database_dispatcher_host_) { 142 if (!database_dispatcher_host_) {
145 delete idb_database; 143 delete idb_database;
146 return 0; 144 return 0;
147 } 145 }
148 int32 ipc_database_id = database_dispatcher_host_->map_.Add(idb_database); 146 int32 ipc_database_id = database_dispatcher_host_->map_.Add(idb_database);
149 Context()->ConnectionOpened(origin_url, idb_database); 147 Context()->ConnectionOpened(origin_url, idb_database);
150 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url; 148 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url;
151 return ipc_database_id; 149 return ipc_database_id;
152 } 150 }
153 151
154 void IndexedDBDispatcherHost::RegisterTransactionId( 152 void IndexedDBDispatcherHost::RegisterTransactionId(int64 host_transaction_id,
155 int64 host_transaction_id, 153 const GURL& url) {
156 const GURL& url)
157 {
158 if (!database_dispatcher_host_) 154 if (!database_dispatcher_host_)
159 return; 155 return;
160 database_dispatcher_host_->transaction_url_map_[host_transaction_id] = url; 156 database_dispatcher_host_->transaction_url_map_[host_transaction_id] = url;
161 } 157 }
162 158
163 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) { 159 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) {
164 // Inject the renderer process id into the transaction id, to 160 // Inject the renderer process id into the transaction id, to
165 // uniquely identify this transaction, and effectively bind it to 161 // uniquely identify this transaction, and effectively bind it to
166 // the renderer that initiated it. The lower 32 bits of 162 // the renderer that initiated it. The lower 32 bits of
167 // transaction_id are guaranteed to be unique within that renderer. 163 // transaction_id are guaranteed to be unique within that renderer.
168 base::ProcessId pid = base::GetProcId(peer_handle()); 164 base::ProcessId pid = base::GetProcId(peer_handle());
169 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits"; 165 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
170 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32), 166 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32),
171 Process_ID_must_fit_in_32_bits); 167 Process_ID_must_fit_in_32_bits);
172 168
173 return transaction_id | (static_cast<uint64>(pid) << 32); 169 return transaction_id | (static_cast<uint64>(pid) << 32);
174 } 170 }
175 171
176 int64 IndexedDBDispatcherHost::RendererTransactionId( 172 int64 IndexedDBDispatcherHost::RendererTransactionId(
177 int64 host_transaction_id) { 173 int64 host_transaction_id) {
178 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle())) << 174 DCHECK(host_transaction_id >> 32 == base::GetProcId(peer_handle()))
179 "Invalid renderer target for transaction id"; 175 << "Invalid renderer target for transaction id";
180 return host_transaction_id & 0xffffffff; 176 return host_transaction_id & 0xffffffff;
181 } 177 }
182 178
183 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) { 179 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
185 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id); 181 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id);
186 } 182 }
187 183
188 IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata( 184 IndexedDBDatabaseMetadata IndexedDBDispatcherHost::ConvertMetadata(
189 const WebIDBMetadata& web_metadata) 185 const WebIDBMetadata& web_metadata) {
190 {
191 IndexedDBDatabaseMetadata metadata; 186 IndexedDBDatabaseMetadata metadata;
192 metadata.id = web_metadata.id; 187 metadata.id = web_metadata.id;
193 metadata.name = web_metadata.name; 188 metadata.name = web_metadata.name;
194 metadata.version = web_metadata.version; 189 metadata.version = web_metadata.version;
195 metadata.int_version = web_metadata.intVersion; 190 metadata.int_version = web_metadata.intVersion;
196 metadata.max_object_store_id = web_metadata.maxObjectStoreId; 191 metadata.max_object_store_id = web_metadata.maxObjectStoreId;
197 192
198 for (size_t i = 0; i < web_metadata.objectStores.size(); ++i) { 193 for (size_t i = 0; i < web_metadata.objectStores.size(); ++i) {
199 const WebIDBMetadata::ObjectStore& web_store_metadata = 194 const WebIDBMetadata::ObjectStore& web_store_metadata =
200 web_metadata.objectStores[i]; 195 web_metadata.objectStores[i];
(...skipping 19 matching lines...) Expand all
220 } 215 }
221 return metadata; 216 return metadata;
222 } 217 }
223 218
224 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( 219 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames(
225 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { 220 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
227 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 222 base::FilePath indexed_db_path = indexed_db_context_->data_path();
228 223
229 Context()->GetIDBFactory()->getDatabaseNames( 224 Context()->GetIDBFactory()->getDatabaseNames(
230 new IndexedDBCallbacks<WebVector<WebString> >(this, params.ipc_thread_id, 225 new IndexedDBCallbacks<WebVector<WebString> >(
231 params.ipc_callbacks_id), params.database_identifier, 226 this, params.ipc_thread_id, params.ipc_callbacks_id),
227 params.database_identifier,
232 webkit_base::FilePathToWebString(indexed_db_path)); 228 webkit_base::FilePathToWebString(indexed_db_path));
233 } 229 }
234 230
235 void IndexedDBDispatcherHost::OnIDBFactoryOpen( 231 void IndexedDBDispatcherHost::OnIDBFactoryOpen(
236 const IndexedDBHostMsg_FactoryOpen_Params& params) { 232 const IndexedDBHostMsg_FactoryOpen_Params& params) {
237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
238 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 234 base::FilePath indexed_db_path = indexed_db_context_->data_path();
239 235
240 GURL origin_url = 236 GURL origin_url =
241 webkit_base::GetOriginURLFromIdentifier(params.database_identifier); 237 webkit_base::GetOriginURLFromIdentifier(params.database_identifier);
242 238
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
244 240
245 int64 host_transaction_id = HostTransactionId(params.transaction_id); 241 int64 host_transaction_id = HostTransactionId(params.transaction_id);
246 242
247 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore 243 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
248 // created) if this origin is already over quota. 244 // created) if this origin is already over quota.
249 Context()->GetIDBFactory()->open( 245 Context()->GetIDBFactory()
250 params.name, 246 ->open(params.name,
251 params.version, 247 params.version,
252 host_transaction_id, 248 host_transaction_id,
253 new IndexedDBCallbacksDatabase(this, params.ipc_thread_id, 249 new IndexedDBCallbacksDatabase(this,
254 params.ipc_callbacks_id, 250 params.ipc_thread_id,
255 params.ipc_database_callbacks_id, 251 params.ipc_callbacks_id,
256 host_transaction_id, 252 params.ipc_database_callbacks_id,
257 origin_url), 253 host_transaction_id,
258 new IndexedDBDatabaseCallbacks(this, params.ipc_thread_id, 254 origin_url),
259 params.ipc_database_callbacks_id), 255 new IndexedDBDatabaseCallbacks(
260 params.database_identifier, 256 this, params.ipc_thread_id, params.ipc_database_callbacks_id),
261 webkit_base::FilePathToWebString(indexed_db_path)); 257 params.database_identifier,
258 webkit_base::FilePathToWebString(indexed_db_path));
262 } 259 }
263 260
264 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( 261 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase(
265 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { 262 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) {
266 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 263 base::FilePath indexed_db_path = indexed_db_context_->data_path();
267 264
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
269 Context()->GetIDBFactory()->deleteDatabase( 266 Context()->GetIDBFactory()
270 params.name, 267 ->deleteDatabase(params.name,
271 new IndexedDBCallbacks<WebData>(this, 268 new IndexedDBCallbacks<WebData>(
272 params.ipc_thread_id, 269 this, params.ipc_thread_id, params.ipc_callbacks_id),
273 params.ipc_callbacks_id), 270 params.database_identifier,
274 params.database_identifier, 271 webkit_base::FilePathToWebString(indexed_db_path));
275 webkit_base::FilePathToWebString(indexed_db_path));
276 } 272 }
277 273
278 void IndexedDBDispatcherHost::FinishTransaction( 274 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id,
279 int64 host_transaction_id, bool committed) { 275 bool committed) {
280 TransactionIDToURLMap& transaction_url_map = 276 TransactionIDToURLMap& transaction_url_map =
281 database_dispatcher_host_->transaction_url_map_; 277 database_dispatcher_host_->transaction_url_map_;
282 TransactionIDToSizeMap& transaction_size_map = 278 TransactionIDToSizeMap& transaction_size_map =
283 database_dispatcher_host_->transaction_size_map_; 279 database_dispatcher_host_->transaction_size_map_;
284 TransactionIDToDatabaseIDMap& transaction_database_map = 280 TransactionIDToDatabaseIDMap& transaction_database_map =
285 database_dispatcher_host_->transaction_database_map_; 281 database_dispatcher_host_->transaction_database_map_;
286 if (committed) 282 if (committed)
287 Context()->TransactionComplete(transaction_url_map[host_transaction_id]); 283 Context()->TransactionComplete(transaction_url_map[host_transaction_id]);
288 // It's unclear if std::map::erase(key) has defined behavior if the 284 // It's unclear if std::map::erase(key) has defined behavior if the
289 // key is not found. 285 // key is not found.
290 // TODO(alecflett): Remove if it is proven that it is safe. 286 // TODO(alecflett): Remove if it is proven that it is safe.
291 if (transaction_url_map.find(host_transaction_id) != 287 if (transaction_url_map.find(host_transaction_id) !=
292 transaction_url_map.end()) 288 transaction_url_map.end())
293 transaction_url_map.erase(host_transaction_id); 289 transaction_url_map.erase(host_transaction_id);
294 if (transaction_size_map.find(host_transaction_id) != 290 if (transaction_size_map.find(host_transaction_id) !=
295 transaction_size_map.end()) 291 transaction_size_map.end())
296 transaction_size_map.erase(host_transaction_id); 292 transaction_size_map.erase(host_transaction_id);
297 if (transaction_database_map.find(host_transaction_id) != 293 if (transaction_database_map.find(host_transaction_id) !=
298 transaction_database_map.end()) 294 transaction_database_map.end())
299 transaction_database_map.erase(host_transaction_id); 295 transaction_database_map.erase(host_transaction_id);
300 } 296 }
301 297
302 ////////////////////////////////////////////////////////////////////// 298 //////////////////////////////////////////////////////////////////////
303 // Helper templates. 299 // Helper templates.
304 // 300 //
305 301
306 template <typename ObjectType> 302 template <typename ObjectType>
307 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess( 303 ObjectType*
308 IDMap<ObjectType, IDMapOwnPointer>* map, int32 ipc_return_object_id) { 304 IndexedDBDispatcherHost::GetOrTerminateProcess(
305 IDMap<ObjectType, IDMapOwnPointer>* map,
306 int32 ipc_return_object_id) {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
310 ObjectType* return_object = map->Lookup(ipc_return_object_id); 308 ObjectType* return_object = map->Lookup(ipc_return_object_id);
311 if (!return_object) { 309 if (!return_object) {
312 NOTREACHED() << "Uh oh, couldn't find object with id " 310 NOTREACHED() << "Uh oh, couldn't find object with id "
313 << ipc_return_object_id; 311 << ipc_return_object_id;
314 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF")); 312 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF"));
315 BadMessageReceived(); 313 BadMessageReceived();
316 } 314 }
317 return return_object; 315 return return_object;
318 } 316 }
319 317
320 template <typename ObjectType> 318 template <typename ObjectType>
321 void IndexedDBDispatcherHost::DestroyObject( 319 void
322 IDMap<ObjectType, IDMapOwnPointer>* map, int32 ipc_object_id) { 320 IndexedDBDispatcherHost::DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map,
jamesr 2013/05/22 18:59:44 ditto
jsbell 2013/05/22 22:21:14 Done.
321 int32 ipc_object_id) {
323 GetOrTerminateProcess(map, ipc_object_id); 322 GetOrTerminateProcess(map, ipc_object_id);
324 map->Remove(ipc_object_id); 323 map->Remove(ipc_object_id);
325 } 324 }
326 325
327
328 ////////////////////////////////////////////////////////////////////// 326 //////////////////////////////////////////////////////////////////////
329 // IndexedDBDispatcherHost::DatabaseDispatcherHost 327 // IndexedDBDispatcherHost::DatabaseDispatcherHost
330 // 328 //
331 329
332 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost( 330 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost(
333 IndexedDBDispatcherHost* parent) 331 IndexedDBDispatcherHost* parent)
334 : parent_(parent) { 332 : parent_(parent) {
335 map_.set_check_on_null_data(true); 333 map_.set_check_on_null_data(true);
336 } 334 }
337 335
338 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() { 336 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() {
339 // TODO(alecflett): uncomment these when we find the source of these leaks. 337 // TODO(alecflett): uncomment these when we find the source of these leaks.
340 // DCHECK(transaction_size_map_.empty()); 338 // DCHECK(transaction_size_map_.empty());
341 // DCHECK(transaction_url_map_.empty()); 339 // DCHECK(transaction_url_map_.empty());
342 } 340 }
343 341
344 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() { 342 void IndexedDBDispatcherHost::DatabaseDispatcherHost::CloseAll() {
345 // Abort outstanding transactions started by connections in the associated 343 // Abort outstanding transactions started by connections in the associated
346 // front-end to unblock later transactions. This should only occur on unclean 344 // front-end to unblock later transactions. This should only occur on unclean
347 // (crash) or abrupt (process-kill) shutdowns. 345 // (crash) or abrupt (process-kill) shutdowns.
348 for (TransactionIDToDatabaseIDMap::iterator iter = 346 for (TransactionIDToDatabaseIDMap::iterator iter =
349 transaction_database_map_.begin(); 347 transaction_database_map_.begin();
350 iter != transaction_database_map_.end();) { 348 iter != transaction_database_map_.end();) {
351 int64 transaction_id = iter->first; 349 int64 transaction_id = iter->first;
352 int32 ipc_database_id = iter->second; 350 int32 ipc_database_id = iter->second;
353 ++iter; 351 ++iter;
354 WebIDBDatabase* database = map_.Lookup(ipc_database_id); 352 WebIDBDatabase* database = map_.Lookup(ipc_database_id);
355 if (database) { 353 if (database) {
356 database->abort(transaction_id, WebIDBDatabaseError( 354 database->abort(
357 WebKit::WebIDBDatabaseExceptionUnknownError)); 355 transaction_id,
356 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError));
358 } 357 }
359 } 358 }
360 DCHECK(transaction_database_map_.empty()); 359 DCHECK(transaction_database_map_.empty());
361 360
362 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); 361 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin();
363 iter != database_url_map_.end(); iter++) { 362 iter != database_url_map_.end();
363 iter++) {
364 WebIDBDatabase* database = map_.Lookup(iter->first); 364 WebIDBDatabase* database = map_.Lookup(iter->first);
365 if (database) { 365 if (database) {
366 database->close(); 366 database->close();
367 parent_->Context()->ConnectionClosed(iter->second, database); 367 parent_->Context()->ConnectionClosed(iter->second, database);
368 } 368 }
369 } 369 }
370 } 370 }
371 371
372 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived( 372 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
373 const IPC::Message& message, bool* msg_is_ok) { 373 const IPC::Message& message,
374 bool* msg_is_ok) {
374 bool handled = true; 375 bool handled = true;
375 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::DatabaseDispatcherHost, 376 IPC_BEGIN_MESSAGE_MAP_EX(
376 message, *msg_is_ok) 377 IndexedDBDispatcherHost::DatabaseDispatcherHost, message, *msg_is_ok)
377 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore, 378 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore,
378 OnCreateObjectStore) 379 OnCreateObjectStore)
379 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore, 380 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore,
380 OnDeleteObjectStore) 381 OnDeleteObjectStore)
381 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction, 382 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction,
382 OnCreateTransaction) 383 OnCreateTransaction)
383 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose) 384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose)
384 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed) 385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed)
385 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet) 386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseGet, OnGet)
386 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut) 387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabasePut, OnPut)
387 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, 388 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexKeys, OnSetIndexKeys)
388 OnSetIndexKeys) 389 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady,
389 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseSetIndexesReady, 390 OnSetIndexesReady)
390 OnSetIndexesReady) 391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor)
391 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseOpenCursor, OnOpenCursor) 392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount)
392 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCount, OnCount) 393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange)
393 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteRange, OnDeleteRange) 394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear)
394 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClear, OnClear) 395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, OnCreateIndex)
395 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateIndex, 396 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, OnDeleteIndex)
396 OnCreateIndex) 397 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort, OnAbort)
397 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteIndex, 398 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit, OnCommit)
398 OnDeleteIndex) 399 IPC_MESSAGE_UNHANDLED(handled = false)
399 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseAbort,
400 OnAbort)
401 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCommit,
402 OnCommit)
403 IPC_MESSAGE_UNHANDLED(handled = false)
404 IPC_END_MESSAGE_MAP() 400 IPC_END_MESSAGE_MAP()
405 return handled; 401 return handled;
406 } 402 }
407 403
408 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send( 404 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send(
409 IPC::Message* message) { 405 IPC::Message* message) {
410 parent_->Send(message); 406 parent_->Send(message);
411 } 407 }
412 408
413 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore( 409 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
414 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) { 410 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params) {
415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
416 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 412 WebIDBDatabase* database =
417 &map_, params.ipc_database_id); 413 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
418 if (!database) 414 if (!database)
419 return; 415 return;
420 416
421 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 417 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
422 database->createObjectStore( 418 database->createObjectStore(host_transaction_id,
423 host_transaction_id, 419 params.object_store_id,
424 params.object_store_id, 420 params.name,
425 params.name, params.key_path, params.auto_increment); 421 params.key_path,
422 params.auto_increment);
426 if (parent_->Context()->IsOverQuota( 423 if (parent_->Context()->IsOverQuota(
427 database_url_map_[params.ipc_database_id])) { 424 database_url_map_[params.ipc_database_id])) {
428 database->abort(host_transaction_id, WebIDBDatabaseError( 425 database->abort(
429 WebKit::WebIDBDatabaseExceptionQuotaError)); 426 host_transaction_id,
427 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
430 } 428 }
431 } 429 }
432 430
433 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( 431 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore(
434 int32 ipc_database_id, 432 int32 ipc_database_id,
435 int64 transaction_id, 433 int64 transaction_id,
436 int64 object_store_id) { 434 int64 object_store_id) {
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
438 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 436 WebIDBDatabase* database =
439 &map_, ipc_database_id); 437 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
440 if (!database) 438 if (!database)
441 return; 439 return;
442 440
443 database->deleteObjectStore(parent_->HostTransactionId(transaction_id), 441 database->deleteObjectStore(parent_->HostTransactionId(transaction_id),
444 object_store_id); 442 object_store_id);
445 } 443 }
446 444
447 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction( 445 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction(
448 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) { 446 const IndexedDBHostMsg_DatabaseCreateTransaction_Params& params) {
449 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 447 WebIDBDatabase* database =
450 &map_, params.ipc_database_id); 448 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
451 if (!database) 449 if (!database)
452 return; 450 return;
453 451
454 WebVector<long long> object_stores(params.object_store_ids.size()); 452 WebVector<long long> object_stores(params.object_store_ids.size());
455 for (size_t i = 0; i < params.object_store_ids.size(); ++i) 453 for (size_t i = 0; i < params.object_store_ids.size(); ++i)
456 object_stores[i] = params.object_store_ids[i]; 454 object_stores[i] = params.object_store_ids[i];
457 455
458 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 456 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
459 457
460 database->createTransaction( 458 database->createTransaction(
461 host_transaction_id, 459 host_transaction_id,
462 new IndexedDBDatabaseCallbacks(parent_, params.ipc_thread_id, 460 new IndexedDBDatabaseCallbacks(
463 params.ipc_database_callbacks_id), 461 parent_, params.ipc_thread_id, params.ipc_database_callbacks_id),
464 object_stores, params.mode); 462 object_stores,
463 params.mode);
465 transaction_database_map_[host_transaction_id] = params.ipc_database_id; 464 transaction_database_map_[host_transaction_id] = params.ipc_database_id;
466 parent_->RegisterTransactionId(host_transaction_id, 465 parent_->RegisterTransactionId(host_transaction_id,
467 database_url_map_[params.ipc_database_id]); 466 database_url_map_[params.ipc_database_id]);
468 } 467 }
469 468
470 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose( 469 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose(
471 int32 ipc_database_id) { 470 int32 ipc_database_id) {
472 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 471 WebIDBDatabase* database =
473 &map_, ipc_database_id); 472 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
474 if (!database) 473 if (!database)
475 return; 474 return;
476 database->close(); 475 database->close();
477 } 476 }
478 477
479 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed( 478 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
480 int32 ipc_object_id) { 479 int32 ipc_object_id) {
481 WebIDBDatabase* database = map_.Lookup(ipc_object_id); 480 WebIDBDatabase* database = map_.Lookup(ipc_object_id);
482 parent_->Context()->ConnectionClosed(database_url_map_[ipc_object_id], 481 parent_->Context()
483 database); 482 ->ConnectionClosed(database_url_map_[ipc_object_id], database);
484 database_url_map_.erase(ipc_object_id); 483 database_url_map_.erase(ipc_object_id);
485 parent_->DestroyObject(&map_, ipc_object_id); 484 parent_->DestroyObject(&map_, ipc_object_id);
486 } 485 }
487 486
488 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet( 487 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnGet(
489 const IndexedDBHostMsg_DatabaseGet_Params& params) { 488 const IndexedDBHostMsg_DatabaseGet_Params& params) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
491 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 490 WebIDBDatabase* database =
492 &map_, params.ipc_database_id); 491 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
493 if (!database) 492 if (!database)
494 return; 493 return;
495 494
496 scoped_ptr<WebIDBCallbacks> callbacks( 495 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>(
497 new IndexedDBCallbacks<WebData>( 496 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
498 parent_, params.ipc_thread_id,
499 params.ipc_callbacks_id));
500 database->get(parent_->HostTransactionId(params.transaction_id), 497 database->get(parent_->HostTransactionId(params.transaction_id),
501 params.object_store_id, 498 params.object_store_id,
502 params.index_id, 499 params.index_id,
503 params.key_range, params.key_only, callbacks.release()); 500 params.key_range,
501 params.key_only,
502 callbacks.release());
504 } 503 }
505 504
506 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut( 505 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnPut(
507 const IndexedDBHostMsg_DatabasePut_Params& params) { 506 const IndexedDBHostMsg_DatabasePut_Params& params) {
508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
509 508
510 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 509 WebIDBDatabase* database =
511 &map_, params.ipc_database_id); 510 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
512 if (!database) 511 if (!database)
513 return; 512 return;
514 scoped_ptr<WebIDBCallbacks> callbacks( 513 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebIDBKey>(
515 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id, 514 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
516 params.ipc_callbacks_id));
517 // Be careful with empty vectors. 515 // Be careful with empty vectors.
518 WebData value; 516 WebData value;
519 if (params.value.size()) 517 if (params.value.size())
520 value.assign(&params.value.front(), params.value.size()); 518 value.assign(&params.value.front(), params.value.size());
521 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 519 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
522 database->put(host_transaction_id, 520 database->put(host_transaction_id,
523 params.object_store_id, 521 params.object_store_id,
524 value, params.key, 522 value,
525 params.put_mode, callbacks.release(), 523 params.key,
524 params.put_mode,
525 callbacks.release(),
526 params.index_ids, 526 params.index_ids,
527 params.index_keys); 527 params.index_keys);
528 TransactionIDToSizeMap* map = 528 TransactionIDToSizeMap* map =
529 &parent_->database_dispatcher_host_->transaction_size_map_; 529 &parent_->database_dispatcher_host_->transaction_size_map_;
530 // Size can't be big enough to overflow because it represents the 530 // Size can't be big enough to overflow because it represents the
531 // actual bytes passed through IPC. 531 // actual bytes passed through IPC.
532 (*map)[host_transaction_id] += params.value.size(); 532 (*map)[host_transaction_id] += params.value.size();
533 } 533 }
534 534
535 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys( 535 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexKeys(
536 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) { 536 const IndexedDBHostMsg_DatabaseSetIndexKeys_Params& params) {
537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
538 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 538 WebIDBDatabase* database =
539 &map_, params.ipc_database_id); 539 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
540 if (!database) 540 if (!database)
541 return; 541 return;
542 542
543 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 543 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
544 if (params.index_ids.size() != params.index_keys.size()) { 544 if (params.index_ids.size() != params.index_keys.size()) {
545 database->abort(host_transaction_id, WebIDBDatabaseError( 545 database->abort(
546 WebKit::WebIDBDatabaseExceptionUnknownError, 546 host_transaction_id,
547 "Malformed IPC message: index_ids.size() != index_keys.size()")); 547 WebIDBDatabaseError(
548 WebKit::WebIDBDatabaseExceptionUnknownError,
549 "Malformed IPC message: index_ids.size() != index_keys.size()"));
548 return; 550 return;
549 } 551 }
550 552
551 database->setIndexKeys(host_transaction_id, 553 database->setIndexKeys(host_transaction_id,
552 params.object_store_id, 554 params.object_store_id,
553 params.primary_key, params.index_ids, 555 params.primary_key,
556 params.index_ids,
554 params.index_keys); 557 params.index_keys);
555 } 558 }
556 559
557 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady( 560 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnSetIndexesReady(
558 int32 ipc_database_id, 561 int32 ipc_database_id,
559 int64 transaction_id, 562 int64 transaction_id,
560 int64 object_store_id, 563 int64 object_store_id,
561 const std::vector<int64>& index_ids) { 564 const std::vector<int64>& index_ids) {
562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
563 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 566 WebIDBDatabase* database =
564 &map_, ipc_database_id); 567 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
565 if (!database) 568 if (!database)
566 return; 569 return;
567 570
568 database->setIndexesReady(parent_->HostTransactionId(transaction_id), 571 database->setIndexesReady(parent_->HostTransactionId(transaction_id),
569 object_store_id, 572 object_store_id,
570 WebVector<long long>(index_ids)); 573 WebVector<long long>(index_ids));
571 } 574 }
572 575
573 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor( 576 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnOpenCursor(
574 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) { 577 const IndexedDBHostMsg_DatabaseOpenCursor_Params& params) {
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
576 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 579 WebIDBDatabase* database =
577 &map_, params.ipc_database_id); 580 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
578 if (!database) 581 if (!database)
579 return; 582 return;
580 583
581 scoped_ptr<WebIDBCallbacks> callbacks( 584 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebIDBCursor>(
582 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id, 585 parent_, params.ipc_thread_id, params.ipc_callbacks_id, -1));
583 params.ipc_callbacks_id, -1)); 586 database->openCursor(parent_->HostTransactionId(params.transaction_id),
584 database->openCursor( 587 params.object_store_id,
585 parent_->HostTransactionId(params.transaction_id), 588 params.index_id,
586 params.object_store_id, params.index_id, 589 params.key_range,
587 params.key_range, params.direction, params.key_only, params.task_type, 590 params.direction,
588 callbacks.release()); 591 params.key_only,
592 params.task_type,
593 callbacks.release());
589 } 594 }
590 595
591 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount( 596 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCount(
592 const IndexedDBHostMsg_DatabaseCount_Params& params) { 597 const IndexedDBHostMsg_DatabaseCount_Params& params) {
593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
594 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 599 WebIDBDatabase* database =
595 &map_, params.ipc_database_id); 600 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
596 if (!database) 601 if (!database)
597 return; 602 return;
598 603
599 scoped_ptr<WebIDBCallbacks> callbacks( 604 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>(
600 new IndexedDBCallbacks<WebData>( 605 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
601 parent_, params.ipc_thread_id, 606 database->count(parent_->HostTransactionId(params.transaction_id),
602 params.ipc_callbacks_id)); 607 params.object_store_id,
603 database->count( 608 params.index_id,
604 parent_->HostTransactionId(params.transaction_id), 609 params.key_range,
605 params.object_store_id, params.index_id, 610 callbacks.release());
606 params.key_range, callbacks.release());
607 } 611 }
608 612
609 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange( 613 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteRange(
610 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) { 614 const IndexedDBHostMsg_DatabaseDeleteRange_Params& params) {
611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
612 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 616 WebIDBDatabase* database =
613 &map_, params.ipc_database_id); 617 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
614 if (!database) 618 if (!database)
615 return; 619 return;
616 620
617 scoped_ptr<WebIDBCallbacks> callbacks( 621 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>(
618 new IndexedDBCallbacks<WebData>( 622 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
619 parent_, params.ipc_thread_id,
620 params.ipc_callbacks_id));
621 database->deleteRange(parent_->HostTransactionId(params.transaction_id), 623 database->deleteRange(parent_->HostTransactionId(params.transaction_id),
622 params.object_store_id, 624 params.object_store_id,
623 params.key_range, callbacks.release()); 625 params.key_range,
626 callbacks.release());
624 } 627 }
625 628
626 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear( 629 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClear(
627 int32 ipc_thread_id, 630 int32 ipc_thread_id,
628 int32 ipc_callbacks_id, 631 int32 ipc_callbacks_id,
629 int32 ipc_database_id, 632 int32 ipc_database_id,
630 int64 transaction_id, 633 int64 transaction_id,
631 int64 object_store_id) { 634 int64 object_store_id) {
632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
633 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 636 WebIDBDatabase* database =
634 &map_, ipc_database_id); 637 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
635 if (!database) 638 if (!database)
636 return; 639 return;
637 640
638 scoped_ptr<WebIDBCallbacks> callbacks( 641 scoped_ptr<WebIDBCallbacks> callbacks(new IndexedDBCallbacks<WebData>(
639 new IndexedDBCallbacks<WebData>( 642 parent_, ipc_thread_id, ipc_callbacks_id));
640 parent_, ipc_thread_id,
641 ipc_callbacks_id));
642 643
643 database->clear(parent_->HostTransactionId(transaction_id), 644 database->clear(parent_->HostTransactionId(transaction_id),
644 object_store_id, callbacks.release()); 645 object_store_id,
646 callbacks.release());
645 } 647 }
646 648
647 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort( 649 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnAbort(
648 int32 ipc_database_id, 650 int32 ipc_database_id,
649 int64 transaction_id) { 651 int64 transaction_id) {
650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
651 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 653 WebIDBDatabase* database =
652 &map_, ipc_database_id); 654 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
653 if (!database) 655 if (!database)
654 return; 656 return;
655 657
656 database->abort(parent_->HostTransactionId(transaction_id)); 658 database->abort(parent_->HostTransactionId(transaction_id));
657 } 659 }
658 660
659 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit( 661 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCommit(
660 int32 ipc_database_id, 662 int32 ipc_database_id,
661 int64 transaction_id) { 663 int64 transaction_id) {
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
663 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 665 WebIDBDatabase* database =
664 &map_, ipc_database_id); 666 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
665 if (!database) 667 if (!database)
666 return; 668 return;
667 669
668 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); 670 int64 host_transaction_id = parent_->HostTransactionId(transaction_id);
669 int64 transaction_size = transaction_size_map_[host_transaction_id]; 671 int64 transaction_size = transaction_size_map_[host_transaction_id];
670 if (transaction_size && parent_->Context()->WouldBeOverQuota( 672 if (transaction_size &&
671 transaction_url_map_[host_transaction_id], transaction_size)) { 673 parent_->Context()->WouldBeOverQuota(
672 database->abort(host_transaction_id, WebIDBDatabaseError( 674 transaction_url_map_[host_transaction_id], transaction_size)) {
673 WebKit::WebIDBDatabaseExceptionQuotaError)); 675 database->abort(
676 host_transaction_id,
677 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
674 return; 678 return;
675 } 679 }
676 680
677 database->commit(host_transaction_id); 681 database->commit(host_transaction_id);
678 } 682 }
679 683
680 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( 684 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex(
681 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { 685 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) {
682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
683 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 687 WebIDBDatabase* database =
684 &map_, params.ipc_database_id); 688 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
685 if (!database) 689 if (!database)
686 return; 690 return;
687 691
688 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 692 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
689 database->createIndex( 693 database->createIndex(host_transaction_id,
690 host_transaction_id, 694 params.object_store_id,
691 params.object_store_id, 695 params.index_id,
692 params.index_id, 696 params.name,
693 params.name, 697 params.key_path,
694 params.key_path, 698 params.unique,
695 params.unique, 699 params.multi_entry);
696 params.multi_entry);
697 if (parent_->Context()->IsOverQuota( 700 if (parent_->Context()->IsOverQuota(
698 database_url_map_[params.ipc_database_id])) { 701 database_url_map_[params.ipc_database_id])) {
699 database->abort(host_transaction_id, WebIDBDatabaseError( 702 database->abort(
700 WebKit::WebIDBDatabaseExceptionQuotaError)); 703 host_transaction_id,
704 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError));
701 } 705 }
702 } 706 }
703 707
704 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( 708 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex(
705 int32 ipc_database_id, 709 int32 ipc_database_id,
706 int64 transaction_id, 710 int64 transaction_id,
707 int64 object_store_id, 711 int64 object_store_id,
708 int64 index_id) { 712 int64 index_id) {
709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
710 WebIDBDatabase* database = parent_->GetOrTerminateProcess( 714 WebIDBDatabase* database =
711 &map_, ipc_database_id); 715 parent_->GetOrTerminateProcess(&map_, ipc_database_id);
712 if (!database) 716 if (!database)
713 return; 717 return;
714 718
715 database->deleteIndex(parent_->HostTransactionId(transaction_id), 719 database->deleteIndex(
716 object_store_id, index_id); 720 parent_->HostTransactionId(transaction_id), object_store_id, index_id);
717 } 721 }
718 722
719 ////////////////////////////////////////////////////////////////////// 723 //////////////////////////////////////////////////////////////////////
720 // IndexedDBDispatcherHost::CursorDispatcherHost 724 // IndexedDBDispatcherHost::CursorDispatcherHost
721 // 725 //
722 726
723 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost( 727 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost(
724 IndexedDBDispatcherHost* parent) 728 IndexedDBDispatcherHost* parent)
725 : parent_(parent) { 729 : parent_(parent) {
726 map_.set_check_on_null_data(true); 730 map_.set_check_on_null_data(true);
727 } 731 }
728 732
729 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() { 733 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {}
730 }
731 734
732 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived( 735 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived(
733 const IPC::Message& message, bool* msg_is_ok) { 736 const IPC::Message& message,
737 bool* msg_is_ok) {
734 bool handled = true; 738 bool handled = true;
735 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::CursorDispatcherHost, 739 IPC_BEGIN_MESSAGE_MAP_EX(
736 message, *msg_is_ok) 740 IndexedDBDispatcherHost::CursorDispatcherHost, message, *msg_is_ok)
737 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance) 741 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance)
738 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue) 742 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue)
739 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch) 743 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch)
740 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset) 744 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset)
741 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDelete, OnDelete) 745 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDelete, OnDelete)
742 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed) 746 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed)
743 IPC_MESSAGE_UNHANDLED(handled = false) 747 IPC_MESSAGE_UNHANDLED(handled = false)
744 IPC_END_MESSAGE_MAP() 748 IPC_END_MESSAGE_MAP()
745 return handled; 749 return handled;
746 } 750 }
747 751
748
749 void IndexedDBDispatcherHost::CursorDispatcherHost::Send( 752 void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
750 IPC::Message* message) { 753 IPC::Message* message) {
751 parent_->Send(message); 754 parent_->Send(message);
752 } 755 }
753 756
754
755 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance( 757 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance(
756 int32 ipc_cursor_id, 758 int32 ipc_cursor_id,
757 int32 ipc_thread_id, 759 int32 ipc_thread_id,
758 int32 ipc_callbacks_id, 760 int32 ipc_callbacks_id,
759 unsigned long count) { 761 unsigned long count) {
760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
761 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess( 763 WebIDBCursor* idb_cursor =
762 &map_, ipc_cursor_id); 764 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
763 if (!idb_cursor) 765 if (!idb_cursor)
764 return; 766 return;
765 767
766 idb_cursor->advance(count, 768 idb_cursor->advance(
767 new IndexedDBCallbacks<WebIDBCursor>(parent_, 769 count,
768 ipc_thread_id, 770 new IndexedDBCallbacks<WebIDBCursor>(
769 ipc_callbacks_id, 771 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
770 ipc_cursor_id));
771 } 772 }
772 773
773 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue( 774 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue(
774 int32 ipc_cursor_id, 775 int32 ipc_cursor_id,
775 int32 ipc_thread_id, 776 int32 ipc_thread_id,
776 int32 ipc_callbacks_id, 777 int32 ipc_callbacks_id,
777 const IndexedDBKey& key) { 778 const IndexedDBKey& key) {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
779 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, 780 WebIDBCursor* idb_cursor =
780 ipc_cursor_id); 781 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
781 if (!idb_cursor) 782 if (!idb_cursor)
782 return; 783 return;
783 784
784 idb_cursor->continueFunction( 785 idb_cursor->continueFunction(
785 key, new IndexedDBCallbacks<WebIDBCursor>(parent_, ipc_thread_id, 786 key,
786 ipc_callbacks_id, 787 new IndexedDBCallbacks<WebIDBCursor>(
787 ipc_cursor_id)); 788 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
788 } 789 }
789 790
790 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch( 791 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch(
791 int32 ipc_cursor_id, 792 int32 ipc_cursor_id,
792 int32 ipc_thread_id, 793 int32 ipc_thread_id,
793 int32 ipc_callbacks_id, 794 int32 ipc_callbacks_id,
794 int n) { 795 int n) {
795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
796 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, 797 WebIDBCursor* idb_cursor =
797 ipc_cursor_id); 798 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
798 if (!idb_cursor) 799 if (!idb_cursor)
799 return; 800 return;
800 801
801 idb_cursor->prefetchContinue( 802 idb_cursor->prefetchContinue(
802 n, new IndexedDBCallbacks<WebIDBCursor>(parent_, ipc_thread_id, 803 n,
803 ipc_callbacks_id, 804 new IndexedDBCallbacks<WebIDBCursor>(
804 ipc_cursor_id)); 805 parent_, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
805 } 806 }
806 807
807 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset( 808 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset(
808 int32 ipc_cursor_id, int used_prefetches, int unused_prefetches) { 809 int32 ipc_cursor_id,
810 int used_prefetches,
811 int unused_prefetches) {
809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 812 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
810 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, 813 WebIDBCursor* idb_cursor =
811 ipc_cursor_id); 814 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
812 if (!idb_cursor) 815 if (!idb_cursor)
813 return; 816 return;
814 817
815 idb_cursor->prefetchReset(used_prefetches, unused_prefetches); 818 idb_cursor->prefetchReset(used_prefetches, unused_prefetches);
816 } 819 }
817 820
818 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDelete( 821 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDelete(
819 int32 ipc_cursor_id, 822 int32 ipc_cursor_id,
820 int32 ipc_thread_id, 823 int32 ipc_thread_id,
821 int32 ipc_callbacks_id) { 824 int32 ipc_callbacks_id) {
822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
823 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_, 826 WebIDBCursor* idb_cursor =
824 ipc_cursor_id); 827 parent_->GetOrTerminateProcess(&map_, ipc_cursor_id);
825 if (!idb_cursor) 828 if (!idb_cursor)
826 return; 829 return;
827 830
828 idb_cursor->deleteFunction( 831 idb_cursor->deleteFunction(new IndexedDBCallbacks<WebData>(
829 new IndexedDBCallbacks<WebData>(parent_, ipc_thread_id, 832 parent_, ipc_thread_id, ipc_callbacks_id));
830 ipc_callbacks_id));
831 } 833 }
832 834
833 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 835 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
834 int32 ipc_object_id) { 836 int32 ipc_object_id) {
835 parent_->DestroyObject(&map_, ipc_object_id); 837 parent_->DestroyObject(&map_, ipc_object_id);
836 } 838 }
837 839
838 } // namespace content 840 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698