Skip to content

Commit

Permalink
Use chromium logic for database identifier<->origin conversions
Browse files Browse the repository at this point in the history
This switches over to using the logic added in r206815 for database id /
origin identification instead of WebSecurityOrigin. I'll delete the old code
after this has landed.

BUG=243095
TBR=thakis

Review URL: https://chromiumcodereview.appspot.com/16879013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207191 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jamesr@chromium.org committed Jun 19, 2013
1 parent d97b7cd commit 2a9644c
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 142 deletions.
6 changes: 3 additions & 3 deletions chrome/browser/extensions/extension_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
#include "sync/protocol/sync.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/database/database_tracker.h"
#include "webkit/browser/quota/quota_manager.h"
#include "webkit/common/database/database_identifier.h"
#include "webkit/plugins/npapi/mock_plugin_list.h"

#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -3892,7 +3892,7 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) {
const Extension* extension = InstallCRX(path, INSTALL_NEW);
ASSERT_TRUE(extension);
GURL ext_url(extension->url());
std::string origin_id = webkit_base::GetOriginIdentifierFromURL(ext_url);
std::string origin_id = webkit_database::GetIdentifierFromOrigin(ext_url);

// Set a cookie for the extension.
net::CookieMonster* cookie_monster =
Expand Down Expand Up @@ -3992,7 +3992,7 @@ TEST_F(ExtensionServiceTest, ClearAppData) {
extensions::AppLaunchInfo::GetFullLaunchURL(extension).GetOrigin());
EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
IsStorageUnlimited(origin1));
std::string origin_id = webkit_base::GetOriginIdentifierFromURL(origin1);
std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin1);

// Install app2 from the same origin with unlimited storage.
extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#include "third_party/WebKit/public/platform/WebIDBDatabaseError.h"
#include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
#include "webkit/base/file_path_string_conversions.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/database/database_util.h"
#include "webkit/common/database/database_identifier.h"

using webkit_database::DatabaseUtil;
using WebKit::WebIDBDatabaseError;
Expand Down Expand Up @@ -233,7 +233,7 @@ void IndexedDBDispatcherHost::OnIDBFactoryOpen(
base::FilePath indexed_db_path = indexed_db_context_->data_path();

GURL origin_url =
webkit_base::GetOriginURLFromIdentifier(params.database_identifier);
webkit_database::GetOriginFromIdentifier(params.database_identifier);

DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));

Expand Down
23 changes: 14 additions & 9 deletions content/browser/indexed_db/indexed_db_context_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@
#include "content/public/common/content_switches.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "webkit/base/file_path_string_conversions.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/database/database_util.h"
#include "webkit/browser/quota/quota_manager.h"
#include "webkit/browser/quota/special_storage_policy.h"
#include "webkit/common/database/database_identifier.h"

using webkit_database::DatabaseUtil;

