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

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

Issue 102593002: Convert string16 to base::string16 in content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser/indexed_db/indexed_db_database.h" 5 #include "content/browser/indexed_db/indexed_db_database.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <set> 8 #include <set>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 public: 101 public:
102 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks) 102 explicit PendingDeleteCall(scoped_refptr<IndexedDBCallbacks> callbacks)
103 : callbacks_(callbacks) {} 103 : callbacks_(callbacks) {}
104 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; } 104 scoped_refptr<IndexedDBCallbacks> Callbacks() { return callbacks_; }
105 105
106 private: 106 private:
107 scoped_refptr<IndexedDBCallbacks> callbacks_; 107 scoped_refptr<IndexedDBCallbacks> callbacks_;
108 }; 108 };
109 109
110 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create( 110 scoped_refptr<IndexedDBDatabase> IndexedDBDatabase::Create(
111 const string16& name, 111 const base::string16& name,
112 IndexedDBBackingStore* backing_store, 112 IndexedDBBackingStore* backing_store,
113 IndexedDBFactory* factory, 113 IndexedDBFactory* factory,
114 const Identifier& unique_identifier) { 114 const Identifier& unique_identifier) {
115 scoped_refptr<IndexedDBDatabase> database = 115 scoped_refptr<IndexedDBDatabase> database =
116 new IndexedDBDatabase(name, backing_store, factory, unique_identifier); 116 new IndexedDBDatabase(name, backing_store, factory, unique_identifier);
117 if (!database->OpenInternal()) 117 if (!database->OpenInternal())
118 return 0; 118 return 0;
119 return database; 119 return database;
120 } 120 }
121 121
122 namespace { 122 namespace {
123 const base::string16::value_type kNoStringVersion[] = {0}; 123 const base::string16::value_type kNoStringVersion[] = {0};
124 124
125 template <typename T, typename U> 125 template <typename T, typename U>
126 bool Contains(const T& container, const U& item) { 126 bool Contains(const T& container, const U& item) {
127 return container.find(item) != container.end(); 127 return container.find(item) != container.end();
128 } 128 }
129 } 129 }
130 130
131 IndexedDBDatabase::IndexedDBDatabase(const string16& name, 131 IndexedDBDatabase::IndexedDBDatabase(const base::string16& name,
132 IndexedDBBackingStore* backing_store, 132 IndexedDBBackingStore* backing_store,
133 IndexedDBFactory* factory, 133 IndexedDBFactory* factory,
134 const Identifier& unique_identifier) 134 const Identifier& unique_identifier)
135 : backing_store_(backing_store), 135 : backing_store_(backing_store),
136 metadata_(name, 136 metadata_(name,
137 kInvalidId, 137 kInvalidId,
138 kNoStringVersion, 138 kNoStringVersion,
139 IndexedDBDatabaseMetadata::NO_INT_VERSION, 139 IndexedDBDatabaseMetadata::NO_INT_VERSION,
140 kInvalidId), 140 kInvalidId),
141 identifier_(unique_identifier), 141 identifier_(unique_identifier),
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 metadata_.object_stores.find(object_store_id)->second; 266 metadata_.object_stores.find(object_store_id)->second;
267 if (Contains(object_store_metadata.indexes, index_id)) { 267 if (Contains(object_store_metadata.indexes, index_id)) {
268 DLOG(ERROR) << "Invalid index_id"; 268 DLOG(ERROR) << "Invalid index_id";
269 return false; 269 return false;
270 } 270 }
271 return true; 271 return true;
272 } 272 }
273 273
274 void IndexedDBDatabase::CreateObjectStore(int64 transaction_id, 274 void IndexedDBDatabase::CreateObjectStore(int64 transaction_id,
275 int64 object_store_id, 275 int64 object_store_id,
276 const string16& name, 276 const base::string16& name,
277 const IndexedDBKeyPath& key_path, 277 const IndexedDBKeyPath& key_path,
278 bool auto_increment) { 278 bool auto_increment) {
279 IDB_TRACE("IndexedDBDatabase::CreateObjectStore"); 279 IDB_TRACE("IndexedDBDatabase::CreateObjectStore");
280 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 280 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
281 if (!transaction) 281 if (!transaction)
282 return; 282 return;
283 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE); 283 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE);
284 284
285 if (Contains(metadata_.object_stores, object_store_id)) { 285 if (Contains(metadata_.object_stores, object_store_id)) {
286 DLOG(ERROR) << "Invalid object_store_id"; 286 DLOG(ERROR) << "Invalid object_store_id";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 object_store_metadata), 344 object_store_metadata),
345 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation, 345 base::Bind(&IndexedDBDatabase::DeleteObjectStoreAbortOperation,
346 this, 346 this,
347 object_store_metadata)); 347 object_store_metadata));
348 RemoveObjectStore(object_store_id); 348 RemoveObjectStore(object_store_id);
349 } 349 }
350 350
351 void IndexedDBDatabase::CreateIndex(int64 transaction_id, 351 void IndexedDBDatabase::CreateIndex(int64 transaction_id,
352 int64 object_store_id, 352 int64 object_store_id,
353 int64 index_id, 353 int64 index_id,
354 const string16& name, 354 const base::string16& name,
355 const IndexedDBKeyPath& key_path, 355 const IndexedDBKeyPath& key_path,
356 bool unique, 356 bool unique,
357 bool multi_entry) { 357 bool multi_entry) {
358 IDB_TRACE("IndexedDBDatabase::CreateIndex"); 358 IDB_TRACE("IndexedDBDatabase::CreateIndex");
359 IndexedDBTransaction* transaction = GetTransaction(transaction_id); 359 IndexedDBTransaction* transaction = GetTransaction(transaction_id);
360 if (!transaction) 360 if (!transaction)
361 return; 361 return;
362 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE); 362 DCHECK_EQ(transaction->mode(), indexed_db::TRANSACTION_VERSION_CHANGE);
363 363
364 if (!ValidateObjectStoreIdAndNewIndexId(object_store_id, index_id)) 364 if (!ValidateObjectStoreIdAndNewIndexId(object_store_id, index_id))
(...skipping 20 matching lines...) Expand all
385 IndexedDBTransaction* transaction) { 385 IndexedDBTransaction* transaction) {
386 IDB_TRACE("IndexedDBDatabase::CreateIndexOperation"); 386 IDB_TRACE("IndexedDBDatabase::CreateIndexOperation");
387 if (!backing_store_->CreateIndex(transaction->BackingStoreTransaction(), 387 if (!backing_store_->CreateIndex(transaction->BackingStoreTransaction(),
388 transaction->database()->id(), 388 transaction->database()->id(),
389 object_store_id, 389 object_store_id,
390 index_metadata.id, 390 index_metadata.id,
391 index_metadata.name, 391 index_metadata.name,
392 index_metadata.key_path, 392 index_metadata.key_path,
393 index_metadata.unique, 393 index_metadata.unique,
394 index_metadata.multi_entry)) { 394 index_metadata.multi_entry)) {
395 string16 error_string = ASCIIToUTF16("Internal error creating index '") + 395 base::string16 error_string =
396 index_metadata.name + ASCIIToUTF16("'."); 396 ASCIIToUTF16("Internal error creating index '") +
397 index_metadata.name + ASCIIToUTF16("'.");
397 transaction->Abort(IndexedDBDatabaseError( 398 transaction->Abort(IndexedDBDatabaseError(
398 blink::WebIDBDatabaseExceptionUnknownError, error_string)); 399 blink::WebIDBDatabaseExceptionUnknownError, error_string));
399 return; 400 return;
400 } 401 }
401 } 402 }
402 403
403 void IndexedDBDatabase::CreateIndexAbortOperation( 404 void IndexedDBDatabase::CreateIndexAbortOperation(
404 int64 object_store_id, 405 int64 object_store_id,
405 int64 index_id, 406 int64 index_id,
406 IndexedDBTransaction* transaction) { 407 IndexedDBTransaction* transaction) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 void IndexedDBDatabase::DeleteIndexOperation( 440 void IndexedDBDatabase::DeleteIndexOperation(
440 int64 object_store_id, 441 int64 object_store_id,
441 const IndexedDBIndexMetadata& index_metadata, 442 const IndexedDBIndexMetadata& index_metadata,
442 IndexedDBTransaction* transaction) { 443 IndexedDBTransaction* transaction) {
443 IDB_TRACE("IndexedDBDatabase::DeleteIndexOperation"); 444 IDB_TRACE("IndexedDBDatabase::DeleteIndexOperation");
444 bool ok = backing_store_->DeleteIndex(transaction->BackingStoreTransaction(), 445 bool ok = backing_store_->DeleteIndex(transaction->BackingStoreTransaction(),
445 transaction->database()->id(), 446 transaction->database()->id(),
446 object_store_id, 447 object_store_id,
447 index_metadata.id); 448 index_metadata.id);
448 if (!ok) { 449 if (!ok) {
449 string16 error_string = ASCIIToUTF16("Internal error deleting index '") + 450 base::string16 error_string =
450 index_metadata.name + ASCIIToUTF16("'."); 451 ASCIIToUTF16("Internal error deleting index '") +
452 index_metadata.name + ASCIIToUTF16("'.");
451 transaction->Abort(IndexedDBDatabaseError( 453 transaction->Abort(IndexedDBDatabaseError(
452 blink::WebIDBDatabaseExceptionUnknownError, error_string)); 454 blink::WebIDBDatabaseExceptionUnknownError, error_string));
453 } 455 }
454 } 456 }
455 457
456 void IndexedDBDatabase::DeleteIndexAbortOperation( 458 void IndexedDBDatabase::DeleteIndexAbortOperation(
457 int64 object_store_id, 459 int64 object_store_id,
458 const IndexedDBIndexMetadata& index_metadata, 460 const IndexedDBIndexMetadata& index_metadata,
459 IndexedDBTransaction* transaction) { 461 IndexedDBTransaction* transaction) {
460 IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation"); 462 IDB_TRACE("IndexedDBDatabase::DeleteIndexAbortOperation");
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 786 }
785 if (found) { 787 if (found) {
786 params->callbacks->OnError( 788 params->callbacks->OnError(
787 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError, 789 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionConstraintError,
788 "Key already exists in the object store.")); 790 "Key already exists in the object store."));
789 return; 791 return;
790 } 792 }
791 } 793 }
792 794
793 ScopedVector<IndexWriter> index_writers; 795 ScopedVector<IndexWriter> index_writers;
794 string16 error_message; 796 base::string16 error_message;
795 bool obeys_constraints = false; 797 bool obeys_constraints = false;
796 bool backing_store_success = MakeIndexWriters(transaction, 798 bool backing_store_success = MakeIndexWriters(transaction,
797 backing_store_.get(), 799 backing_store_.get(),
798 id(), 800 id(),
799 object_store, 801 object_store,
800 *key, 802 *key,
801 key_was_generated, 803 key_was_generated,
802 params->index_ids, 804 params->index_ids,
803 params->index_keys, 805 params->index_keys,
804 &index_writers, 806 &index_writers,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 return; 892 return;
891 } 893 }
892 if (!found) { 894 if (!found) {
893 transaction->Abort(IndexedDBDatabaseError( 895 transaction->Abort(IndexedDBDatabaseError(
894 blink::WebIDBDatabaseExceptionUnknownError, 896 blink::WebIDBDatabaseExceptionUnknownError,
895 "Internal error setting index keys for object store.")); 897 "Internal error setting index keys for object store."));
896 return; 898 return;
897 } 899 }
898 900
899 ScopedVector<IndexWriter> index_writers; 901 ScopedVector<IndexWriter> index_writers;
900 string16 error_message; 902 base::string16 error_message;
901 bool obeys_constraints = false; 903 bool obeys_constraints = false;
902 DCHECK(metadata_.object_stores.find(object_store_id) != 904 DCHECK(metadata_.object_stores.find(object_store_id) !=
903 metadata_.object_stores.end()); 905 metadata_.object_stores.end());
904 const IndexedDBObjectStoreMetadata& object_store_metadata = 906 const IndexedDBObjectStoreMetadata& object_store_metadata =
905 metadata_.object_stores[object_store_id]; 907 metadata_.object_stores[object_store_id];
906 bool backing_store_success = MakeIndexWriters(transaction, 908 bool backing_store_success = MakeIndexWriters(transaction,
907 backing_store_, 909 backing_store_,
908 id(), 910 id(),
909 object_store_metadata, 911 object_store_metadata,
910 *primary_key, 912 *primary_key,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 1214
1213 void IndexedDBDatabase::DeleteObjectStoreOperation( 1215 void IndexedDBDatabase::DeleteObjectStoreOperation(
1214 const IndexedDBObjectStoreMetadata& object_store_metadata, 1216 const IndexedDBObjectStoreMetadata& object_store_metadata,
1215 IndexedDBTransaction* transaction) { 1217 IndexedDBTransaction* transaction) {
1216 IDB_TRACE("IndexedDBDatabase::DeleteObjectStoreOperation"); 1218 IDB_TRACE("IndexedDBDatabase::DeleteObjectStoreOperation");
1217 bool ok = 1219 bool ok =
1218 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(), 1220 backing_store_->DeleteObjectStore(transaction->BackingStoreTransaction(),
1219 transaction->database()->id(), 1221 transaction->database()->id(),
1220 object_store_metadata.id); 1222 object_store_metadata.id);
1221 if (!ok) { 1223 if (!ok) {
1222 string16 error_string = 1224 base::string16 error_string =
1223 ASCIIToUTF16("Internal error deleting object store '") + 1225 ASCIIToUTF16("Internal error deleting object store '") +
1224 object_store_metadata.name + ASCIIToUTF16("'."); 1226 object_store_metadata.name + ASCIIToUTF16("'.");
1225 transaction->Abort(IndexedDBDatabaseError( 1227 transaction->Abort(IndexedDBDatabaseError(
1226 blink::WebIDBDatabaseExceptionUnknownError, error_string)); 1228 blink::WebIDBDatabaseExceptionUnknownError, error_string));
1227 } 1229 }
1228 } 1230 }
1229 1231
1230 void IndexedDBDatabase::VersionChangeOperation( 1232 void IndexedDBDatabase::VersionChangeOperation(
1231 int64 version, 1233 int64 version,
1232 scoped_refptr<IndexedDBCallbacks> callbacks, 1234 scoped_refptr<IndexedDBCallbacks> callbacks,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 return; 1444 return;
1443 } 1445 }
1444 1446
1445 if (metadata_.id == kInvalidId) { 1447 if (metadata_.id == kInvalidId) {
1446 // The database was deleted then immediately re-opened; OpenInternal() 1448 // The database was deleted then immediately re-opened; OpenInternal()
1447 // recreates it in the backing store. 1449 // recreates it in the backing store.
1448 if (OpenInternal()) { 1450 if (OpenInternal()) {
1449 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION, 1451 DCHECK_EQ(IndexedDBDatabaseMetadata::NO_INT_VERSION,
1450 metadata_.int_version); 1452 metadata_.int_version);
1451 } else { 1453 } else {
1452 string16 message; 1454 base::string16 message;
1453 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION) 1455 if (version == IndexedDBDatabaseMetadata::NO_INT_VERSION)
1454 message = ASCIIToUTF16( 1456 message = ASCIIToUTF16(
1455 "Internal error opening database with no version specified."); 1457 "Internal error opening database with no version specified.");
1456 else 1458 else
1457 message = 1459 message =
1458 ASCIIToUTF16("Internal error opening database with version ") + 1460 ASCIIToUTF16("Internal error opening database with version ") +
1459 Int64ToString16(version); 1461 Int64ToString16(version);
1460 callbacks->OnError(IndexedDBDatabaseError( 1462 callbacks->OnError(IndexedDBDatabaseError(
1461 blink::WebIDBDatabaseExceptionUnknownError, message)); 1463 blink::WebIDBDatabaseExceptionUnknownError, message));
1462 return; 1464 return;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 void IndexedDBDatabase::DeleteObjectStoreAbortOperation( 1709 void IndexedDBDatabase::DeleteObjectStoreAbortOperation(
1708 const IndexedDBObjectStoreMetadata& object_store_metadata, 1710 const IndexedDBObjectStoreMetadata& object_store_metadata,
1709 IndexedDBTransaction* transaction) { 1711 IndexedDBTransaction* transaction) {
1710 IDB_TRACE("IndexedDBDatabase::DeleteObjectStoreAbortOperation"); 1712 IDB_TRACE("IndexedDBDatabase::DeleteObjectStoreAbortOperation");
1711 DCHECK(!transaction); 1713 DCHECK(!transaction);
1712 AddObjectStore(object_store_metadata, 1714 AddObjectStore(object_store_metadata,
1713 IndexedDBObjectStoreMetadata::kInvalidId); 1715 IndexedDBObjectStoreMetadata::kInvalidId);
1714 } 1716 }
1715 1717
1716 void IndexedDBDatabase::VersionChangeAbortOperation( 1718 void IndexedDBDatabase::VersionChangeAbortOperation(
1717 const string16& previous_version, 1719 const base::string16& previous_version,
1718 int64 previous_int_version, 1720 int64 previous_int_version,
1719 IndexedDBTransaction* transaction) { 1721 IndexedDBTransaction* transaction) {
1720 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); 1722 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation");
1721 DCHECK(!transaction); 1723 DCHECK(!transaction);
1722 metadata_.version = previous_version; 1724 metadata_.version = previous_version;
1723 metadata_.int_version = previous_int_version; 1725 metadata_.int_version = previous_int_version;
1724 } 1726 }
1725 1727
1726 } // namespace content 1728 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.h ('k') | content/browser/indexed_db/indexed_db_database_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698