summaryrefslogtreecommitdiffstats
path: root/webkit/database
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-26 00:28:43 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-26 00:28:43 +0000
commit19eb8015c483fff874bf1eddb80bd26cf4167f33 (patch)
treebe896411dde17d24eb8dbcd67e7b4c5cad2ef1b6 /webkit/database
parentf02074331bddc7d89b20e6b3a8fb934e6891207c (diff)
downloadchromium_src-19eb8015c483fff874bf1eddb80bd26cf4167f33.zip
chromium_src-19eb8015c483fff874bf1eddb80bd26cf4167f33.tar.gz
chromium_src-19eb8015c483fff874bf1eddb80bd26cf4167f33.tar.bz2
Add an accessor for an ExtensionSpecialStoragePolicy to the Profile class
and use it in the extension service, data remover, and storage subsystems. BUG=52357 TEST=extension_service_unittest.cc Review URL: http://codereview.chromium.org/6551028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database')
-rw-r--r--webkit/database/database_tracker.cc46
-rw-r--r--webkit/database/database_tracker.h19
-rw-r--r--webkit/database/database_tracker_unittest.cc38
-rw-r--r--webkit/database/database_util.cc7
-rw-r--r--webkit/database/database_util.h1
5 files changed, 68 insertions, 43 deletions
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc
index 46e9dc1..20f5971 100644
--- a/webkit/database/database_tracker.cc
+++ b/webkit/database/database_tracker.cc
@@ -17,8 +17,10 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "net/base/net_errors.h"
+#include "webkit/database/database_util.h"
#include "webkit/database/databases_table.h"
#include "webkit/database/quota_table.h"
+#include "webkit/quota/special_storage_policy.h"
namespace {
@@ -78,8 +80,10 @@ string16 OriginInfo::GetDatabaseDescription(
OriginInfo::OriginInfo(const string16& origin, int64 total_size, int64 quota)
: origin_(origin), total_size_(total_size), quota_(quota) {}
-DatabaseTracker::DatabaseTracker(const FilePath& profile_path,
- bool is_incognito)
+DatabaseTracker::DatabaseTracker(
+ const FilePath& profile_path,
+ bool is_incognito,
+ quota::SpecialStoragePolicy* special_storage_policy)
: is_initialized_(false),
is_incognito_(is_incognito),
shutting_down_(false),
@@ -91,6 +95,7 @@ DatabaseTracker::DatabaseTracker(const FilePath& profile_path,
databases_table_(NULL),
meta_table_(NULL),
default_quota_(5 * 1024 * 1024),
+ special_storage_policy_(special_storage_policy),
incognito_origin_directories_generator_(0) {
}
@@ -289,16 +294,6 @@ void DatabaseTracker::SetOriginQuota(const string16& origin_identifier,
}
}
-void DatabaseTracker::SetOriginQuotaInMemory(const string16& origin_identifier,
- int64 new_quota) {
- DCHECK(new_quota >= 0);
- in_memory_quotas_[origin_identifier] = new_quota;
-}
-
-void DatabaseTracker::ResetOriginQuotaInMemory(
- const string16& origin_identifier) {
- in_memory_quotas_.erase(origin_identifier);
-}
bool DatabaseTracker::DeleteClosedDatabase(const string16& origin_identifier,
const string16& database_name) {
@@ -464,8 +459,12 @@ DatabaseTracker::CachedOriginInfo* DatabaseTracker::GetCachedOriginInfo(
origin_info.SetDatabaseDescription(it->database_name, it->description);
}
- if (in_memory_quotas_.find(origin_identifier) != in_memory_quotas_.end()) {
- origin_info.SetQuota(in_memory_quotas_[origin_identifier]);
+ if (special_storage_policy_.get() &&
+ special_storage_policy_->IsStorageUnlimited(
+ DatabaseUtil::GetOriginFromIdentifier(origin_identifier))) {
+ // TODO(michaeln): handle the case where it changes status sometime after
+ // the cached origin_info has been established
+ origin_info.SetQuota(kint64max);
} else {
int64 origin_quota = quota_table_->GetOriginQuota(origin_identifier);
if (origin_quota > 0)
@@ -554,7 +553,6 @@ int DatabaseTracker::DeleteDatabase(const string16& origin_identifier,
int DatabaseTracker::DeleteDataModifiedSince(
const base::Time& cutoff,
- const std::vector<string16>& protected_origins,
net::CompletionCallback* callback) {
if (!LazyInit())
return net::ERR_FAILED;
@@ -563,19 +561,17 @@ int DatabaseTracker::DeleteDataModifiedSince(
deletion_callbacks_.find(callback) == deletion_callbacks_.end());
DatabaseSet to_be_deleted;
- std::vector<string16> origins;
- if (!databases_table_->GetAllOrigins(&origins))
+ std::vector<string16> origins_identifiers;
+ if (!databases_table_->GetAllOrigins(&origins_identifiers))
return net::ERR_FAILED;
int rv = net::OK;
- for (std::vector<string16>::const_iterator ori = origins.begin();
- ori != origins.end(); ++ori) {
- if (StartsWith(*ori, ASCIIToUTF16(kExtensionOriginIdentifierPrefix), true))
- continue;
-
- std::vector<string16>::const_iterator find_iter =
- std::find(protected_origins.begin(), protected_origins.end(), *ori);
- if (find_iter != protected_origins.end())
+ for (std::vector<string16>::const_iterator ori = origins_identifiers.begin();
+ ori != origins_identifiers.end(); ++ori) {
+ if (special_storage_policy_.get() &&
+ special_storage_policy_->IsStorageProtected(
+ DatabaseUtil::GetOriginFromIdentifier(*ori))) {
continue;
+ }
std::vector<DatabaseDetails> details;
if (!databases_table_->GetAllDatabaseDetailsForOrigin(*ori, &details))
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h
index 08a66b2..140753e 100644
--- a/webkit/database/database_tracker.h
+++ b/webkit/database/database_tracker.h
@@ -25,6 +25,10 @@ class Connection;
class MetaTable;
}
+namespace quota {
+class SpecialStoragePolicy;
+}
+
namespace webkit_database {
extern const FilePath::CharType kDatabaseDirectoryName[];
@@ -83,7 +87,8 @@ class DatabaseTracker
virtual ~Observer() {}
};
- DatabaseTracker(const FilePath& profile_path, bool is_incognito);
+ DatabaseTracker(const FilePath& profile_path, bool is_incognito,
+ quota::SpecialStoragePolicy* special_storage_policy);
void DatabaseOpened(const string16& origin_identifier,
const string16& database_name,
@@ -108,9 +113,6 @@ class DatabaseTracker
bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info);
void SetOriginQuota(const string16& origin_identifier, int64 new_quota);
- void SetOriginQuotaInMemory(const string16& origin_identifier,
- int64 new_quota);
- void ResetOriginQuotaInMemory(const string16& origin_identifier);
int64 GetDefaultQuota() { return default_quota_; }
// Sets the default quota for all origins. Should be used in tests only.
@@ -130,9 +132,9 @@ class DatabaseTracker
// supplied, omitting any that match IDs within |protected_origins|.
// Returns net::OK on success, net::FAILED if not all databases could be
// deleted, and net::ERR_IO_PENDING and |callback| is invoked upon completion,
- // if non-NULL.
+ // if non-NULL. Protected origins, according the the SpecialStoragePolicy,
+ // are not deleted by this method.
int DeleteDataModifiedSince(const base::Time& cutoff,
- const std::vector<string16>& protected_origins,
net::CompletionCallback* callback);
// Delete all databases that belong to the given origin. Returns net::OK on
@@ -238,9 +240,8 @@ class DatabaseTracker
// Default quota for all origins; changed only by tests
int64 default_quota_;
- // Store quotas for extensions in memory, in order to prevent writing a row
- // to quota_table_ every time an extention is loaded.
- std::map<string16, int64> in_memory_quotas_;
+ // Apps and Extensions can have special rights.
+ scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
// When in incognito mode, store a DELETE_ON_CLOSE handle to each
// main DB and journal file that was accessed. When the incognito profile
diff --git a/webkit/database/database_tracker_unittest.cc b/webkit/database/database_tracker_unittest.cc
index 641c207..a8d2928 100644
--- a/webkit/database/database_tracker_unittest.cc
+++ b/webkit/database/database_tracker_unittest.cc
@@ -12,9 +12,25 @@
#include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/database/database_tracker.h"
+#include "webkit/database/database_util.h"
+#include "webkit/quota/special_storage_policy.h"
namespace {
+const char kOrigin1Url[] = "http://origin1";
+const char kOrigin2Url[] = "http://protected_origin2";
+
+class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
+ public:
+ virtual bool IsStorageProtected(const GURL& origin) {
+ return origin == GURL(kOrigin2Url);
+ }
+
+ virtual bool IsStorageUnlimited(const GURL& origin) {
+ return false;
+ }
+};
+
class TestObserver : public webkit_database::DatabaseTracker::Observer {
public:
TestObserver() : new_notification_received_(false) {}
@@ -85,13 +101,16 @@ class DatabaseTracker_TestHelper_Test {
ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
scoped_refptr<DatabaseTracker> tracker(
- new DatabaseTracker(temp_dir.path(), incognito_mode));
+ new DatabaseTracker(temp_dir.path(), incognito_mode,
+ new TestSpecialStoragePolicy));
// Create and open three databases.
int64 database_size = 0;
int64 space_available = 0;
- const string16 kOrigin1 = ASCIIToUTF16("origin1");
- const string16 kOrigin2 = ASCIIToUTF16("origin2");
+ const string16 kOrigin1 =
+ DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
+ const string16 kOrigin2 =
+ DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
const string16 kDB1 = ASCIIToUTF16("db1");
const string16 kDB2 = ASCIIToUTF16("db2");
const string16 kDB3 = ASCIIToUTF16("db3");
@@ -160,10 +179,8 @@ class DatabaseTracker_TestHelper_Test {
// Delete databases modified since yesterday. db2 is whitelisted.
base::Time yesterday = base::Time::Now();
yesterday -= base::TimeDelta::FromDays(1);
- std::vector<string16> protected_origins;
- protected_origins.push_back(kOrigin2);
result = tracker->DeleteDataModifiedSince(
- yesterday, protected_origins, &callback);
+ yesterday, &callback);
EXPECT_EQ(net::ERR_IO_PENDING, result);
ASSERT_FALSE(callback.have_result());
EXPECT_TRUE(observer.DidReceiveNewNotification());
@@ -187,7 +204,8 @@ class DatabaseTracker_TestHelper_Test {
ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
scoped_refptr<DatabaseTracker> tracker(
- new DatabaseTracker(temp_dir.path(), incognito_mode));
+ new DatabaseTracker(temp_dir.path(), incognito_mode,
+ new TestSpecialStoragePolicy));
// Add two observers.
TestObserver observer1;
@@ -198,8 +216,10 @@ class DatabaseTracker_TestHelper_Test {
// Open three new databases.
int64 database_size = 0;
int64 space_available = 0;
- const string16 kOrigin1 = ASCIIToUTF16("origin1");
- const string16 kOrigin2 = ASCIIToUTF16("origin2");
+ const string16 kOrigin1 =
+ DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
+ const string16 kOrigin2 =
+ DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
const string16 kDB1 = ASCIIToUTF16("db1");
const string16 kDB2 = ASCIIToUTF16("db2");
const string16 kDB3 = ASCIIToUTF16("db3");
diff --git a/webkit/database/database_util.cc b/webkit/database/database_util.cc
index 8002d81..2886095 100644
--- a/webkit/database/database_util.cc
+++ b/webkit/database/database_util.cc
@@ -71,4 +71,11 @@ string16 DatabaseUtil::GetOriginIdentifier(const GURL& url) {
return WebKit::WebSecurityOrigin::createFromString(spec).databaseIdentifier();
}
+GURL DatabaseUtil::GetOriginFromIdentifier(const string16& origin_identifier) {
+ GURL origin(WebKit::WebSecurityOrigin::createFromDatabaseIdentifier(
+ origin_identifier).toString());
+ DCHECK(origin == origin.GetOrigin());
+ return origin;
+}
+
} // namespace webkit_database
diff --git a/webkit/database/database_util.h b/webkit/database/database_util.h
index cecea79..20410dc 100644
--- a/webkit/database/database_util.h
+++ b/webkit/database/database_util.h
@@ -25,6 +25,7 @@ class DatabaseUtil {
static FilePath GetFullFilePathForVfsFile(DatabaseTracker* db_tracker,
const string16& vfs_file_name);
static string16 GetOriginIdentifier(const GURL& url);
+ static GURL GetOriginFromIdentifier(const string16& origin_identifier);
};
} // namespace webkit_database