namespace content {
const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBDirectory[] =
FILE_PATH_LITERAL("IndexedDB");

const base::FilePath::CharType IndexedDBContextImpl::kIndexedDBExtension[] =
static const base::FilePath::CharType kIndexedDBExtension[] =
FILE_PATH_LITERAL(".indexeddb");

static const base::FilePath::CharType kLevelDBExtension[] =
FILE_PATH_LITERAL(".leveldb");

namespace {
Expand All @@ -48,9 +51,11 @@ void GetAllOriginsAndPaths(const base::FilePath& indexeddb_path,
indexeddb_path, false, base::FileEnumerator::DIRECTORIES);
for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty();
file_path = file_enumerator.Next()) {
if (file_path.Extension() == IndexedDBContextImpl::kIndexedDBExtension) {
std::string origin_id = file_path.BaseName().MaybeAsASCII();
origins->push_back(webkit_base::GetOriginURLFromIdentifier(origin_id));
if (file_path.Extension() == kLevelDBExtension &&
file_path.RemoveExtension().Extension() == kIndexedDBExtension) {
std::string origin_id = file_path.BaseName().RemoveExtension()
.RemoveExtension().MaybeAsASCII();
origins->push_back(webkit_database::GetOriginFromIdentifier(origin_id));
if (file_paths)
file_paths->push_back(file_path);
}
Expand Down Expand Up @@ -195,7 +200,7 @@ void IndexedDBContextImpl::ForceClose(const GURL& origin_url) {

base::FilePath IndexedDBContextImpl::GetFilePath(const GURL& origin_url) {
std::string origin_id =
webkit_base::GetOriginIdentifierFromURL(origin_url);
webkit_database::GetIdentifierFromOrigin(origin_url);
return GetIndexedDBFilePath(origin_id);
}

Expand Down Expand Up @@ -303,15 +308,15 @@ base::FilePath IndexedDBContextImpl::GetIndexedDBFilePath(
const std::string& origin_id) const {
DCHECK(!data_path_.empty());
return data_path_.AppendASCII(origin_id).
AddExtension(FILE_PATH_LITERAL(".indexeddb")).
AddExtension(kIndexedDBExtension);
AddExtension(kIndexedDBExtension).
AddExtension(kLevelDBExtension);
}

int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const {
if (data_path_.empty())
return 0;
std::string origin_id =
webkit_base::GetOriginIdentifierFromURL(origin_url);
webkit_database::GetIdentifierFromOrigin(origin_url);
base::FilePath file_path = GetIndexedDBFilePath(origin_id);
return file_util::ComputeDirectorySize(file_path);
}
Expand Down
3 changes: 0 additions & 3 deletions content/browser/indexed_db/indexed_db_context_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class CONTENT_EXPORT IndexedDBContextImpl
// The indexed db directory.
static const base::FilePath::CharType kIndexedDBDirectory[];

// The indexed db file extension.
static const base::FilePath::CharType kIndexedDBExtension[];

// Disables the exit-time deletion of session-only data.
void SetForceKeepSessionState() { force_keep_session_state_ = true; }

Expand Down
4 changes: 2 additions & 2 deletions content/browser/indexed_db/indexed_db_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/zlib/google/zip.h"
#include "webkit/base/file_path_string_conversions.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/common/database/database_identifier.h"

namespace content {

Expand Down Expand Up @@ -206,7 +206,7 @@ void IndexedDBInternalsUI::DownloadOriginDataOnWebkitThread(
base::FilePath temp_path = temp_dir.Take();

std::string origin_id =
webkit_base::GetOriginIdentifierFromURL(origin_url);
webkit_database::GetIdentifierFromOrigin(origin_url);
base::FilePath zip_path =
temp_path.AppendASCII(origin_id).AddExtension(FILE_PATH_LITERAL("zip"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "content/public/browser/storage_partition.h"
#include "content/public/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/common/database/database_identifier.h"

// Declared to shorten the line lengths.
static const quota::StorageType kTemp = quota::kStorageTypeTemporary;
Expand Down Expand Up @@ -128,7 +128,7 @@ class IndexedDBQuotaClientTest : public testing::Test {

void AddFakeIndexedDB(const GURL& origin, int size) {
base::FilePath file_path_origin = idb_context()->GetFilePathForTesting(
webkit_base::GetOriginIdentifierFromURL(origin));
webkit_database::GetIdentifierFromOrigin(origin));
if (!file_util::CreateDirectory(file_path_origin)) {
LOG(ERROR) << "failed to file_util::CreateDirectory "
<< file_path_origin.value();
Expand Down
12 changes: 6 additions & 6 deletions content/browser/indexed_db/indexed_db_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include "content/public/common/url_constants.h"
#include "content/public/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/quota/mock_special_storage_policy.h"
#include "webkit/browser/quota/quota_manager.h"
#include "webkit/browser/quota/special_storage_policy.h"
#include "webkit/common/database/database_identifier.h"

namespace content {

Expand Down Expand Up @@ -64,9 +64,9 @@ TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) {
idb_context->set_data_path_for_testing(temp_dir.path());

normal_path = idb_context->GetFilePathForTesting(
webkit_base::GetOriginIdentifierFromURL(kNormalOrigin));
webkit_database::GetIdentifierFromOrigin(kNormalOrigin));
session_only_path = idb_context->GetFilePathForTesting(
webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin));
webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin));
ASSERT_TRUE(file_util::CreateDirectory(normal_path));
ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
message_loop_.RunUntilIdle();
Expand Down Expand Up @@ -110,9 +110,9 @@ TEST_F(IndexedDBTest, SetForceKeepSessionState) {
idb_context->SetForceKeepSessionState();

normal_path = idb_context->GetFilePathForTesting(
webkit_base::GetOriginIdentifierFromURL(kNormalOrigin));
webkit_database::GetIdentifierFromOrigin(kNormalOrigin));
session_only_path = idb_context->GetFilePathForTesting(
webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin));
webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin));
ASSERT_TRUE(file_util::CreateDirectory(normal_path));
ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
message_loop_.RunUntilIdle();
Expand Down Expand Up @@ -168,7 +168,7 @@ TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
idb_context->set_data_path_for_testing(temp_dir.path());

test_path = idb_context->GetFilePathForTesting(
webkit_base::GetOriginIdentifierFromURL(kTestOrigin));
webkit_database::GetIdentifierFromOrigin(kTestOrigin));
ASSERT_TRUE(file_util::CreateDirectory(test_path));

const bool kExpectForceClose = true;
Expand Down
4 changes: 2 additions & 2 deletions content/browser/renderer_host/database_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include "content/public/common/result_codes.h"
#include "googleurl/src/gurl.h"
#include "third_party/sqlite/sqlite3.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/database/database_util.h"
#include "webkit/browser/database/vfs_backend.h"
#include "webkit/browser/quota/quota_manager.h"
#include "webkit/common/database/database_identifier.h"

#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
Expand Down Expand Up @@ -260,7 +260,7 @@ void DatabaseMessageFilter::OnDatabaseGetSpaceAvailable(
}

quota_manager->GetUsageAndQuota(
webkit_base::GetOriginURLFromIdentifier(origin_identifier),
webkit_database::GetOriginFromIdentifier(origin_identifier),
quota::kStorageTypeTemporary,
base::Bind(&DatabaseMessageFilter::OnDatabaseGetUsageAndQuota,
this, reply_msg));
Expand Down
36 changes: 0 additions & 36 deletions webkit/base/origin_url_conversions.cc

This file was deleted.

30 changes: 0 additions & 30 deletions webkit/base/origin_url_conversions.h

This file was deleted.

2 changes: 0 additions & 2 deletions webkit/base/webkit_base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
'data_element.h',
'file_path_string_conversions.cc',
'file_path_string_conversions.h',
'origin_url_conversions.cc',
'origin_url_conversions.h',
'webkit_base_export.h',
],
},
Expand Down
10 changes: 5 additions & 5 deletions webkit/browser/database/database_quota_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include "base/task_runner_util.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/database/database_tracker.h"
#include "webkit/browser/database/database_util.h"
#include "webkit/common/database/database_identifier.h"

using quota::QuotaClient;

Expand All @@ -29,7 +29,7 @@ int64 GetOriginUsageOnDBThread(
const GURL& origin_url) {
OriginInfo info;
if (db_tracker->GetOriginInfo(
webkit_base::GetOriginIdentifierFromURL(origin_url), &info))
webkit_database::GetIdentifierFromOrigin(origin_url), &info))
return info.TotalSize();
return 0;
}
Expand All @@ -42,7 +42,7 @@ void GetOriginsOnDBThread(
for (std::vector<std::string>::const_iterator iter =
origin_identifiers.begin();
iter != origin_identifiers.end(); ++iter) {
GURL origin = webkit_base::GetOriginURLFromIdentifier(*iter);
GURL origin = webkit_database::GetOriginFromIdentifier(*iter);
origins_ptr->insert(origin);
}
}
Expand All @@ -57,7 +57,7 @@ void GetOriginsForHostOnDBThread(
for (std::vector<std::string>::const_iterator iter =
origin_identifiers.begin();
iter != origin_identifiers.end(); ++iter) {
GURL origin = webkit_base::GetOriginURLFromIdentifier(*iter);
GURL origin = webkit_database::GetOriginFromIdentifier(*iter);
if (host == net::GetHostOrSpecFromURL(origin))
origins_ptr->insert(origin);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ void DatabaseQuotaClient::DeleteOriginData(
FROM_HERE,
base::Bind(&DatabaseTracker::DeleteDataForOrigin,
db_tracker_,
webkit_base::GetOriginIdentifierFromURL(origin),
webkit_database::GetIdentifierFromOrigin(origin),
delete_callback),
delete_callback);
}
Expand Down
6 changes: 3 additions & 3 deletions webkit/browser/database/database_quota_client_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/base/origin_url_conversions.h"
#include "webkit/browser/database/database_quota_client.h"
#include "webkit/browser/database/database_tracker.h"
#include "webkit/browser/database/database_util.h"
#include "webkit/common/database/database_identifier.h"

namespace webkit_database {

Expand All @@ -37,7 +37,7 @@ class MockDatabaseTracker : public DatabaseTracker {
OriginInfo* info) OVERRIDE {
std::map<GURL, MockOriginInfo>::const_iterator found =
mock_origin_infos_.find(
webkit_base::GetOriginURLFromIdentifier(origin_identifier));
webkit_database::GetOriginFromIdentifier(origin_identifier));
if (found == mock_origin_infos_.end())
return false;
*info = OriginInfo(found->second);
Expand Down Expand Up @@ -86,7 +86,7 @@ class MockDatabaseTracker : public DatabaseTracker {

void AddMockDatabase(const GURL& origin, const char* name, int size) {
MockOriginInfo& info = mock_origin_infos_[origin];
info.set_origin(webkit_base::GetOriginIdentifierFromURL(origin));
info.set_origin(webkit_database::GetIdentifierFromOrigin(origin));
info.AddMockDatabase(ASCIIToUTF16(name), size);
}

Expand Down
Loading

0 comments on commit 2a9644c

Please sign in to comment.