summaryrefslogtreecommitdiffstats
path: root/content/browser/indexed_db
diff options
context:
space:
mode:
authorjsbell <jsbell@chromium.org>2016-03-10 10:59:50 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-10 19:01:20 +0000
commitb8f7a9160398c23a44807ff474e7e5288e223416 (patch)
tree07919ac9151e2c5568488e1c6654d037a43ba257 /content/browser/indexed_db
parent1ff345867aad0aab194da5acf8d46410f27d6494 (diff)
downloadchromium_src-b8f7a9160398c23a44807ff474e7e5288e223416.zip
chromium_src-b8f7a9160398c23a44807ff474e7e5288e223416.tar.gz
chromium_src-b8f7a9160398c23a44807ff474e7e5288e223416.tar.bz2
Reduce use of DatabaseIdentifier in Indexed DB entry points.
A DatabaseIdentifier is a way to serialize an origin URL, but it is only needed when creating filenames. Stop using it where an origin URL is perfectly appropriate, and remove duplicate conversion functions when it is used. Also, remove a few unused includes of database identifier headers. BUG=591240 R=michaeln@chromium.org Review URL: https://codereview.chromium.org/1757693002 Cr-Commit-Position: refs/heads/master@{#380438}
Diffstat (limited to 'content/browser/indexed_db')
-rw-r--r--content/browser/indexed_db/indexed_db_backing_store.cc27
-rw-r--r--content/browser/indexed_db/indexed_db_context_impl.cc56
-rw-r--r--content/browser/indexed_db/indexed_db_context_impl.h10
-rw-r--r--content/browser/indexed_db/indexed_db_factory_impl.cc1
-rw-r--r--content/browser/indexed_db/indexed_db_factory_unittest.cc1
-rw-r--r--content/browser/indexed_db/indexed_db_quota_client_unittest.cc5
-rw-r--r--content/browser/indexed_db/indexed_db_unittest.cc19
7 files changed, 54 insertions, 65 deletions
diff --git a/content/browser/indexed_db/indexed_db_backing_store.cc b/content/browser/indexed_db/indexed_db_backing_store.cc
index cfca4f8..71ad4e1 100644
--- a/content/browser/indexed_db/indexed_db_backing_store.cc
+++ b/content/browser/indexed_db/indexed_db_backing_store.cc
@@ -23,6 +23,7 @@
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/indexed_db/indexed_db_blob_info.h"
#include "content/browser/indexed_db/indexed_db_class_factory.h"
+#include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/indexed_db/indexed_db_database_error.h"
#include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
#include "content/browser/indexed_db/indexed_db_metadata.h"
@@ -89,20 +90,8 @@ static std::string ComputeOriginIdentifier(const GURL& origin_url) {
return storage::GetIdentifierFromOrigin(origin_url) + "@1";
}
-static base::FilePath ComputeFileName(const GURL& origin_url) {
- return base::FilePath()
- .AppendASCII(storage::GetIdentifierFromOrigin(origin_url))
- .AddExtension(FILE_PATH_LITERAL(".indexeddb.leveldb"));
-}
-
-static base::FilePath ComputeBlobPath(const GURL& origin_url) {
- return base::FilePath()
- .AppendASCII(storage::GetIdentifierFromOrigin(origin_url))
- .AddExtension(FILE_PATH_LITERAL(".indexeddb.blob"));
-}
-
-static base::FilePath ComputeCorruptionFileName(const GURL& origin_url) {
- return ComputeFileName(origin_url)
+static FilePath ComputeCorruptionFileName(const GURL& origin_url) {
+ return IndexedDBContextImpl::GetLevelDBFileName(origin_url)
.Append(FILE_PATH_LITERAL("corruption_info.json"));
}
@@ -910,7 +899,7 @@ leveldb::Status IndexedDBBackingStore::DestroyBackingStore(
const base::FilePath& path_base,
const GURL& origin_url) {
const base::FilePath file_path =
- path_base.Append(ComputeFileName(origin_url));
+ path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin_url));
DefaultLevelDBFactory leveldb_factory;
return leveldb_factory.DestroyLevelDB(file_path);
}
@@ -1014,10 +1003,10 @@ scoped_refptr<IndexedDBBackingStore> IndexedDBBackingStore::Open(
return scoped_refptr<IndexedDBBackingStore>();
}
- const base::FilePath file_path =
- path_base.Append(ComputeFileName(origin_url));
- const base::FilePath blob_path =
- path_base.Append(ComputeBlobPath(origin_url));
+ const FilePath file_path =
+ path_base.Append(IndexedDBContextImpl::GetLevelDBFileName(origin_url));
+ const FilePath blob_path =
+ path_base.Append(IndexedDBContextImpl::GetBlobStoreFileName(origin_url));
if (IsPathTooLong(file_path)) {
*status = leveldb::Status::IOError("File path too long");
diff --git a/content/browser/indexed_db/indexed_db_context_impl.cc b/content/browser/indexed_db/indexed_db_context_impl.cc
index 28843d6..cbe6016 100644
--- a/content/browser/indexed_db/indexed_db_context_impl.cc
+++ b/content/browser/indexed_db/indexed_db_context_impl.cc
@@ -281,9 +281,8 @@ base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() {
int IndexedDBContextImpl::GetOriginBlobFileCount(const GURL& origin_url) {
DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
int count = 0;
- base::FileEnumerator file_enumerator(
- GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), true,
- base::FileEnumerator::FILES);
+ base::FileEnumerator file_enumerator(GetBlobStorePath(origin_url), true,
+ base::FileEnumerator::FILES);
for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty();
file_path = file_enumerator.Next()) {
count++;
@@ -329,8 +328,7 @@ void IndexedDBContextImpl::DeleteForOrigin(const GURL& origin_url) {
const bool kNonRecursive = false;
base::DeleteFile(idb_directory, kNonRecursive);
}
- base::DeleteFile(GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)),
- true /* recursive */);
+ base::DeleteFile(GetBlobStorePath(origin_url), true /* recursive */);
QueryDiskAndUpdateQuotaUsage(origin_url);
if (s.ok()) {
RemoveFromOriginSet(origin_url);
@@ -349,7 +347,6 @@ void IndexedDBContextImpl::CopyOriginData(const GURL& origin_url,
static_cast<IndexedDBContextImpl*>(dest_context);
ForceClose(origin_url, FORCE_CLOSE_COPY_ORIGIN);
- std::string origin_id = storage::GetIdentifierFromOrigin(origin_url);
// Make sure we're not about to delete our own database.
CHECK_NE(dest_context_impl->data_path().value(), data_path().value());
@@ -397,24 +394,17 @@ size_t IndexedDBContextImpl::GetConnectionCount(const GURL& origin_url) {
return factory_->GetConnectionCount(origin_url);
}
-base::FilePath IndexedDBContextImpl::GetLevelDBPath(
- const GURL& origin_url) const {
- std::string origin_id = storage::GetIdentifierFromOrigin(origin_url);
- return GetLevelDBPath(origin_id);
-}
-
std::vector<base::FilePath> IndexedDBContextImpl::GetStoragePaths(
const GURL& origin_url) const {
- std::string origin_id = storage::GetIdentifierFromOrigin(origin_url);
std::vector<base::FilePath> paths;
- paths.push_back(GetLevelDBPath(origin_id));
- paths.push_back(GetBlobPath(origin_id));
+ paths.push_back(GetLevelDBPath(origin_url));
+ paths.push_back(GetBlobStorePath(origin_url));
return paths;
}
base::FilePath IndexedDBContextImpl::GetFilePathForTesting(
- const std::string& origin_id) const {
- return GetLevelDBPath(origin_id);
+ const GURL& origin_url) const {
+ return GetLevelDBPath(origin_url);
}
void IndexedDBContextImpl::SetTaskRunnerForTesting(
@@ -484,18 +474,36 @@ IndexedDBContextImpl::~IndexedDBContextImpl() {
&ClearSessionOnlyOrigins, data_path_, special_storage_policy_));
}
-base::FilePath IndexedDBContextImpl::GetBlobPath(
- const std::string& origin_id) const {
- DCHECK(!data_path_.empty());
- return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension)
+// static
+base::FilePath IndexedDBContextImpl::GetBlobStoreFileName(
+ const GURL& origin_url) {
+ std::string origin_id = storage::GetIdentifierFromOrigin(origin_url);
+ return base::FilePath()
+ .AppendASCII(origin_id)
+ .AddExtension(kIndexedDBExtension)
.AddExtension(kBlobExtension);
}
+// static
+base::FilePath IndexedDBContextImpl::GetLevelDBFileName(
+ const GURL& origin_url) {
+ std::string origin_id = storage::GetIdentifierFromOrigin(origin_url);
+ return base::FilePath()
+ .AppendASCII(origin_id)
+ .AddExtension(kIndexedDBExtension)
+ .AddExtension(kLevelDBExtension);
+}
+
+base::FilePath IndexedDBContextImpl::GetBlobStorePath(
+ const GURL& origin_url) const {
+ DCHECK(!data_path_.empty());
+ return data_path_.Append(GetBlobStoreFileName(origin_url));
+}
+
base::FilePath IndexedDBContextImpl::GetLevelDBPath(
- const std::string& origin_id) const {
+ const GURL& origin_url) const {
DCHECK(!data_path_.empty());
- return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension)
- .AddExtension(kLevelDBExtension);
+ return data_path_.Append(GetLevelDBFileName(origin_url));
}
int64_t IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const {
diff --git a/content/browser/indexed_db/indexed_db_context_impl.h b/content/browser/indexed_db/indexed_db_context_impl.h
index 9967d2c..608e0f2 100644
--- a/content/browser/indexed_db/indexed_db_context_impl.h
+++ b/content/browser/indexed_db/indexed_db_context_impl.h
@@ -74,8 +74,7 @@ class CONTENT_EXPORT IndexedDBContextImpl
void DeleteForOrigin(const GURL& origin_url) override;
void CopyOriginData(const GURL& origin_url,
IndexedDBContext* dest_context) override;
- base::FilePath GetFilePathForTesting(
- const std::string& origin_id) const override;
+ base::FilePath GetFilePathForTesting(const GURL& origin_url) const override;
void SetTaskRunnerForTesting(base::SequencedTaskRunner* task_runner) override;
// Methods called by IndexedDBDispatcherHost for quota support.
@@ -84,6 +83,9 @@ class CONTENT_EXPORT IndexedDBContextImpl
void TransactionComplete(const GURL& origin_url);
void DatabaseDeleted(const GURL& origin_url);
+ static base::FilePath GetBlobStoreFileName(const GURL& origin_url);
+ static base::FilePath GetLevelDBFileName(const GURL& origin_url);
+
// Will be null in unit tests.
storage::QuotaManagerProxy* quota_manager_proxy() const {
return quota_manager_proxy_.get();
@@ -127,9 +129,9 @@ class CONTENT_EXPORT IndexedDBContextImpl
typedef std::map<GURL, int64_t> OriginToSizeMap;
class IndexedDBGetUsageAndQuotaCallback;
- base::FilePath GetBlobPath(const std::string& origin_id) const;
+ base::FilePath GetBlobStorePath(const GURL& origin_url) const;
base::FilePath GetLevelDBPath(const GURL& origin_url) const;
- base::FilePath GetLevelDBPath(const std::string& origin_id) const;
+
int64_t ReadUsageFromDisk(const GURL& origin_url) const;
void EnsureDiskUsageCacheInitialized(const GURL& origin_url);
void QueryDiskAndUpdateQuotaUsage(const GURL& origin_url);
diff --git a/content/browser/indexed_db/indexed_db_factory_impl.cc b/content/browser/indexed_db/indexed_db_factory_impl.cc
index 2261dcc..33db01f 100644
--- a/content/browser/indexed_db/indexed_db_factory_impl.cc
+++ b/content/browser/indexed_db/indexed_db_factory_impl.cc
@@ -17,7 +17,6 @@
#include "content/browser/indexed_db/indexed_db_database_error.h"
#include "content/browser/indexed_db/indexed_db_tracing.h"
#include "content/browser/indexed_db/indexed_db_transaction_coordinator.h"
-#include "storage/common/database/database_identifier.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h"
#include "third_party/leveldatabase/env_chromium.h"
diff --git a/content/browser/indexed_db/indexed_db_factory_unittest.cc b/content/browser/indexed_db/indexed_db_factory_unittest.cc
index 946799a..b61e66c 100644
--- a/content/browser/indexed_db/indexed_db_factory_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_factory_unittest.cc
@@ -18,7 +18,6 @@
#include "content/browser/indexed_db/mock_indexed_db_callbacks.h"
#include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h"
#include "content/browser/quota/mock_quota_manager_proxy.h"
-#include "storage/common/database/database_identifier.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseException.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
diff --git a/content/browser/indexed_db/indexed_db_quota_client_unittest.cc b/content/browser/indexed_db/indexed_db_quota_client_unittest.cc
index 31a4136..a626dc0 100644
--- a/content/browser/indexed_db/indexed_db_quota_client_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_quota_client_unittest.cc
@@ -20,7 +20,6 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h"
-#include "storage/common/database/database_identifier.h"
#include "testing/gtest/include/gtest/gtest.h"
// Declared to shorten the line lengths.
@@ -139,8 +138,8 @@ class IndexedDBQuotaClientTest : public testing::Test {
}
void AddFakeIndexedDB(const GURL& origin, int size) {
- base::FilePath file_path_origin = idb_context()->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(origin));
+ base::FilePath file_path_origin =
+ idb_context()->GetFilePathForTesting(origin);
if (!base::CreateDirectory(file_path_origin)) {
LOG(ERROR) << "failed to base::CreateDirectory "
<< file_path_origin.value();
diff --git a/content/browser/indexed_db/indexed_db_unittest.cc b/content/browser/indexed_db/indexed_db_unittest.cc
index 9ed1e73..7b057d5 100644
--- a/content/browser/indexed_db/indexed_db_unittest.cc
+++ b/content/browser/indexed_db/indexed_db_unittest.cc
@@ -23,7 +23,6 @@
#include "content/public/test/test_browser_context.h"
#include "storage/browser/quota/quota_manager.h"
#include "storage/browser/quota/special_storage_policy.h"
-#include "storage/common/database/database_identifier.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
@@ -78,10 +77,8 @@ TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) {
quota_manager_proxy_.get(),
task_runner_.get());
- normal_path = idb_context->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(kNormalOrigin));
- session_only_path = idb_context->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(kSessionOnlyOrigin));
+ normal_path = idb_context->GetFilePathForTesting(kNormalOrigin);
+ session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin);
ASSERT_TRUE(base::CreateDirectory(normal_path));
ASSERT_TRUE(base::CreateDirectory(session_only_path));
FlushIndexedDBTaskRunner();
@@ -116,10 +113,8 @@ TEST_F(IndexedDBTest, SetForceKeepSessionState) {
// Save session state. This should bypass the destruction-time deletion.
idb_context->SetForceKeepSessionState();
- normal_path = idb_context->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(kNormalOrigin));
- session_only_path = idb_context->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(kSessionOnlyOrigin));
+ normal_path = idb_context->GetFilePathForTesting(kNormalOrigin);
+ session_only_path = idb_context->GetFilePathForTesting(kSessionOnlyOrigin);
ASSERT_TRUE(base::CreateDirectory(normal_path));
ASSERT_TRUE(base::CreateDirectory(session_only_path));
message_loop_.RunUntilIdle();
@@ -192,8 +187,7 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
IndexedDBFactory* factory = idb_context->GetIDBFactory();
- test_path = idb_context->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(kTestOrigin));
+ test_path = idb_context->GetFilePathForTesting(kTestOrigin);
IndexedDBPendingConnection open_connection(open_callbacks,
open_db_callbacks,
@@ -243,8 +237,7 @@ TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) {
temp_dir.path(), special_storage_policy_.get(),
quota_manager_proxy_.get(), task_runner_.get());
- base::FilePath test_path = idb_context->GetFilePathForTesting(
- storage::GetIdentifierFromOrigin(kTestOrigin));
+ base::FilePath test_path = idb_context->GetFilePathForTesting(kTestOrigin);
ASSERT_TRUE(base::CreateDirectory(test_path));
scoped_ptr<LevelDBLock> lock =