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

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

Issue 2735213002: Indexed DB: Ensure large explicit keys consistently max out generator (Closed)
Patch Set: Created 3 years, 9 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
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 8
9 #include <algorithm>
9 #include <limits> 10 #include <limits>
10 #include <set> 11 #include <set>
11 12
12 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
17 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 if (!s.ok()) { 1195 if (!s.ok()) {
1195 LOG(ERROR) << "Failed to GetKeyGeneratorCurrentNumber"; 1196 LOG(ERROR) << "Failed to GetKeyGeneratorCurrentNumber";
1196 return base::MakeUnique<IndexedDBKey>(); 1197 return base::MakeUnique<IndexedDBKey>();
1197 } 1198 }
1198 if (current_number < 0 || current_number > max_generator_value) 1199 if (current_number < 0 || current_number > max_generator_value)
1199 return base::MakeUnique<IndexedDBKey>(); 1200 return base::MakeUnique<IndexedDBKey>();
1200 1201
1201 return base::MakeUnique<IndexedDBKey>(current_number, WebIDBKeyTypeNumber); 1202 return base::MakeUnique<IndexedDBKey>(current_number, WebIDBKeyTypeNumber);
1202 } 1203 }
1203 1204
1205 // Called at the end of a "put" operation. The key is a number that was either
1206 // generated by the generator which now needs to be incremented (so
1207 // |check_current| is false) or was user-supplied so we only conditionally use
1208 // (and |check_current| is true).
1204 static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store, 1209 static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store,
1205 IndexedDBTransaction* transaction, 1210 IndexedDBTransaction* transaction,
1206 int64_t database_id, 1211 int64_t database_id,
1207 int64_t object_store_id, 1212 int64_t object_store_id,
1208 const IndexedDBKey& key, 1213 const IndexedDBKey& key,
1209 bool check_current) { 1214 bool check_current) {
1210 DCHECK_EQ(WebIDBKeyTypeNumber, key.type()); 1215 DCHECK_EQ(WebIDBKeyTypeNumber, key.type());
1216 // Maximum integer storable as ECMAScript number.
pwnall 2017/03/07 19:42:41 Technically not true, 9007199254740994 can also be
jsbell 2017/03/07 20:27:57 Yeah, bad comment (copied pasted from above). Need
1217 const double max_generator_value = 9007199254740992.0;
1218 int64_t value = base::saturated_cast<int64_t>(
1219 floor(std::min(key.number(), max_generator_value)));
1211 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber( 1220 return backing_store->MaybeUpdateKeyGeneratorCurrentNumber(
1212 transaction->BackingStoreTransaction(), database_id, object_store_id, 1221 transaction->BackingStoreTransaction(), database_id, object_store_id,
1213 static_cast<int64_t>(floor(key.number())) + 1, check_current); 1222 value + 1, check_current);
1214 } 1223 }
1215 1224
1216 struct IndexedDBDatabase::PutOperationParams { 1225 struct IndexedDBDatabase::PutOperationParams {
1217 PutOperationParams() {} 1226 PutOperationParams() {}
1218 int64_t object_store_id; 1227 int64_t object_store_id;
1219 IndexedDBValue value; 1228 IndexedDBValue value;
1220 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; 1229 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
1221 std::unique_ptr<IndexedDBKey> key; 1230 std::unique_ptr<IndexedDBKey> key;
1222 blink::WebIDBPutMode put_mode; 1231 blink::WebIDBPutMode put_mode;
1223 scoped_refptr<IndexedDBCallbacks> callbacks; 1232 scoped_refptr<IndexedDBCallbacks> callbacks;
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1948 if (status.IsCorruption()) { 1957 if (status.IsCorruption()) {
1949 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, 1958 IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError,
1950 message); 1959 message);
1951 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error); 1960 factory_->HandleBackingStoreCorruption(backing_store_->origin(), error);
1952 } else { 1961 } else {
1953 factory_->HandleBackingStoreFailure(backing_store_->origin()); 1962 factory_->HandleBackingStoreFailure(backing_store_->origin());
1954 } 1963 }
1955 } 1964 }
1956 1965
1957 } // namespace content 1966 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698