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

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

Issue 17915004: IndexedDB: Remove uses of WebKit API types from back-end code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/indexed_db/indexed_db_dispatcher_host.h" 5 #include "content/browser/indexed_db/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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/process.h" 12 #include "base/process.h"
13 #include "base/process_util.h" 13 #include "base/process_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "content/browser/indexed_db/indexed_db_callbacks.h" 15 #include "content/browser/indexed_db/indexed_db_callbacks.h"
16 #include "content/browser/indexed_db/indexed_db_context_impl.h" 16 #include "content/browser/indexed_db/indexed_db_context_impl.h"
17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
18 #include "content/browser/indexed_db/indexed_db_metadata.h" 18 #include "content/browser/indexed_db/indexed_db_metadata.h"
19 #include "content/browser/indexed_db/webidbcursor_impl.h" 19 #include "content/browser/indexed_db/webidbcursor_impl.h"
20 #include "content/browser/indexed_db/webidbcursor_impl.h" 20 #include "content/browser/indexed_db/webidbcursor_impl.h"
21 #include "content/browser/indexed_db/webidbdatabase_impl.h" 21 #include "content/browser/indexed_db/webidbdatabase_impl.h"
22 #include "content/browser/renderer_host/render_message_filter.h" 22 #include "content/browser/renderer_host/render_message_filter.h"
23 #include "content/common/indexed_db/indexed_db_messages.h" 23 #include "content/common/indexed_db/indexed_db_messages.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/user_metrics.h" 25 #include "content/public/browser/user_metrics.h"
26 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
27 #include "content/public/common/result_codes.h" 27 #include "content/public/common/result_codes.h"
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 #include "third_party/WebKit/public/platform/WebIDBDatabase.h" 29 #include "third_party/WebKit/public/platform/WebIDBDatabase.h"
30 #include "third_party/WebKit/public/platform/WebIDBDatabaseError.h"
31 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" 30 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
32 #include "webkit/browser/database/database_util.h" 31 #include "webkit/browser/database/database_util.h"
33 #include "webkit/common/database/database_identifier.h" 32 #include "webkit/common/database/database_identifier.h"
34 33
35 using webkit_database::DatabaseUtil; 34 using webkit_database::DatabaseUtil;
36 using WebKit::WebIDBDatabaseError;
37 using WebKit::WebIDBKey; 35 using WebKit::WebIDBKey;
38 36
39 namespace content { 37 namespace content {
40 38
39 static const char* kQuotaExceededErrorMessage =
40 "An attempt was made to add something to storage that exceeded the quota.";
jamesr 2013/06/26 20:08:25 shouldn't this go in a resources file somewhere?
jsbell 2013/06/26 20:14:28 Exception messages aren't localized. This particul
jsbell 2013/06/26 22:12:47 Changed it to pass through blank messages if the f
41
41 IndexedDBDispatcherHost::IndexedDBDispatcherHost( 42 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
42 int ipc_process_id, 43 int ipc_process_id,
43 IndexedDBContextImpl* indexed_db_context) 44 IndexedDBContextImpl* indexed_db_context)
44 : indexed_db_context_(indexed_db_context), 45 : indexed_db_context_(indexed_db_context),
45 database_dispatcher_host_(new DatabaseDispatcherHost(this)), 46 database_dispatcher_host_(new DatabaseDispatcherHost(this)),
46 cursor_dispatcher_host_(new CursorDispatcherHost(this)), 47 cursor_dispatcher_host_(new CursorDispatcherHost(this)),
47 ipc_process_id_(ipc_process_id) { 48 ipc_process_id_(ipc_process_id) {
48 DCHECK(indexed_db_context_.get()); 49 DCHECK(indexed_db_context_.get());
49 } 50 }
50 51
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 215 }
215 216
216 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( 217 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames(
217 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { 218 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) {
218 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 219 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
219 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 220 base::FilePath indexed_db_path = indexed_db_context_->data_path();
220 221
221 Context()->GetIDBFactory()->getDatabaseNames( 222 Context()->GetIDBFactory()->getDatabaseNames(
222 new IndexedDBCallbacks<std::vector<string16> >( 223 new IndexedDBCallbacks<std::vector<string16> >(
223 this, params.ipc_thread_id, params.ipc_callbacks_id), 224 this, params.ipc_thread_id, params.ipc_callbacks_id),
224 WebKit::WebString::fromUTF8(params.database_identifier), 225 base::UTF8ToUTF16(params.database_identifier),
225 indexed_db_path.AsUTF16Unsafe()); 226 indexed_db_path.AsUTF16Unsafe());
226 } 227 }
227 228
228 void IndexedDBDispatcherHost::OnIDBFactoryOpen( 229 void IndexedDBDispatcherHost::OnIDBFactoryOpen(
229 const IndexedDBHostMsg_FactoryOpen_Params& params) { 230 const IndexedDBHostMsg_FactoryOpen_Params& params) {
230 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 231 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
231 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 232 base::FilePath indexed_db_path = indexed_db_context_->data_path();
232 233
233 GURL origin_url = 234 GURL origin_url =
234 webkit_database::GetOriginFromIdentifier(params.database_identifier); 235 webkit_database::GetOriginFromIdentifier(params.database_identifier);
235 236
236 int64 host_transaction_id = HostTransactionId(params.transaction_id); 237 int64 host_transaction_id = HostTransactionId(params.transaction_id);
237 238
238 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore 239 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
239 // created) if this origin is already over quota. 240 // created) if this origin is already over quota.
240 Context()->GetIDBFactory() 241 Context()->GetIDBFactory()
241 ->open(params.name, 242 ->open(params.name,
242 params.version, 243 params.version,
243 host_transaction_id, 244 host_transaction_id,
244 new IndexedDBCallbacksDatabase(this, 245 new IndexedDBCallbacksDatabase(this,
245 params.ipc_thread_id, 246 params.ipc_thread_id,
246 params.ipc_callbacks_id, 247 params.ipc_callbacks_id,
247 params.ipc_database_callbacks_id, 248 params.ipc_database_callbacks_id,
248 host_transaction_id, 249 host_transaction_id,
249 origin_url), 250 origin_url),
250 new IndexedDBDatabaseCallbacks( 251 new IndexedDBDatabaseCallbacks(
251 this, params.ipc_thread_id, params.ipc_database_callbacks_id), 252 this, params.ipc_thread_id, params.ipc_database_callbacks_id),
252 WebKit::WebString::fromUTF8(params.database_identifier), 253 base::UTF8ToUTF16(params.database_identifier),
253 indexed_db_path.AsUTF16Unsafe()); 254 indexed_db_path.AsUTF16Unsafe());
254 } 255 }
255 256
256 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( 257 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase(
257 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { 258 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) {
258 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 259 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
259 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 260 base::FilePath indexed_db_path = indexed_db_context_->data_path();
260 261
261 Context()->GetIDBFactory() 262 Context()->GetIDBFactory()
262 ->deleteDatabase(params.name, 263 ->deleteDatabase(params.name,
263 new IndexedDBCallbacks<std::vector<char> >( 264 new IndexedDBCallbacks<std::vector<char> >(
264 this, params.ipc_thread_id, params.ipc_callbacks_id), 265 this, params.ipc_thread_id, params.ipc_callbacks_id),
265 WebKit::WebString::fromUTF8(params.database_identifier), 266 base::UTF8ToUTF16(params.database_identifier),
266 indexed_db_path.AsUTF16Unsafe()); 267 indexed_db_path.AsUTF16Unsafe());
267 } 268 }
268 269
269 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, 270 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id,
270 bool committed) { 271 bool committed) {
271 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 272 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
272 TransactionIDToURLMap& transaction_url_map = 273 TransactionIDToURLMap& transaction_url_map =
273 database_dispatcher_host_->transaction_url_map_; 274 database_dispatcher_host_->transaction_url_map_;
274 TransactionIDToSizeMap& transaction_size_map = 275 TransactionIDToSizeMap& transaction_size_map =
275 database_dispatcher_host_->transaction_size_map_; 276 database_dispatcher_host_->transaction_size_map_;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 for (TransactionIDToDatabaseIDMap::iterator iter = 344 for (TransactionIDToDatabaseIDMap::iterator iter =
344 transaction_database_map_.begin(); 345 transaction_database_map_.begin();
345 iter != transaction_database_map_.end();) { 346 iter != transaction_database_map_.end();) {
346 int64 transaction_id = iter->first; 347 int64 transaction_id = iter->first;
347 int32 ipc_database_id = iter->second; 348 int32 ipc_database_id = iter->second;
348 ++iter; 349 ++iter;
349 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id); 350 WebIDBDatabaseImpl* database = map_.Lookup(ipc_database_id);
350 if (database) { 351 if (database) {
351 database->abort( 352 database->abort(
352 transaction_id, 353 transaction_id,
353 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError)); 354 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
355 "Connection closed."));
354 } 356 }
355 } 357 }
356 DCHECK(transaction_database_map_.empty()); 358 DCHECK(transaction_database_map_.empty());
357 359
358 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin(); 360 for (WebIDBObjectIDToURLMap::iterator iter = database_url_map_.begin();
359 iter != database_url_map_.end(); 361 iter != database_url_map_.end();
360 iter++) { 362 iter++) {
361 WebIDBDatabaseImpl* database = map_.Lookup(iter->first); 363 WebIDBDatabaseImpl* database = map_.Lookup(iter->first);
362 if (database) { 364 if (database) {
363 database->close(); 365 database->close();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 419 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
418 database->createObjectStore(host_transaction_id, 420 database->createObjectStore(host_transaction_id,
419 params.object_store_id, 421 params.object_store_id,
420 params.name, 422 params.name,
421 params.key_path, 423 params.key_path,
422 params.auto_increment); 424 params.auto_increment);
423 if (parent_->Context()->IsOverQuota( 425 if (parent_->Context()->IsOverQuota(
424 database_url_map_[params.ipc_database_id])) { 426 database_url_map_[params.ipc_database_id])) {
425 database->abort( 427 database->abort(
426 host_transaction_id, 428 host_transaction_id,
427 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); 429 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError,
430 kQuotaExceededErrorMessage));
428 } 431 }
429 } 432 }
430 433
431 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore( 434 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteObjectStore(
432 int32 ipc_database_id, 435 int32 ipc_database_id,
433 int64 transaction_id, 436 int64 transaction_id,
434 int64 object_store_id) { 437 int64 object_store_id) {
435 DCHECK( 438 DCHECK(
436 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 439 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
437 WebIDBDatabaseImpl* database = 440 WebIDBDatabaseImpl* database =
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 547 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
545 WebIDBDatabaseImpl* database = 548 WebIDBDatabaseImpl* database =
546 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 549 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
547 if (!database) 550 if (!database)
548 return; 551 return;
549 552
550 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 553 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
551 if (params.index_ids.size() != params.index_keys.size()) { 554 if (params.index_ids.size() != params.index_keys.size()) {
552 database->abort( 555 database->abort(
553 host_transaction_id, 556 host_transaction_id,
554 WebIDBDatabaseError( 557 IndexedDBDatabaseError(
555 WebKit::WebIDBDatabaseExceptionUnknownError, 558 WebKit::WebIDBDatabaseExceptionUnknownError,
556 "Malformed IPC message: index_ids.size() != index_keys.size()")); 559 "Malformed IPC message: index_ids.size() != index_keys.size()"));
557 return; 560 return;
558 } 561 }
559 562
560 database->setIndexKeys(host_transaction_id, 563 database->setIndexKeys(host_transaction_id,
561 params.object_store_id, 564 params.object_store_id,
562 params.primary_key, 565 params.primary_key,
563 params.index_ids, 566 params.index_ids,
564 params.index_keys); 567 params.index_keys);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 if (!database) 687 if (!database)
685 return; 688 return;
686 689
687 int64 host_transaction_id = parent_->HostTransactionId(transaction_id); 690 int64 host_transaction_id = parent_->HostTransactionId(transaction_id);
688 int64 transaction_size = transaction_size_map_[host_transaction_id]; 691 int64 transaction_size = transaction_size_map_[host_transaction_id];
689 if (transaction_size && 692 if (transaction_size &&
690 parent_->Context()->WouldBeOverQuota( 693 parent_->Context()->WouldBeOverQuota(
691 transaction_url_map_[host_transaction_id], transaction_size)) { 694 transaction_url_map_[host_transaction_id], transaction_size)) {
692 database->abort( 695 database->abort(
693 host_transaction_id, 696 host_transaction_id,
694 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); 697 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError,
698 kQuotaExceededErrorMessage));
695 return; 699 return;
696 } 700 }
697 701
698 database->commit(host_transaction_id); 702 database->commit(host_transaction_id);
699 } 703 }
700 704
701 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex( 705 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateIndex(
702 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) { 706 const IndexedDBHostMsg_DatabaseCreateIndex_Params& params) {
703 DCHECK( 707 DCHECK(
704 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 708 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
705 WebIDBDatabaseImpl* database = 709 WebIDBDatabaseImpl* database =
706 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 710 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
707 if (!database) 711 if (!database)
708 return; 712 return;
709 713
710 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 714 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
711 database->createIndex(host_transaction_id, 715 database->createIndex(host_transaction_id,
712 params.object_store_id, 716 params.object_store_id,
713 params.index_id, 717 params.index_id,
714 params.name, 718 params.name,
715 params.key_path, 719 params.key_path,
716 params.unique, 720 params.unique,
717 params.multi_entry); 721 params.multi_entry);
718 if (parent_->Context()->IsOverQuota( 722 if (parent_->Context()->IsOverQuota(
719 database_url_map_[params.ipc_database_id])) { 723 database_url_map_[params.ipc_database_id])) {
720 database->abort( 724 database->abort(
721 host_transaction_id, 725 host_transaction_id,
722 WebIDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError)); 726 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionQuotaError,
727 kQuotaExceededErrorMessage));
723 } 728 }
724 } 729 }
725 730
726 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex( 731 void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDeleteIndex(
727 int32 ipc_database_id, 732 int32 ipc_database_id,
728 int64 transaction_id, 733 int64 transaction_id,
729 int64 object_store_id, 734 int64 object_store_id,
730 int64 index_id) { 735 int64 index_id) {
731 DCHECK( 736 DCHECK(
732 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 737 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 } 849 }
845 850
846 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 851 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
847 int32 ipc_object_id) { 852 int32 ipc_object_id) {
848 DCHECK( 853 DCHECK(
849 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 854 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
850 parent_->DestroyObject(&map_, ipc_object_id); 855 parent_->DestroyObject(&map_, ipc_object_id);
851 } 856 }
852 857
853 } // namespace content 858 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database_unittest.cc ('k') | content/browser/indexed_db/indexed_db_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698