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

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

Issue 1757693002: Reduce use of DatabaseIdentifier in Indexed DB entry points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert change for ZIP file naming Created 4 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_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "content/browser/child_process_security_policy_impl.h" 22 #include "content/browser/child_process_security_policy_impl.h"
23 #include "content/browser/indexed_db/indexed_db_blob_info.h" 23 #include "content/browser/indexed_db/indexed_db_blob_info.h"
24 #include "content/browser/indexed_db/indexed_db_class_factory.h" 24 #include "content/browser/indexed_db/indexed_db_class_factory.h"
25 #include "content/browser/indexed_db/indexed_db_context_impl.h"
25 #include "content/browser/indexed_db/indexed_db_database_error.h" 26 #include "content/browser/indexed_db/indexed_db_database_error.h"
26 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" 27 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
27 #include "content/browser/indexed_db/indexed_db_metadata.h" 28 #include "content/browser/indexed_db/indexed_db_metadata.h"
28 #include "content/browser/indexed_db/indexed_db_tracing.h" 29 #include "content/browser/indexed_db/indexed_db_tracing.h"
29 #include "content/browser/indexed_db/indexed_db_value.h" 30 #include "content/browser/indexed_db/indexed_db_value.h"
30 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" 31 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h"
31 #include "content/browser/indexed_db/leveldb/leveldb_database.h" 32 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
32 #include "content/browser/indexed_db/leveldb/leveldb_factory.h" 33 #include "content/browser/indexed_db/leveldb/leveldb_factory.h"
33 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h" 34 #include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
34 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h" 35 #include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 int64_t database_id, 82 int64_t database_id,
82 int64_t key) { 83 int64_t key) {
83 FilePath path = GetBlobDirectoryNameForKey(path_base, database_id, key); 84 FilePath path = GetBlobDirectoryNameForKey(path_base, database_id, key);
84 return base::CreateDirectory(path); 85 return base::CreateDirectory(path);
85 } 86 }
86 87
87 static std::string ComputeOriginIdentifier(const GURL& origin_url) { 88 static std::string ComputeOriginIdentifier(const GURL& origin_url) {
88 return storage::GetIdentifierFromOrigin(origin_url) + "@1"; 89 return storage::GetIdentifierFromOrigin(origin_url) + "@1";
89 } 90 }
90 91
91 static base::FilePath ComputeFileName(const GURL& origin_url) { 92 static FilePath ComputeCorruptionFileName(const GURL& origin_url) {
92 return base::FilePath() 93 return IndexedDBContextImpl::GetLevelDBFileName(origin_url)
93 .AppendASCII(storage::GetIdentifierFromOrigin(origin_url))
94 .AddExtension(FILE_PATH_LITERAL(".indexeddb.leveldb"));
95 }
96
97 static base::FilePath ComputeBlobPath(const GURL& origin_url) {
98 return base::FilePath()
99 .AppendASCII(storage::GetIdentifierFromOrigin(origin_url))
100 .AddExtension(FILE_PATH_LITERAL(".indexeddb.blob"));
101 }
102
103 static base::FilePath ComputeCorruptionFileName(const GURL& origin_url) {
104 return ComputeFileName(origin_url)
105 .Append(FILE_PATH_LITERAL("corruption_info.json")); 94 .Append(FILE_PATH_LITERAL("corruption_info.json"));
106 } 95 }
107 96
108 } // namespace 97 } // namespace
109 98
110 static const int64_t kKeyGeneratorInitialNumber = 99 static const int64_t kKeyGeneratorInitialNumber =
111 1; // From the IndexedDB specification. 100 1; // From the IndexedDB specification.
112 101
113 enum IndexedDBBackingStoreErrorSource { 102 enum IndexedDBBackingStoreErrorSource {
114 // 0 - 2 are no longer used. 103 // 0 - 2 are no longer used.
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 num_buckets); 891 num_buckets);
903 return true; 892 return true;
904 } 893 }
905 return false; 894 return false;
906 } 895 }
907 896
908 leveldb::Status IndexedDBBackingStore::DestroyBackingStore( 897 leveldb::Status IndexedDBBackingStore::DestroyBackingStore(
909 const base::FilePath& path_base, 898 const base::FilePath& path_base,
910 const GURL& origin_url) { 899 const GURL& origin_url) {
911 const base::FilePath file_path = 900 const base::FilePath file_path =
912 path_base.Append(ComputeFileName(origin_url)); 901 path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin_url));
913 DefaultLevelDBFactory leveldb_factory; 902 DefaultLevelDBFactory leveldb_factory;
914 return leveldb_factory.DestroyLevelDB(file_path); 903 return leveldb_factory.DestroyLevelDB(file_path);
915 } 904 }
916 905
917 bool IndexedDBBackingStore::ReadCorruptionInfo(const base::FilePath& path_base, 906 bool IndexedDBBackingStore::ReadCorruptionInfo(const base::FilePath& path_base,
918 const GURL& origin_url, 907 const GURL& origin_url,
919 std::string* message) { 908 std::string* message) {
920 const base::FilePath info_path = 909 const base::FilePath info_path =
921 path_base.Append(ComputeCorruptionFileName(origin_url)); 910 path_base.Append(ComputeCorruptionFileName(origin_url));
922 911
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 if (!base::CreateDirectory(path_base)) { 995 if (!base::CreateDirectory(path_base)) {
1007 *status = 996 *status =
1008 leveldb::Status::IOError("Unable to create IndexedDB database path"); 997 leveldb::Status::IOError("Unable to create IndexedDB database path");
1009 LOG(ERROR) << status->ToString() << ": \"" << path_base.AsUTF8Unsafe() 998 LOG(ERROR) << status->ToString() << ": \"" << path_base.AsUTF8Unsafe()
1010 << "\""; 999 << "\"";
1011 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_DIRECTORY, 1000 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_FAILED_DIRECTORY,
1012 origin_url); 1001 origin_url);
1013 return scoped_refptr<IndexedDBBackingStore>(); 1002 return scoped_refptr<IndexedDBBackingStore>();
1014 } 1003 }
1015 1004
1016 const base::FilePath file_path = 1005 const FilePath file_path =
1017 path_base.Append(ComputeFileName(origin_url)); 1006 path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin_url));
1018 const base::FilePath blob_path = 1007 const FilePath blob_path =
1019 path_base.Append(ComputeBlobPath(origin_url)); 1008 path_base.Append(IndexedDBContextImpl::GetBlobStoreFileName(origin_url));
1020 1009
1021 if (IsPathTooLong(file_path)) { 1010 if (IsPathTooLong(file_path)) {
1022 *status = leveldb::Status::IOError("File path too long"); 1011 *status = leveldb::Status::IOError("File path too long");
1023 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG, 1012 HistogramOpenStatus(INDEXED_DB_BACKING_STORE_OPEN_ORIGIN_TOO_LONG,
1024 origin_url); 1013 origin_url);
1025 return scoped_refptr<IndexedDBBackingStore>(); 1014 return scoped_refptr<IndexedDBBackingStore>();
1026 } 1015 }
1027 1016
1028 scoped_ptr<LevelDBDatabase> db; 1017 scoped_ptr<LevelDBDatabase> db;
1029 *status = leveldb_factory->OpenLevelDB( 1018 *status = leveldb_factory->OpenLevelDB(
(...skipping 3452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4482 4471
4483 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( 4472 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor(
4484 const WriteDescriptor& other) = default; 4473 const WriteDescriptor& other) = default;
4485 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = 4474 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() =
4486 default; 4475 default;
4487 IndexedDBBackingStore::Transaction::WriteDescriptor& 4476 IndexedDBBackingStore::Transaction::WriteDescriptor&
4488 IndexedDBBackingStore::Transaction::WriteDescriptor:: 4477 IndexedDBBackingStore::Transaction::WriteDescriptor::
4489 operator=(const WriteDescriptor& other) = default; 4478 operator=(const WriteDescriptor& other) = default;
4490 4479
4491 } // namespace content 4480 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698