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

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.cc

Issue 19752007: Use builders to convert between WebKit and content IDB types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/child/indexed_db/indexed_db_dispatcher.h" 5 #include "content/child/indexed_db/indexed_db_dispatcher.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "content/child/indexed_db/indexed_db_key_builders.h"
11 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" 12 #include "content/child/indexed_db/proxy_webidbcursor_impl.h"
12 #include "content/child/indexed_db/proxy_webidbdatabase_impl.h" 13 #include "content/child/indexed_db/proxy_webidbdatabase_impl.h"
13 #include "content/child/thread_safe_sender.h" 14 #include "content/child/thread_safe_sender.h"
14 #include "content/common/indexed_db/indexed_db_messages.h" 15 #include "content/common/indexed_db/indexed_db_messages.h"
15 #include "ipc/ipc_channel.h" 16 #include "ipc/ipc_channel.h"
16 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h" 17 #include "third_party/WebKit/public/platform/WebIDBDatabaseCallbacks.h"
17 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h" 18 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h"
18 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" 19 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
19 #include "third_party/WebKit/public/platform/WebIDBKeyRange.h"
20 20
21 using WebKit::WebData; 21 using WebKit::WebData;
22 using WebKit::WebIDBCallbacks; 22 using WebKit::WebIDBCallbacks;
23 using WebKit::WebIDBDatabase; 23 using WebKit::WebIDBDatabase;
24 using WebKit::WebIDBDatabaseCallbacks; 24 using WebKit::WebIDBDatabaseCallbacks;
25 using WebKit::WebIDBDatabaseError; 25 using WebKit::WebIDBDatabaseError;
26 using WebKit::WebIDBKey; 26 using WebKit::WebIDBKey;
27 using WebKit::WebIDBKeyRange;
28 using WebKit::WebIDBMetadata; 27 using WebKit::WebIDBMetadata;
29 using WebKit::WebString; 28 using WebKit::WebString;
30 using WebKit::WebVector; 29 using WebKit::WebVector;
31 using base::ThreadLocalPointer; 30 using base::ThreadLocalPointer;
32 using webkit_glue::WorkerTaskRunner; 31 using webkit_glue::WorkerTaskRunner;
33 32
34 namespace content { 33 namespace content {
35 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky 34 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky
36 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; 35 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER;
37 36
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 WebVector<WebIDBMetadata::ObjectStore>(idb_metadata.object_stores.size()); 92 WebVector<WebIDBMetadata::ObjectStore>(idb_metadata.object_stores.size());
94 93
95 for (size_t i = 0; i < idb_metadata.object_stores.size(); ++i) { 94 for (size_t i = 0; i < idb_metadata.object_stores.size(); ++i) {
96 const IndexedDBObjectStoreMetadata& idb_store_metadata = 95 const IndexedDBObjectStoreMetadata& idb_store_metadata =
97 idb_metadata.object_stores[i]; 96 idb_metadata.object_stores[i];
98 WebIDBMetadata::ObjectStore& web_store_metadata = 97 WebIDBMetadata::ObjectStore& web_store_metadata =
99 web_metadata.objectStores[i]; 98 web_metadata.objectStores[i];
100 99
101 web_store_metadata.id = idb_store_metadata.id; 100 web_store_metadata.id = idb_store_metadata.id;
102 web_store_metadata.name = idb_store_metadata.name; 101 web_store_metadata.name = idb_store_metadata.name;
103 web_store_metadata.keyPath = idb_store_metadata.keyPath; 102 web_store_metadata.keyPath =
103 WebIDBKeyPathBuilder::Build(idb_store_metadata.keyPath);
104 web_store_metadata.autoIncrement = idb_store_metadata.autoIncrement; 104 web_store_metadata.autoIncrement = idb_store_metadata.autoIncrement;
105 web_store_metadata.maxIndexId = idb_store_metadata.max_index_id; 105 web_store_metadata.maxIndexId = idb_store_metadata.max_index_id;
106 web_store_metadata.indexes = 106 web_store_metadata.indexes =
107 WebVector<WebIDBMetadata::Index>(idb_store_metadata.indexes.size()); 107 WebVector<WebIDBMetadata::Index>(idb_store_metadata.indexes.size());
108 108
109 for (size_t j = 0; j < idb_store_metadata.indexes.size(); ++j) { 109 for (size_t j = 0; j < idb_store_metadata.indexes.size(); ++j) {
110 const IndexedDBIndexMetadata& idb_index_metadata = 110 const IndexedDBIndexMetadata& idb_index_metadata =
111 idb_store_metadata.indexes[j]; 111 idb_store_metadata.indexes[j];
112 WebIDBMetadata::Index& web_index_metadata = web_store_metadata.indexes[j]; 112 WebIDBMetadata::Index& web_index_metadata = web_store_metadata.indexes[j];
113 113
114 web_index_metadata.id = idb_index_metadata.id; 114 web_index_metadata.id = idb_index_metadata.id;
115 web_index_metadata.name = idb_index_metadata.name; 115 web_index_metadata.name = idb_index_metadata.name;
116 web_index_metadata.keyPath = idb_index_metadata.keyPath; 116 web_index_metadata.keyPath =
117 WebIDBKeyPathBuilder::Build(idb_index_metadata.keyPath);
117 web_index_metadata.unique = idb_index_metadata.unique; 118 web_index_metadata.unique = idb_index_metadata.unique;
118 web_index_metadata.multiEntry = idb_index_metadata.multiEntry; 119 web_index_metadata.multiEntry = idb_index_metadata.multiEntry;
119 } 120 }
120 } 121 }
121 122
122 return web_metadata; 123 return web_metadata;
123 } 124 }
124 125
125 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) { 126 void IndexedDBDispatcher::OnMessageReceived(const IPC::Message& msg) {
126 bool handled = true; 127 bool handled = true;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 353
353 COMPILE_ASSERT(sizeof(params.index_ids[0]) == sizeof(index_ids[0]), 354 COMPILE_ASSERT(sizeof(params.index_ids[0]) == sizeof(index_ids[0]),
354 Cant_copy); 355 Cant_copy);
355 params.index_ids 356 params.index_ids
356 .assign(index_ids.data(), index_ids.data() + index_ids.size()); 357 .assign(index_ids.data(), index_ids.data() + index_ids.size());
357 358
358 params.index_keys.resize(index_keys.size()); 359 params.index_keys.resize(index_keys.size());
359 for (size_t i = 0; i < index_keys.size(); ++i) { 360 for (size_t i = 0; i < index_keys.size(); ++i) {
360 params.index_keys[i].resize(index_keys[i].size()); 361 params.index_keys[i].resize(index_keys[i].size());
361 for (size_t j = 0; j < index_keys[i].size(); ++j) { 362 for (size_t j = 0; j < index_keys[i].size(); ++j) {
362 params.index_keys[i][j] = IndexedDBKey(index_keys[i][j]); 363 params.index_keys[i][j] =
364 IndexedDBKey(IndexedDBKeyBuilder::Build(index_keys[i][j]));
363 } 365 }
364 } 366 }
365 Send(new IndexedDBHostMsg_DatabasePut(params)); 367 Send(new IndexedDBHostMsg_DatabasePut(params));
366 } 368 }
367 369
368 void IndexedDBDispatcher::RequestIDBDatabaseOpenCursor( 370 void IndexedDBDispatcher::RequestIDBDatabaseOpenCursor(
369 int32 ipc_database_id, 371 int32 ipc_database_id,
370 int64 transaction_id, 372 int64 transaction_id,
371 int64 object_store_id, 373 int64 object_store_id,
372 int64 index_id, 374 int64 index_id,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 pending_callbacks_.Remove(ipc_callbacks_id); 468 pending_callbacks_.Remove(ipc_callbacks_id);
467 } 469 }
468 470
469 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32 ipc_thread_id, 471 void IndexedDBDispatcher::OnSuccessIndexedDBKey(int32 ipc_thread_id,
470 int32 ipc_callbacks_id, 472 int32 ipc_callbacks_id,
471 const IndexedDBKey& key) { 473 const IndexedDBKey& key) {
472 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 474 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
473 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 475 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
474 if (!callbacks) 476 if (!callbacks)
475 return; 477 return;
476 callbacks->onSuccess(WebIDBKey(key)); 478 callbacks->onSuccess(WebIDBKeyBuilder::Build(key));
477 pending_callbacks_.Remove(ipc_callbacks_id); 479 pending_callbacks_.Remove(ipc_callbacks_id);
478 } 480 }
479 481
480 void IndexedDBDispatcher::OnSuccessStringList( 482 void IndexedDBDispatcher::OnSuccessStringList(
481 int32 ipc_thread_id, 483 int32 ipc_thread_id,
482 int32 ipc_callbacks_id, 484 int32 ipc_callbacks_id,
483 const std::vector<string16>& value) { 485 const std::vector<string16>& value) {
484 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 486 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
485 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 487 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
486 if (!callbacks) 488 if (!callbacks)
(...skipping 22 matching lines...) Expand all
509 const std::string& value, 511 const std::string& value,
510 const IndexedDBKey& primary_key, 512 const IndexedDBKey& primary_key,
511 const IndexedDBKeyPath& key_path) { 513 const IndexedDBKeyPath& key_path) {
512 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 514 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
513 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 515 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
514 if (!callbacks) 516 if (!callbacks)
515 return; 517 return;
516 WebData web_value; 518 WebData web_value;
517 if (value.size()) 519 if (value.size())
518 web_value.assign(&*value.begin(), value.size()); 520 web_value.assign(&*value.begin(), value.size());
519 callbacks->onSuccess(web_value, primary_key, key_path); 521 callbacks->onSuccess(web_value,
522 WebIDBKeyBuilder::Build(primary_key),
523 WebIDBKeyPathBuilder::Build(key_path));
520 pending_callbacks_.Remove(ipc_callbacks_id); 524 pending_callbacks_.Remove(ipc_callbacks_id);
521 } 525 }
522 526
523 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id, 527 void IndexedDBDispatcher::OnSuccessInteger(int32 ipc_thread_id,
524 int32 ipc_callbacks_id, 528 int32 ipc_callbacks_id,
525 int64 value) { 529 int64 value) {
526 DCHECK_EQ(ipc_thread_id, CurrentWorkerId()); 530 DCHECK_EQ(ipc_thread_id, CurrentWorkerId());
527 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 531 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
528 if (!callbacks) 532 if (!callbacks)
529 return; 533 return;
(...skipping 22 matching lines...) Expand all
552 if (p.value.size()) 556 if (p.value.size())
553 web_value.assign(&*p.value.begin(), p.value.size()); 557 web_value.assign(&*p.value.begin(), p.value.size());
554 558
555 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 559 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
556 if (!callbacks) 560 if (!callbacks)
557 return; 561 return;
558 562
559 RendererWebIDBCursorImpl* cursor = 563 RendererWebIDBCursorImpl* cursor =
560 new RendererWebIDBCursorImpl(ipc_object_id, thread_safe_sender_.get()); 564 new RendererWebIDBCursorImpl(ipc_object_id, thread_safe_sender_.get());
561 cursors_[ipc_object_id] = cursor; 565 cursors_[ipc_object_id] = cursor;
562 callbacks->onSuccess(cursor, key, primary_key, web_value); 566 callbacks->onSuccess(cursor, WebIDBKeyBuilder::Build(key),
567 WebIDBKeyBuilder::Build(primary_key), web_value);
563 568
564 pending_callbacks_.Remove(ipc_callbacks_id); 569 pending_callbacks_.Remove(ipc_callbacks_id);
565 } 570 }
566 571
567 void IndexedDBDispatcher::OnSuccessCursorContinue( 572 void IndexedDBDispatcher::OnSuccessCursorContinue(
568 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) { 573 const IndexedDBMsg_CallbacksSuccessCursorContinue_Params& p) {
569 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 574 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
570 int32 ipc_callbacks_id = p.ipc_callbacks_id; 575 int32 ipc_callbacks_id = p.ipc_callbacks_id;
571 int32 ipc_cursor_id = p.ipc_cursor_id; 576 int32 ipc_cursor_id = p.ipc_cursor_id;
572 const IndexedDBKey& key = p.key; 577 const IndexedDBKey& key = p.key;
573 const IndexedDBKey& primary_key = p.primary_key; 578 const IndexedDBKey& primary_key = p.primary_key;
574 const std::string& value = p.value; 579 const std::string& value = p.value;
575 580
576 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id]; 581 RendererWebIDBCursorImpl* cursor = cursors_[ipc_cursor_id];
577 DCHECK(cursor); 582 DCHECK(cursor);
578 583
579 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id); 584 WebIDBCallbacks* callbacks = pending_callbacks_.Lookup(ipc_callbacks_id);
580 if (!callbacks) 585 if (!callbacks)
581 return; 586 return;
582 587
583 WebData web_value; 588 WebData web_value;
584 if (value.size()) 589 if (value.size())
585 web_value.assign(&*value.begin(), value.size()); 590 web_value.assign(&*value.begin(), value.size());
586 callbacks->onSuccess(key, primary_key, web_value); 591 callbacks->onSuccess(WebIDBKeyBuilder::Build(key),
592 WebIDBKeyBuilder::Build(primary_key), web_value);
587 593
588 pending_callbacks_.Remove(ipc_callbacks_id); 594 pending_callbacks_.Remove(ipc_callbacks_id);
589 } 595 }
590 596
591 void IndexedDBDispatcher::OnSuccessCursorPrefetch( 597 void IndexedDBDispatcher::OnSuccessCursorPrefetch(
592 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) { 598 const IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params& p) {
593 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId()); 599 DCHECK_EQ(p.ipc_thread_id, CurrentWorkerId());
594 int32 ipc_callbacks_id = p.ipc_callbacks_id; 600 int32 ipc_callbacks_id = p.ipc_callbacks_id;
595 int32 ipc_cursor_id = p.ipc_cursor_id; 601 int32 ipc_cursor_id = p.ipc_cursor_id;
596 const std::vector<IndexedDBKey>& keys = p.keys; 602 const std::vector<IndexedDBKey>& keys = p.keys;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 int32 ipc_exception_cursor_id) { 713 int32 ipc_exception_cursor_id) {
708 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; 714 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator;
709 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { 715 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) {
710 if (i->first == ipc_exception_cursor_id) 716 if (i->first == ipc_exception_cursor_id)
711 continue; 717 continue;
712 i->second->ResetPrefetchCache(); 718 i->second->ResetPrefetchCache();
713 } 719 }
714 } 720 }
715 721
716 } // namespace content 722 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_leveldb_coding.cc ('k') | content/child/indexed_db/indexed_db_key_builders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698