OLD | NEW |
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 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
| 15 #include "base/command_line.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
18 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/numerics/safe_conversions.h" |
20 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
21 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
23 #include "content/browser/indexed_db/indexed_db_blob_info.h" | 25 #include "content/browser/indexed_db/indexed_db_blob_info.h" |
24 #include "content/browser/indexed_db/indexed_db_class_factory.h" | 26 #include "content/browser/indexed_db/indexed_db_class_factory.h" |
25 #include "content/browser/indexed_db/indexed_db_connection.h" | 27 #include "content/browser/indexed_db/indexed_db_connection.h" |
26 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 28 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
27 #include "content/browser/indexed_db/indexed_db_cursor.h" | 29 #include "content/browser/indexed_db/indexed_db_cursor.h" |
28 #include "content/browser/indexed_db/indexed_db_factory.h" | 30 #include "content/browser/indexed_db/indexed_db_factory.h" |
29 #include "content/browser/indexed_db/indexed_db_index_writer.h" | 31 #include "content/browser/indexed_db/indexed_db_index_writer.h" |
30 #include "content/browser/indexed_db/indexed_db_pending_connection.h" | 32 #include "content/browser/indexed_db/indexed_db_pending_connection.h" |
31 #include "content/browser/indexed_db/indexed_db_return_value.h" | 33 #include "content/browser/indexed_db/indexed_db_return_value.h" |
32 #include "content/browser/indexed_db/indexed_db_tracing.h" | 34 #include "content/browser/indexed_db/indexed_db_tracing.h" |
33 #include "content/browser/indexed_db/indexed_db_transaction.h" | 35 #include "content/browser/indexed_db/indexed_db_transaction.h" |
34 #include "content/browser/indexed_db/indexed_db_value.h" | 36 #include "content/browser/indexed_db/indexed_db_value.h" |
35 #include "content/common/indexed_db/indexed_db_constants.h" | 37 #include "content/common/indexed_db/indexed_db_constants.h" |
36 #include "content/common/indexed_db/indexed_db_key_path.h" | 38 #include "content/common/indexed_db/indexed_db_key_path.h" |
37 #include "content/common/indexed_db/indexed_db_key_range.h" | 39 #include "content/common/indexed_db/indexed_db_key_range.h" |
| 40 #include "content/public/common/content_switches.h" |
38 #include "storage/browser/blob/blob_data_handle.h" | 41 #include "storage/browser/blob/blob_data_handle.h" |
39 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 42 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
40 #include "third_party/leveldatabase/env_chromium.h" | 43 #include "third_party/leveldatabase/env_chromium.h" |
41 #include "url/origin.h" | 44 #include "url/origin.h" |
42 | 45 |
43 using base::ASCIIToUTF16; | 46 using base::ASCIIToUTF16; |
44 using base::Int64ToString16; | 47 using base::Int64ToString16; |
45 using blink::WebIDBKeyTypeNumber; | 48 using blink::WebIDBKeyTypeNumber; |
46 | 49 |
47 namespace content { | 50 namespace content { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 IndexedDBDatabase::IndexedDBDatabase(const base::string16& name, | 153 IndexedDBDatabase::IndexedDBDatabase(const base::string16& name, |
151 IndexedDBBackingStore* backing_store, | 154 IndexedDBBackingStore* backing_store, |
152 IndexedDBFactory* factory, | 155 IndexedDBFactory* factory, |
153 const Identifier& unique_identifier) | 156 const Identifier& unique_identifier) |
154 : backing_store_(backing_store), | 157 : backing_store_(backing_store), |
155 metadata_(name, | 158 metadata_(name, |
156 kInvalidId, | 159 kInvalidId, |
157 IndexedDBDatabaseMetadata::NO_VERSION, | 160 IndexedDBDatabaseMetadata::NO_VERSION, |
158 kInvalidId), | 161 kInvalidId), |
159 identifier_(unique_identifier), | 162 identifier_(unique_identifier), |
160 factory_(factory) { | 163 factory_(factory), |
| 164 experimental_web_platform_features_enabled_( |
| 165 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 166 switches::kEnableExperimentalWebPlatformFeatures)) { |
161 DCHECK(factory != NULL); | 167 DCHECK(factory != NULL); |
162 } | 168 } |
163 | 169 |
164 void IndexedDBDatabase::AddObjectStore( | 170 void IndexedDBDatabase::AddObjectStore( |
165 const IndexedDBObjectStoreMetadata& object_store, | 171 const IndexedDBObjectStoreMetadata& object_store, |
166 int64_t new_max_object_store_id) { | 172 int64_t new_max_object_store_id) { |
167 DCHECK(metadata_.object_stores.find(object_store.id) == | 173 DCHECK(metadata_.object_stores.find(object_store.id) == |
168 metadata_.object_stores.end()); | 174 metadata_.object_stores.end()); |
169 if (new_max_object_store_id != IndexedDBObjectStoreMetadata::kInvalidId) { | 175 if (new_max_object_store_id != IndexedDBObjectStoreMetadata::kInvalidId) { |
170 DCHECK_LT(metadata_.max_object_store_id, new_max_object_store_id); | 176 DCHECK_LT(metadata_.max_object_store_id, new_max_object_store_id); |
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 object_store_id, | 1409 object_store_id, |
1404 base::Passed(&key_range), | 1410 base::Passed(&key_range), |
1405 callbacks)); | 1411 callbacks)); |
1406 } | 1412 } |
1407 | 1413 |
1408 void IndexedDBDatabase::DeleteRangeOperation( | 1414 void IndexedDBDatabase::DeleteRangeOperation( |
1409 int64_t object_store_id, | 1415 int64_t object_store_id, |
1410 std::unique_ptr<IndexedDBKeyRange> key_range, | 1416 std::unique_ptr<IndexedDBKeyRange> key_range, |
1411 scoped_refptr<IndexedDBCallbacks> callbacks, | 1417 scoped_refptr<IndexedDBCallbacks> callbacks, |
1412 IndexedDBTransaction* transaction) { | 1418 IndexedDBTransaction* transaction) { |
1413 IDB_TRACE1( | 1419 IDB_TRACE1("IndexedDBDatabase::DeleteRangeOperation", "txn.id", |
1414 "IndexedDBDatabase::DeleteRangeOperation", "txn.id", transaction->id()); | 1420 transaction->id()); |
| 1421 size_t delete_count = 0; |
1415 leveldb::Status s = | 1422 leveldb::Status s = |
1416 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), | 1423 backing_store_->DeleteRange(transaction->BackingStoreTransaction(), id(), |
1417 id(), | 1424 object_store_id, *key_range, &delete_count); |
1418 object_store_id, | |
1419 *key_range); | |
1420 if (!s.ok()) { | 1425 if (!s.ok()) { |
1421 base::string16 error_string = | 1426 base::string16 error_string = |
1422 ASCIIToUTF16("Internal error deleting data in range"); | 1427 ASCIIToUTF16("Internal error deleting data in range"); |
1423 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, | 1428 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
1424 error_string); | 1429 error_string); |
1425 transaction->Abort(error); | 1430 transaction->Abort(error); |
1426 if (s.IsCorruption()) { | 1431 if (s.IsCorruption()) { |
1427 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); | 1432 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); |
1428 } | 1433 } |
1429 return; | 1434 return; |
1430 } | 1435 } |
1431 callbacks->OnSuccess(); | 1436 if (experimental_web_platform_features_enabled_) { |
| 1437 callbacks->OnSuccess(base::checked_cast<int64_t>(delete_count)); |
| 1438 } else { |
| 1439 callbacks->OnSuccess(); |
| 1440 } |
1432 } | 1441 } |
1433 | 1442 |
1434 void IndexedDBDatabase::Clear(int64_t transaction_id, | 1443 void IndexedDBDatabase::Clear(int64_t transaction_id, |
1435 int64_t object_store_id, | 1444 int64_t object_store_id, |
1436 scoped_refptr<IndexedDBCallbacks> callbacks) { | 1445 scoped_refptr<IndexedDBCallbacks> callbacks) { |
1437 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); | 1446 IDB_TRACE1("IndexedDBDatabase::Clear", "txn.id", transaction_id); |
1438 IndexedDBTransaction* transaction = GetTransaction(transaction_id); | 1447 IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
1439 if (!transaction) | 1448 if (!transaction) |
1440 return; | 1449 return; |
1441 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); | 1450 DCHECK_NE(transaction->mode(), blink::WebIDBTransactionModeReadOnly); |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 | 1950 |
1942 void IndexedDBDatabase::VersionChangeAbortOperation( | 1951 void IndexedDBDatabase::VersionChangeAbortOperation( |
1943 int64_t previous_version, | 1952 int64_t previous_version, |
1944 IndexedDBTransaction* transaction) { | 1953 IndexedDBTransaction* transaction) { |
1945 DCHECK(!transaction); | 1954 DCHECK(!transaction); |
1946 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); | 1955 IDB_TRACE("IndexedDBDatabase::VersionChangeAbortOperation"); |
1947 metadata_.version = previous_version; | 1956 metadata_.version = previous_version; |
1948 } | 1957 } |
1949 | 1958 |
1950 } // namespace content | 1959 } // namespace content |
OLD | NEW |