[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / browser / in_process_webkit / indexed_db_dispatcher_host.cc
blob3f46966c2b36c15e7d7d16f288e364a65a3cba00
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.
5 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/process.h"
12 #include "base/process_util.h"
13 #include "base/utf_string_conversions.h"
14 #include "content/browser/in_process_webkit/indexed_db_callbacks.h"
15 #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
16 #include "content/browser/in_process_webkit/indexed_db_database_callbacks.h"
17 #include "content/browser/in_process_webkit/indexed_db_transaction_callbacks.h"
18 #include "content/browser/renderer_host/render_message_filter.h"
19 #include "content/common/indexed_db/indexed_db_messages.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/user_metrics.h"
22 #include "content/public/common/content_switches.h"
23 #include "content/public/common/result_codes.h"
24 #include "googleurl/src/gurl.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMStringList.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBCursor.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabase.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBDatabaseCallbacks.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBFactory.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBIndex.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBMetadata.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBObjectStore.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
36 #include "webkit/base/file_path_string_conversions.h"
37 #include "webkit/database/database_util.h"
39 using webkit_database::DatabaseUtil;
40 using WebKit::WebDOMStringList;
41 using WebKit::WebExceptionCode;
42 using WebKit::WebIDBCallbacks;
43 using WebKit::WebIDBCursor;
44 using WebKit::WebIDBDatabase;
45 using WebKit::WebIDBIndex;
46 using WebKit::WebIDBKey;
47 using WebKit::WebIDBMetadata;
48 using WebKit::WebIDBObjectStore;
49 using WebKit::WebIDBTransaction;
50 using WebKit::WebSecurityOrigin;
51 using WebKit::WebSerializedScriptValue;
52 using WebKit::WebVector;
54 namespace content {
55 namespace {
57 template <class T>
58 void DeleteOnWebKitThread(T* obj) {
59 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT_DEPRECATED,
60 FROM_HERE, obj))
61 delete obj;
65 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
66 int ipc_process_id, IndexedDBContextImpl* indexed_db_context)
67 : indexed_db_context_(indexed_db_context),
68 ALLOW_THIS_IN_INITIALIZER_LIST(database_dispatcher_host_(
69 new DatabaseDispatcherHost(this))),
70 ALLOW_THIS_IN_INITIALIZER_LIST(index_dispatcher_host_(
71 new IndexDispatcherHost(this))),
72 ALLOW_THIS_IN_INITIALIZER_LIST(object_store_dispatcher_host_(
73 new ObjectStoreDispatcherHost(this))),
74 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_dispatcher_host_(
75 new CursorDispatcherHost(this))),
76 ALLOW_THIS_IN_INITIALIZER_LIST(transaction_dispatcher_host_(
77 new TransactionDispatcherHost(this))),
78 ipc_process_id_(ipc_process_id) {
79 DCHECK(indexed_db_context_.get());
82 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {
85 void IndexedDBDispatcherHost::OnChannelClosing() {
86 BrowserMessageFilter::OnChannelClosing();
88 bool success = BrowserThread::PostTask(
89 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
90 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this));
92 if (!success)
93 ResetDispatcherHosts();
96 void IndexedDBDispatcherHost::ResetDispatcherHosts() {
97 // It is important that the various *_dispatcher_host_ members are reset
98 // on the WebKit thread, since there might be incoming messages on that
99 // thread, and we must not reset the dispatcher hosts until after those
100 // messages are processed.
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED) ||
102 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess));
104 database_dispatcher_host_.reset();
105 index_dispatcher_host_.reset();
106 object_store_dispatcher_host_.reset();
107 cursor_dispatcher_host_.reset();
108 transaction_dispatcher_host_.reset();
111 void IndexedDBDispatcherHost::OverrideThreadForMessage(
112 const IPC::Message& message,
113 BrowserThread::ID* thread) {
114 if (IPC_MESSAGE_CLASS(message) == IndexedDBMsgStart)
115 *thread = BrowserThread::WEBKIT_DEPRECATED;
118 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message,
119 bool* message_was_ok) {
120 if (IPC_MESSAGE_CLASS(message) != IndexedDBMsgStart)
121 return false;
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
125 bool handled =
126 database_dispatcher_host_->OnMessageReceived(message, message_was_ok) ||
127 index_dispatcher_host_->OnMessageReceived(message, message_was_ok) ||
128 object_store_dispatcher_host_->OnMessageReceived(
129 message, message_was_ok) ||
130 cursor_dispatcher_host_->OnMessageReceived(message, message_was_ok) ||
131 transaction_dispatcher_host_->OnMessageReceived(message, message_was_ok);
133 if (!handled) {
134 handled = true;
135 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, *message_was_ok)
136 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryGetDatabaseNames,
137 OnIDBFactoryGetDatabaseNames)
138 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpen, OnIDBFactoryOpen)
139 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryOpenOld, OnIDBFactoryOpenOld)
140 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_FactoryDeleteDatabase,
141 OnIDBFactoryDeleteDatabase)
142 IPC_MESSAGE_UNHANDLED(handled = false)
143 IPC_END_MESSAGE_MAP()
145 return handled;
148 int32 IndexedDBDispatcherHost::Add(WebIDBCursor* idb_cursor) {
149 if (!cursor_dispatcher_host_.get()) {
150 delete idb_cursor;
151 return 0;
153 return cursor_dispatcher_host_->map_.Add(idb_cursor);
156 int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database,
157 int32 ipc_thread_id,
158 const GURL& origin_url) {
159 if (!database_dispatcher_host_.get()) {
160 delete idb_database;
161 return 0;
163 int32 ipc_database_id = database_dispatcher_host_->map_.Add(idb_database);
164 Context()->ConnectionOpened(origin_url, idb_database);
165 database_dispatcher_host_->database_url_map_[ipc_database_id] = origin_url;
166 return ipc_database_id;
169 int32 IndexedDBDispatcherHost::Add(WebIDBIndex* idb_index) {
170 if (!index_dispatcher_host_.get()) {
171 delete idb_index;
172 return 0;
174 if (!idb_index)
175 return 0;
176 return index_dispatcher_host_->map_.Add(idb_index);
179 int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) {
180 if (!object_store_dispatcher_host_.get()) {
181 delete idb_object_store;
182 return 0;
184 if (!idb_object_store)
185 return 0;
186 return object_store_dispatcher_host_->map_.Add(idb_object_store);
189 int32 IndexedDBDispatcherHost::Add(WebIDBTransaction* idb_transaction,
190 int32 ipc_thread_id,
191 const GURL& url) {
192 if (!transaction_dispatcher_host_.get()) {
193 delete idb_transaction;
194 return 0;
196 int32 id = transaction_dispatcher_host_->map_.Add(idb_transaction);
197 idb_transaction->setCallbacks(
198 new IndexedDBTransactionCallbacks(this, ipc_thread_id, id));
199 transaction_dispatcher_host_->transaction_url_map_[id] = url;
200 return id;
203 int64 IndexedDBDispatcherHost::HostTransactionId(int64 transaction_id) {
204 // Inject the renderer process id into the transaction id, to
205 // uniquely identify this transaction, and effectively bind it to
206 // the renderer that initiated it. The lower 32 bits of
207 // transaction_id are guaranteed to be unique within that renderer.
208 base::ProcessId pid = base::GetProcId(peer_handle());
209 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
210 COMPILE_ASSERT(sizeof(base::ProcessId) <= sizeof(int32),
211 Process_ID_must_fit_in_32_bits);
213 return transaction_id |= (static_cast<uint64>(pid) << 32);
216 WebIDBCursor* IndexedDBDispatcherHost::GetCursorFromId(int32 ipc_cursor_id) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
218 return cursor_dispatcher_host_->map_.Lookup(ipc_cursor_id);
221 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames(
222 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) {
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
224 FilePath indexed_db_path = indexed_db_context_->data_path();
226 WebSecurityOrigin origin(
227 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin));
229 Context()->GetIDBFactory()->getDatabaseNames(
230 new IndexedDBCallbacks<WebDOMStringList>(this, params.ipc_thread_id,
231 params.ipc_response_id), origin, NULL,
232 webkit_base::FilePathToWebString(indexed_db_path));
235 void IndexedDBDispatcherHost::OnIDBFactoryOpenOld(
236 const IndexedDBHostMsg_FactoryOpen_Params& params) {
237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
238 FilePath indexed_db_path = indexed_db_context_->data_path();
240 GURL origin_url = DatabaseUtil::GetOriginFromIdentifier(params.origin);
241 WebSecurityOrigin origin(
242 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin));
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
246 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
247 // created) if this origin is already over quota.
248 Context()->GetIDBFactory()->open(
249 params.name,
250 params.version,
251 new IndexedDBCallbacksDatabase(this, params.ipc_thread_id,
252 params.ipc_response_id, origin_url),
253 new IndexedDBDatabaseCallbacks(this, params.ipc_thread_id,
254 params.ipc_database_response_id),
255 origin, NULL, webkit_base::FilePathToWebString(indexed_db_path));
258 void IndexedDBDispatcherHost::OnIDBFactoryOpen(
259 const IndexedDBHostMsg_FactoryOpen_Params& params) {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
261 FilePath indexed_db_path = indexed_db_context_->data_path();
263 GURL origin_url = DatabaseUtil::GetOriginFromIdentifier(params.origin);
264 WebSecurityOrigin origin(
265 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin));
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
269 int64 transaction_id = HostTransactionId(params.transaction_id);
271 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
272 // created) if this origin is already over quota.
273 Context()->GetIDBFactory()->open(
274 params.name,
275 params.version,
276 transaction_id,
277 new IndexedDBCallbacksDatabase(this, params.ipc_thread_id,
278 params.ipc_response_id, origin_url),
279 new IndexedDBDatabaseCallbacks(this, params.ipc_thread_id,
280 params.ipc_database_response_id),
281 origin, NULL, webkit_base::FilePathToWebString(indexed_db_path));
284 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase(
285 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) {
286 FilePath indexed_db_path = indexed_db_context_->data_path();
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
289 Context()->GetIDBFactory()->deleteDatabase(
290 params.name,
291 new IndexedDBCallbacks<WebSerializedScriptValue>(this,
292 params.ipc_thread_id,
293 params.ipc_response_id),
294 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin), NULL,
295 webkit_base::FilePathToWebString(indexed_db_path));
298 void IndexedDBDispatcherHost::TransactionComplete(int32 ipc_transaction_id) {
299 Context()->TransactionComplete(
300 transaction_dispatcher_host_->transaction_url_map_[ipc_transaction_id]);
303 //////////////////////////////////////////////////////////////////////
304 // Helper templates.
307 template <typename ObjectType>
308 ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess(
309 IDMap<ObjectType, IDMapOwnPointer>* map, int32 ipc_return_object_id) {
310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
311 ObjectType* return_object = map->Lookup(ipc_return_object_id);
312 if (!return_object) {
313 NOTREACHED() << "Uh oh, couldn't find object with id "
314 << ipc_return_object_id;
315 RecordAction(UserMetricsAction("BadMessageTerminate_IDBMF"));
316 BadMessageReceived();
318 return return_object;
321 template <typename ObjectType>
322 void IndexedDBDispatcherHost::DestroyObject(
323 IDMap<ObjectType, IDMapOwnPointer>* map, int32 ipc_object_id) {
324 GetOrTerminateProcess(map, ipc_object_id);
325 map->Remove(ipc_object_id);
329 //////////////////////////////////////////////////////////////////////
330 // IndexedDBDispatcherHost::DatabaseDispatcherHost
333 IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost(
334 IndexedDBDispatcherHost* parent)
335 : parent_(parent) {
336 map_.set_check_on_null_data(true);
339 IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() {
340 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin();
341 iter != database_url_map_.end(); iter++) {
342 WebIDBDatabase* database = map_.Lookup(iter->first);
343 if (database) {
344 database->close();
345 parent_->Context()->ConnectionClosed(iter->second, database);
350 bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
351 const IPC::Message& message, bool* msg_is_ok) {
352 bool handled = true;
353 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::DatabaseDispatcherHost,
354 message, *msg_is_ok)
355 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseMetadata, OnMetadata)
356 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateObjectStore,
357 OnCreateObjectStore)
358 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDeleteObjectStore,
359 OnDeleteObjectStore)
360 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseCreateTransaction,
361 OnCreateTransaction)
362 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseClose, OnClose)
363 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_DatabaseDestroyed, OnDestroyed)
364 IPC_MESSAGE_UNHANDLED(handled = false)
365 IPC_END_MESSAGE_MAP()
366 return handled;
369 void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send(
370 IPC::Message* message) {
371 parent_->Send(message);
374 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMetadata(
375 int32 ipc_database_id, IndexedDBDatabaseMetadata* metadata) {
376 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
377 &map_, ipc_database_id);
378 if (!idb_database)
379 return;
381 WebIDBMetadata web_metadata = idb_database->metadata();
382 metadata->id = web_metadata.id;
383 metadata->name = web_metadata.name;
384 metadata->version = web_metadata.version;
385 metadata->int_version = web_metadata.intVersion;
386 metadata->max_object_store_id = web_metadata.maxObjectStoreId;
388 for (size_t i = 0; i < web_metadata.objectStores.size(); ++i) {
389 const WebIDBMetadata::ObjectStore& web_store_metadata =
390 web_metadata.objectStores[i];
391 IndexedDBObjectStoreMetadata idb_store_metadata;
392 idb_store_metadata.id = web_store_metadata.id;
393 idb_store_metadata.name = web_store_metadata.name;
394 idb_store_metadata.keyPath = IndexedDBKeyPath(web_store_metadata.keyPath);
395 idb_store_metadata.autoIncrement = web_store_metadata.autoIncrement;
396 idb_store_metadata.max_index_id = web_store_metadata.maxIndexId;
398 for (size_t j = 0; j < web_store_metadata.indexes.size(); ++j) {
399 const WebIDBMetadata::Index& web_index_metadata =
400 web_store_metadata.indexes[j];
401 IndexedDBIndexMetadata idb_index_metadata;
402 idb_index_metadata.id = web_index_metadata.id;
403 idb_index_metadata.name = web_index_metadata.name;
404 idb_index_metadata.keyPath = IndexedDBKeyPath(web_index_metadata.keyPath);
405 idb_index_metadata.unique = web_index_metadata.unique;
406 idb_index_metadata.multiEntry = web_index_metadata.multiEntry;
407 idb_store_metadata.indexes.push_back(idb_index_metadata);
409 metadata->object_stores.push_back(idb_store_metadata);
413 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
414 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params,
415 int32* object_store_id, WebKit::WebExceptionCode* ec) {
416 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
417 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
418 &map_, params.ipc_database_id);
419 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
420 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
421 if (!idb_database || !idb_transaction)
422 return;
424 *ec = 0;
425 WebIDBObjectStore* object_store = idb_database->createObjectStore(
426 params.id, params.name, params.key_path, params.auto_increment,
427 *idb_transaction, *ec);
428 *object_store_id = *ec ? 0 : parent_->Add(object_store);
429 if (parent_->Context()->IsOverQuota(
430 database_url_map_[params.ipc_database_id])) {
431 idb_transaction->abort();
435 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore(
436 int32 ipc_database_id,
437 int64 index_id,
438 int32 ipc_transaction_id,
439 WebKit::WebExceptionCode* ec) {
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
441 WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
442 &map_, ipc_database_id);
443 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
444 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
445 if (!idb_database || !idb_transaction)
446 return;
448 *ec = 0;
449 idb_database->deleteObjectStore(index_id, *idb_transaction, *ec);
452 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateTransaction(
453 int32 ipc_thread_id,
454 int32 ipc_database_id,
455 int64 transaction_id,
456 const std::vector<int64>& object_store_ids,
457 int32 mode,
458 int32* ipc_transaction_id) {
459 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
460 &map_, ipc_database_id);
461 if (!database)
462 return;
464 WebVector<long long> object_stores(object_store_ids.size());
465 for (size_t i = 0; i < object_store_ids.size(); ++i)
466 object_stores[i] = object_store_ids[i];
468 transaction_id = parent_->HostTransactionId(transaction_id);
470 WebIDBTransaction* transaction = database->createTransaction(
471 transaction_id, object_stores, mode);
472 *ipc_transaction_id = parent_->Add(transaction, ipc_thread_id,
473 database_url_map_[ipc_database_id]);
476 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnClose(
477 int32 ipc_database_id) {
478 WebIDBDatabase* database = parent_->GetOrTerminateProcess(
479 &map_, ipc_database_id);
480 if (!database)
481 return;
482 database->close();
485 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
486 int32 ipc_object_id) {
487 WebIDBDatabase* database = map_.Lookup(ipc_object_id);
488 parent_->Context()->ConnectionClosed(database_url_map_[ipc_object_id],
489 database);
490 database_url_map_.erase(ipc_object_id);
491 parent_->DestroyObject(&map_, ipc_object_id);
495 //////////////////////////////////////////////////////////////////////
496 // IndexedDBDispatcherHost::IndexDispatcherHost
499 IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost(
500 IndexedDBDispatcherHost* parent)
501 : parent_(parent) {
502 map_.set_check_on_null_data(true);
505 IndexedDBDispatcherHost::IndexDispatcherHost::~IndexDispatcherHost() {
508 bool IndexedDBDispatcherHost::IndexDispatcherHost::OnMessageReceived(
509 const IPC::Message& message, bool* msg_is_ok) {
510 bool handled = true;
511 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::IndexDispatcherHost,
512 message, *msg_is_ok)
513 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_IndexOpenObjectCursor,
514 OnOpenObjectCursor)
515 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_IndexOpenKeyCursor, OnOpenKeyCursor)
516 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_IndexCount, OnCount)
517 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_IndexGetObject, OnGetObject)
518 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_IndexGetKey, OnGetKey)
519 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_IndexDestroyed, OnDestroyed)
520 IPC_MESSAGE_UNHANDLED(handled = false)
521 IPC_END_MESSAGE_MAP()
522 return handled;
525 void IndexedDBDispatcherHost::IndexDispatcherHost::Send(
526 IPC::Message* message) {
527 parent_->Send(message);
530 void IndexedDBDispatcherHost::IndexDispatcherHost::OnOpenObjectCursor(
531 const IndexedDBHostMsg_IndexOpenCursor_Params& params) {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
533 WebIDBIndex* idb_index = parent_->GetOrTerminateProcess(
534 &map_, params.ipc_index_id);
535 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
536 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
537 if (!idb_transaction || !idb_index)
538 return;
540 WebKit::WebExceptionCode ec = 0;
541 scoped_ptr<WebIDBCallbacks> callbacks(
542 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id,
543 params.ipc_response_id, -1));
544 idb_index->openObjectCursor(
545 params.key_range, params.direction, callbacks.release(),
546 *idb_transaction, ec);
547 DCHECK(!ec);
550 void IndexedDBDispatcherHost::IndexDispatcherHost::OnOpenKeyCursor(
551 const IndexedDBHostMsg_IndexOpenCursor_Params& params) {
552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
553 WebIDBIndex* idb_index = parent_->GetOrTerminateProcess(
554 &map_, params.ipc_index_id);
555 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
556 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
557 if (!idb_transaction || !idb_index)
558 return;
560 WebKit::WebExceptionCode ec = 0;
561 scoped_ptr<WebIDBCallbacks> callbacks(
562 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id,
563 params.ipc_response_id, -1));
564 idb_index->openKeyCursor(
565 params.key_range, params.direction, callbacks.release(),
566 *idb_transaction, ec);
567 DCHECK(!ec);
570 void IndexedDBDispatcherHost::IndexDispatcherHost::OnCount(
571 const IndexedDBHostMsg_IndexCount_Params& params) {
572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
573 WebIDBIndex* idb_index = parent_->GetOrTerminateProcess(
574 &map_, params.ipc_index_id);
575 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
576 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
577 if (!idb_transaction || !idb_index)
578 return;
580 WebKit::WebExceptionCode ec = 0;
581 scoped_ptr<WebIDBCallbacks> callbacks(
582 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_,
583 params.ipc_thread_id,
584 params.ipc_response_id));
585 idb_index->count(
586 params.key_range, callbacks.release(), *idb_transaction, ec);
587 DCHECK(!ec);
590 void IndexedDBDispatcherHost::IndexDispatcherHost::OnGetObject(
591 int ipc_index_id,
592 int32 ipc_thread_id,
593 int32 ipc_response_id,
594 const IndexedDBKeyRange& key_range,
595 int32 ipc_transaction_id) {
596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
597 WebIDBIndex* idb_index = parent_->GetOrTerminateProcess(
598 &map_, ipc_index_id);
599 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
600 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
601 if (!idb_transaction || !idb_index)
602 return;
604 WebKit::WebExceptionCode ec = 0;
605 scoped_ptr<WebIDBCallbacks> callbacks(
606 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_, ipc_thread_id,
607 ipc_response_id));
608 idb_index->getObject(key_range, callbacks.release(), *idb_transaction, ec);
609 DCHECK(!ec);
612 void IndexedDBDispatcherHost::IndexDispatcherHost::OnGetKey(
613 int ipc_index_id,
614 int32 ipc_thread_id,
615 int32 ipc_response_id,
616 const IndexedDBKeyRange& key_range,
617 int32 ipc_transaction_id) {
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
619 WebIDBIndex* idb_index = parent_->GetOrTerminateProcess(
620 &map_, ipc_index_id);
621 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
622 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
623 if (!idb_transaction || !idb_index)
624 return;
626 WebKit::WebExceptionCode ec = 0;
627 scoped_ptr<WebIDBCallbacks> callbacks(
628 new IndexedDBCallbacks<WebIDBKey>(parent_, ipc_thread_id,
629 ipc_response_id));
630 idb_index->getKey(key_range, callbacks.release(), *idb_transaction, ec);
631 DCHECK(!ec);
634 void IndexedDBDispatcherHost::IndexDispatcherHost::OnDestroyed(
635 int32 ipc_object_id) {
636 parent_->DestroyObject(&map_, ipc_object_id);
639 //////////////////////////////////////////////////////////////////////
640 // IndexedDBDispatcherHost::ObjectStoreDispatcherHost
643 IndexedDBDispatcherHost::ObjectStoreDispatcherHost::ObjectStoreDispatcherHost(
644 IndexedDBDispatcherHost* parent)
645 : parent_(parent) {
646 map_.set_check_on_null_data(true);
649 IndexedDBDispatcherHost::
650 ObjectStoreDispatcherHost::~ObjectStoreDispatcherHost() {
653 bool IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnMessageReceived(
654 const IPC::Message& message, bool* msg_is_ok) {
655 bool handled = true;
656 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::ObjectStoreDispatcherHost,
657 message, *msg_is_ok)
658 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreGet, OnGet)
659 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStorePut, OnPut)
660 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreSetIndexKeys,
661 OnSetIndexKeys)
662 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreSetIndexesReady,
663 OnSetIndexesReady)
664 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreDelete, OnDelete)
665 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreClear, OnClear)
666 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreCreateIndex, OnCreateIndex)
667 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreIndex, OnIndex)
668 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreDeleteIndex, OnDeleteIndex)
669 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreOpenCursor, OnOpenCursor)
670 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreCount, OnCount)
671 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_ObjectStoreDestroyed, OnDestroyed)
672 IPC_MESSAGE_UNHANDLED(handled = false)
673 IPC_END_MESSAGE_MAP()
674 return handled;
677 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::Send(
678 IPC::Message* message) {
679 parent_->Send(message);
682 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnGet(
683 int ipc_object_store_id,
684 int32 ipc_thread_id,
685 int32 ipc_response_id,
686 const IndexedDBKeyRange& key_range,
687 int32 ipc_transaction_id) {
688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
689 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
690 &map_, ipc_object_store_id);
691 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
692 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
693 if (!idb_transaction || !idb_object_store)
694 return;
696 WebKit::WebExceptionCode ec = 0;
697 scoped_ptr<WebIDBCallbacks> callbacks(
698 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_, ipc_thread_id,
699 ipc_response_id));
700 idb_object_store->get(key_range, callbacks.release(), *idb_transaction, ec);
701 DCHECK(!ec);
704 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnPut(
705 const IndexedDBHostMsg_ObjectStorePut_Params& params) {
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
707 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
708 &map_, params.ipc_object_store_id);
709 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
710 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
711 if (!idb_transaction || !idb_object_store)
712 return;
714 scoped_ptr<WebIDBCallbacks> callbacks(
715 new IndexedDBCallbacks<WebIDBKey>(parent_, params.ipc_thread_id,
716 params.ipc_response_id));
717 idb_object_store->put(params.serialized_value, params.key,
718 params.put_mode, callbacks.release(),
719 *idb_transaction, params.index_ids,
720 params.index_keys);
721 int64 size = UTF16ToUTF8(params.serialized_value.data()).size();
722 WebIDBTransactionIDToSizeMap* map =
723 &parent_->transaction_dispatcher_host_->transaction_size_map_;
724 (*map)[params.ipc_transaction_id] += size;
727 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnSetIndexKeys(
728 int32 ipc_object_store_id,
729 const IndexedDBKey& primary_key,
730 const std::vector<int64>& index_names,
731 const std::vector<std::vector<IndexedDBKey> >& index_keys,
732 int32 ipc_transaction_id) {
733 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
734 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
735 &map_, ipc_object_store_id);
736 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
737 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
738 if (!idb_transaction || !idb_object_store)
739 return;
740 idb_object_store->setIndexKeys(primary_key,
741 WebVector<long long>(index_names),
742 index_keys, *idb_transaction);
745 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnSetIndexesReady(
746 int32 ipc_object_store_id,
747 const std::vector<int64>& index_ids,
748 int32 ipc_transaction_id) {
749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
750 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
751 &map_, ipc_object_store_id);
752 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
753 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
754 if (!idb_transaction || !idb_object_store)
755 return;
757 idb_object_store->setIndexesReady(WebVector<long long>(index_ids),
758 *idb_transaction);
761 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDelete(
762 int ipc_object_store_id,
763 int32 ipc_thread_id,
764 int32 ipc_response_id,
765 const IndexedDBKeyRange& key_range,
766 int32 ipc_transaction_id) {
767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
768 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
769 &map_, ipc_object_store_id);
770 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
771 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
772 if (!idb_transaction || !idb_object_store)
773 return;
775 WebKit::WebExceptionCode ec = 0;
776 scoped_ptr<WebIDBCallbacks> callbacks(
777 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_, ipc_thread_id,
778 ipc_response_id));
779 idb_object_store->deleteFunction(
780 key_range, callbacks.release(), *idb_transaction, ec);
781 DCHECK(!ec);
784 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnClear(
785 int ipc_object_store_id,
786 int32 ipc_thread_id,
787 int32 ipc_response_id,
788 int32 ipc_transaction_id) {
789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
790 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
791 &map_, ipc_object_store_id);
792 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
793 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
794 if (!idb_transaction || !idb_object_store)
795 return;
797 WebKit::WebExceptionCode ec = 0;
798 scoped_ptr<WebIDBCallbacks> callbacks(
799 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_, ipc_thread_id,
800 ipc_response_id));
801 idb_object_store->clear(callbacks.release(), *idb_transaction, ec);
802 DCHECK(!ec);
805 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnCreateIndex(
806 const IndexedDBHostMsg_ObjectStoreCreateIndex_Params& params,
807 int32* index_id, WebKit::WebExceptionCode* ec) {
808 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
809 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
810 &map_, params.ipc_object_store_id);
811 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
812 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
813 if (!idb_object_store || !idb_transaction)
814 return;
816 *ec = 0;
817 WebIDBIndex* index = idb_object_store->createIndex(
818 params.id, params.name, params.key_path, params.unique,
819 params.multi_entry, *idb_transaction, *ec);
820 *index_id = *ec ? 0 : parent_->Add(index);
821 WebIDBObjectIDToURLMap* transaction_url_map =
822 &parent_->transaction_dispatcher_host_->transaction_url_map_;
823 if (parent_->Context()->IsOverQuota(
824 (*transaction_url_map)[params.ipc_transaction_id])) {
825 idb_transaction->abort();
829 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndex(
830 int32 ipc_object_store_id,
831 int64 index_id,
832 int32* ipc_index_id) {
833 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
834 &map_, ipc_object_store_id);
835 if (!idb_object_store)
836 return;
838 WebIDBIndex* index = idb_object_store->index(index_id);
839 *ipc_index_id = parent_->Add(index);
842 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDeleteIndex(
843 int32 ipc_object_store_id,
844 int64 index_id,
845 int32 ipc_transaction_id,
846 WebKit::WebExceptionCode* ec) {
847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
848 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
849 &map_, ipc_object_store_id);
850 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
851 &parent_->transaction_dispatcher_host_->map_, ipc_transaction_id);
852 if (!idb_object_store || !idb_transaction)
853 return;
855 *ec = 0;
856 idb_object_store->deleteIndex(index_id, *idb_transaction, *ec);
859 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnOpenCursor(
860 const IndexedDBHostMsg_ObjectStoreOpenCursor_Params& params) {
861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
862 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
863 &parent_->object_store_dispatcher_host_->map_,
864 params.ipc_object_store_id);
865 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
866 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
867 if (!idb_transaction || !idb_object_store)
868 return;
870 WebKit::WebExceptionCode ec = 0;
871 scoped_ptr<WebIDBCallbacks> callbacks(
872 new IndexedDBCallbacks<WebIDBCursor>(parent_, params.ipc_thread_id,
873 params.ipc_response_id, -1));
874 idb_object_store->openCursor(
875 params.key_range, params.direction, callbacks.release(),
876 params.task_type,
877 *idb_transaction, ec);
878 DCHECK(!ec);
881 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnCount(
882 const IndexedDBHostMsg_ObjectStoreCount_Params& params) {
883 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
884 WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
885 &parent_->object_store_dispatcher_host_->map_,
886 params.ipc_object_store_id);
887 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
888 &parent_->transaction_dispatcher_host_->map_, params.ipc_transaction_id);
889 if (!idb_transaction || !idb_object_store)
890 return;
892 WebKit::WebExceptionCode ec = 0;
893 scoped_ptr<WebIDBCallbacks> callbacks(
894 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_,
895 params.ipc_thread_id,
896 params.ipc_response_id));
897 idb_object_store->count(
898 params.key_range, callbacks.release(), *idb_transaction, ec);
899 DCHECK(!ec);
902 void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDestroyed(
903 int32 ipc_object_id) {
904 parent_->DestroyObject(&map_, ipc_object_id);
907 //////////////////////////////////////////////////////////////////////
908 // IndexedDBDispatcherHost::CursorDispatcherHost
911 IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost(
912 IndexedDBDispatcherHost* parent)
913 : parent_(parent) {
914 map_.set_check_on_null_data(true);
917 IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {
920 bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived(
921 const IPC::Message& message, bool* msg_is_ok) {
922 bool handled = true;
923 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::CursorDispatcherHost,
924 message, *msg_is_ok)
925 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorAdvance, OnAdvance)
926 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorContinue, OnContinue)
927 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetch, OnPrefetch)
928 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorPrefetchReset, OnPrefetchReset)
929 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDelete, OnDelete)
930 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_CursorDestroyed, OnDestroyed)
931 IPC_MESSAGE_UNHANDLED(handled = false)
932 IPC_END_MESSAGE_MAP()
933 return handled;
937 void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
938 IPC::Message* message) {
939 parent_->Send(message);
943 void IndexedDBDispatcherHost::CursorDispatcherHost::OnAdvance(
944 int32 ipc_cursor_id,
945 int32 ipc_thread_id,
946 int32 ipc_response_id,
947 unsigned long count) {
948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
949 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(
950 &map_, ipc_cursor_id);
951 if (!idb_cursor)
952 return;
954 WebKit::WebExceptionCode ec = 0;
955 idb_cursor->advance(count,
956 new IndexedDBCallbacks<WebIDBCursor>(parent_,
957 ipc_thread_id,
958 ipc_response_id,
959 ipc_cursor_id),
960 ec);
961 DCHECK(!ec);
964 void IndexedDBDispatcherHost::CursorDispatcherHost::OnContinue(
965 int32 ipc_cursor_id,
966 int32 ipc_thread_id,
967 int32 ipc_response_id,
968 const IndexedDBKey& key) {
969 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
970 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
971 ipc_cursor_id);
972 if (!idb_cursor)
973 return;
975 WebKit::WebExceptionCode ec = 0;
976 idb_cursor->continueFunction(
977 key, new IndexedDBCallbacks<WebIDBCursor>(parent_, ipc_thread_id,
978 ipc_response_id,
979 ipc_cursor_id), ec);
980 DCHECK(!ec);
983 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetch(
984 int32 ipc_cursor_id,
985 int32 ipc_thread_id,
986 int32 ipc_response_id,
987 int n) {
988 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
989 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
990 ipc_cursor_id);
991 if (!idb_cursor)
992 return;
994 WebKit::WebExceptionCode ec = 0;
995 idb_cursor->prefetchContinue(
996 n, new IndexedDBCallbacks<WebIDBCursor>(parent_, ipc_thread_id,
997 ipc_response_id,
998 ipc_cursor_id), ec);
999 DCHECK(!ec);
1002 void IndexedDBDispatcherHost::CursorDispatcherHost::OnPrefetchReset(
1003 int32 ipc_cursor_id, int used_prefetches, int unused_prefetches) {
1004 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
1005 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
1006 ipc_cursor_id);
1007 if (!idb_cursor)
1008 return;
1010 idb_cursor->prefetchReset(used_prefetches, unused_prefetches);
1013 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDelete(
1014 int32 ipc_cursor_id,
1015 int32 ipc_thread_id,
1016 int32 ipc_response_id) {
1017 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
1018 WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(&map_,
1019 ipc_cursor_id);
1020 if (!idb_cursor)
1021 return;
1023 WebKit::WebExceptionCode ec = 0;
1024 idb_cursor->deleteFunction(
1025 new IndexedDBCallbacks<WebSerializedScriptValue>(parent_, ipc_thread_id,
1026 ipc_response_id), ec);
1027 DCHECK(!ec);
1030 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
1031 int32 ipc_object_id) {
1032 parent_->DestroyObject(&map_, ipc_object_id);
1035 //////////////////////////////////////////////////////////////////////
1036 // IndexedDBDispatcherHost::TransactionDispatcherHost
1039 IndexedDBDispatcherHost::TransactionDispatcherHost::TransactionDispatcherHost(
1040 IndexedDBDispatcherHost* parent)
1041 : parent_(parent) {
1042 map_.set_check_on_null_data(true);
1045 IndexedDBDispatcherHost::
1046 TransactionDispatcherHost::~TransactionDispatcherHost() {
1047 MapType::iterator it(&map_);
1048 while (!it.IsAtEnd()) {
1049 it.GetCurrentValue()->abort();
1050 it.Advance();
1054 bool IndexedDBDispatcherHost::TransactionDispatcherHost::OnMessageReceived(
1055 const IPC::Message& message, bool* msg_is_ok) {
1056 bool handled = true;
1057 IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::TransactionDispatcherHost,
1058 message, *msg_is_ok)
1059 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_TransactionCommit, OnCommit)
1060 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_TransactionAbort, OnAbort)
1061 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_TransactionObjectStore, OnObjectStore)
1062 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_TransactionDidCompleteTaskEvents,
1063 OnDidCompleteTaskEvents)
1064 IPC_MESSAGE_HANDLER(IndexedDBHostMsg_TransactionDestroyed, OnDestroyed)
1065 IPC_MESSAGE_UNHANDLED(handled = false)
1066 IPC_END_MESSAGE_MAP()
1067 return handled;
1070 void IndexedDBDispatcherHost::TransactionDispatcherHost::Send(
1071 IPC::Message* message) {
1072 parent_->Send(message);
1075 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnCommit(
1076 int32 ipc_transaction_id) {
1077 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
1078 &map_, ipc_transaction_id);
1079 if (!idb_transaction)
1080 return;
1082 // TODO(dgrogan): Tell the page the transaction aborted because of quota.
1083 // http://crbug.com/113118
1084 if (parent_->Context()->WouldBeOverQuota(
1085 transaction_url_map_[ipc_transaction_id],
1086 transaction_size_map_[ipc_transaction_id])) {
1087 idb_transaction->abort();
1088 return;
1091 idb_transaction->commit();
1094 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnAbort(
1095 int32 ipc_transaction_id) {
1096 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
1097 &map_, ipc_transaction_id);
1098 if (!idb_transaction)
1099 return;
1101 idb_transaction->abort();
1104 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnObjectStore(
1105 int32 ipc_transaction_id, int64 object_store_id, int32* ipc_object_store_id,
1106 WebKit::WebExceptionCode* ec) {
1107 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
1108 &map_, ipc_transaction_id);
1109 if (!idb_transaction)
1110 return;
1112 *ec = 0;
1113 WebIDBObjectStore* object_store =
1114 idb_transaction->objectStore(object_store_id, *ec);
1115 *ipc_object_store_id = object_store ? parent_->Add(object_store) : 0;
1118 void IndexedDBDispatcherHost::
1119 TransactionDispatcherHost::OnDidCompleteTaskEvents(int ipc_transaction_id) {
1120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
1121 WebIDBTransaction* idb_transaction = parent_->GetOrTerminateProcess(
1122 &map_, ipc_transaction_id);
1123 if (!idb_transaction)
1124 return;
1125 idb_transaction->didCompleteTaskEvents();
1128 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed(
1129 int32 ipc_object_id) {
1130 // TODO(dgrogan): This doesn't seem to be happening with some version change
1131 // transactions. Possibly introduced with integer version support.
1132 transaction_size_map_.erase(ipc_object_id);
1133 transaction_url_map_.erase(ipc_object_id);
1134 parent_->DestroyObject(&map_, ipc_object_id);
1137 } // namespace content