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_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" | 13 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" |
14 #include "content/browser/indexed_db/indexed_db_metadata.h" | 14 #include "content/browser/indexed_db/indexed_db_metadata.h" |
15 #include "content/browser/indexed_db/indexed_db_tracing.h" | 15 #include "content/browser/indexed_db/indexed_db_tracing.h" |
16 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" | 16 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" |
17 #include "content/browser/indexed_db/leveldb/leveldb_database.h" | 17 #include "content/browser/indexed_db/leveldb/leveldb_database.h" |
18 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" | 18 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" |
19 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" | 19 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" |
20 #include "content/common/indexed_db/indexed_db_key.h" | 20 #include "content/common/indexed_db/indexed_db_key.h" |
21 #include "content/common/indexed_db/indexed_db_key_path.h" | 21 #include "content/common/indexed_db/indexed_db_key_path.h" |
22 #include "content/common/indexed_db/indexed_db_key_range.h" | 22 #include "content/common/indexed_db/indexed_db_key_range.h" |
23 #include "third_party/WebKit/public/platform/WebIDBTypes.h" | 23 #include "third_party/WebKit/public/platform/WebIDBTypes.h" |
| 24 #include "third_party/WebKit/public/web/WebSerializedScriptValueVersion.h" |
24 #include "third_party/leveldatabase/env_chromium.h" | 25 #include "third_party/leveldatabase/env_chromium.h" |
25 | 26 |
26 using base::StringPiece; | 27 using base::StringPiece; |
27 | 28 |
28 // TODO(jsbell): Make blink push the version during the open() call. | |
29 static const uint32 kWireVersion = 2; | |
30 | |
31 namespace content { | 29 namespace content { |
32 | 30 |
33 static const int64 kKeyGeneratorInitialNumber = | 31 static const int64 kKeyGeneratorInitialNumber = |
34 1; // From the IndexedDB specification. | 32 1; // From the IndexedDB specification. |
35 | 33 |
36 enum IndexedDBBackingStoreErrorSource { | 34 enum IndexedDBBackingStoreErrorSource { |
37 // 0 - 2 are no longer used. | 35 // 0 - 2 are no longer used. |
38 FIND_KEY_IN_INDEX = 3, | 36 FIND_KEY_IN_INDEX = 3, |
39 GET_IDBDATABASE_METADATA, | 37 GET_IDBDATABASE_METADATA, |
40 GET_INDEXES, | 38 GET_INDEXES, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 return false; | 200 return false; |
203 if (!found) { | 201 if (!found) { |
204 *known = true; | 202 *known = true; |
205 return true; | 203 return true; |
206 } | 204 } |
207 if (db_schema_version > kLatestKnownSchemaVersion) { | 205 if (db_schema_version > kLatestKnownSchemaVersion) { |
208 *known = false; | 206 *known = false; |
209 return true; | 207 return true; |
210 } | 208 } |
211 | 209 |
212 const uint32 latest_known_data_version = kWireVersion; | 210 const uint32 latest_known_data_version = |
| 211 WebKit::kSerializedScriptValueVersion; |
213 int64 db_data_version = 0; | 212 int64 db_data_version = 0; |
214 ok = GetInt(db, DataVersionKey::Encode(), &db_data_version, &found); | 213 ok = GetInt(db, DataVersionKey::Encode(), &db_data_version, &found); |
215 if (!ok) | 214 if (!ok) |
216 return false; | 215 return false; |
217 if (!found) { | 216 if (!found) { |
218 *known = true; | 217 *known = true; |
219 return true; | 218 return true; |
220 } | 219 } |
221 | 220 |
222 if (db_data_version > latest_known_data_version) { | 221 if (db_data_version > latest_known_data_version) { |
223 *known = false; | 222 *known = false; |
224 return true; | 223 return true; |
225 } | 224 } |
226 | 225 |
227 *known = true; | 226 *known = true; |
228 return true; | 227 return true; |
229 } | 228 } |
230 | 229 |
231 WARN_UNUSED_RESULT static bool SetUpMetadata( | 230 WARN_UNUSED_RESULT static bool SetUpMetadata( |
232 LevelDBDatabase* db, | 231 LevelDBDatabase* db, |
233 const std::string& origin_identifier) { | 232 const std::string& origin_identifier) { |
234 const uint32 latest_known_data_version = kWireVersion; | 233 const uint32 latest_known_data_version = |
| 234 WebKit::kSerializedScriptValueVersion; |
235 const std::string schema_version_key = SchemaVersionKey::Encode(); | 235 const std::string schema_version_key = SchemaVersionKey::Encode(); |
236 const std::string data_version_key = DataVersionKey::Encode(); | 236 const std::string data_version_key = DataVersionKey::Encode(); |
237 | 237 |
238 scoped_refptr<LevelDBTransaction> transaction = new LevelDBTransaction(db); | 238 scoped_refptr<LevelDBTransaction> transaction = new LevelDBTransaction(db); |
239 | 239 |
240 int64 db_schema_version = 0; | 240 int64 db_schema_version = 0; |
241 int64 db_data_version = 0; | 241 int64 db_data_version = 0; |
242 bool found = false; | 242 bool found = false; |
243 bool ok = | 243 bool ok = |
244 GetInt(transaction.get(), schema_version_key, &db_schema_version, &found); | 244 GetInt(transaction.get(), schema_version_key, &db_schema_version, &found); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 std::string int_version_key = DatabaseMetaDataKey::Encode( | 280 std::string int_version_key = DatabaseMetaDataKey::Encode( |
281 database_id, DatabaseMetaDataKey::USER_INT_VERSION); | 281 database_id, DatabaseMetaDataKey::USER_INT_VERSION); |
282 PutVarInt(transaction.get(), | 282 PutVarInt(transaction.get(), |
283 int_version_key, | 283 int_version_key, |
284 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); | 284 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); |
285 } | 285 } |
286 } | 286 } |
287 if (db_schema_version < 2) { | 287 if (db_schema_version < 2) { |
288 db_schema_version = 2; | 288 db_schema_version = 2; |
289 PutInt(transaction.get(), schema_version_key, db_schema_version); | 289 PutInt(transaction.get(), schema_version_key, db_schema_version); |
290 db_data_version = kWireVersion; | 290 db_data_version = WebKit::kSerializedScriptValueVersion; |
291 PutInt(transaction.get(), data_version_key, db_data_version); | 291 PutInt(transaction.get(), data_version_key, db_data_version); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 // All new values will be written using this serialization version. | 295 // All new values will be written using this serialization version. |
296 found = false; | 296 found = false; |
297 ok = GetInt(transaction.get(), data_version_key, &db_data_version, &found); | 297 ok = GetInt(transaction.get(), data_version_key, &db_data_version, &found); |
298 if (!ok) { | 298 if (!ok) { |
299 INTERNAL_READ_ERROR(SET_UP_METADATA); | 299 INTERNAL_READ_ERROR(SET_UP_METADATA); |
300 return false; | 300 return false; |
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2638 } | 2638 } |
2639 | 2639 |
2640 void IndexedDBBackingStore::Transaction::Rollback() { | 2640 void IndexedDBBackingStore::Transaction::Rollback() { |
2641 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); | 2641 IDB_TRACE("IndexedDBBackingStore::Transaction::Rollback"); |
2642 DCHECK(transaction_.get()); | 2642 DCHECK(transaction_.get()); |
2643 transaction_->Rollback(); | 2643 transaction_->Rollback(); |
2644 transaction_ = NULL; | 2644 transaction_ = NULL; |
2645 } | 2645 } |
2646 | 2646 |
2647 } // namespace content | 2647 } // namespace content |
OLD | NEW |