summaryrefslogtreecommitdiffstats
path: root/webkit/database
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-27 01:22:44 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-27 01:22:44 +0000
commit24b538ac49c0283fe6475f00aaab5bdc76b9f11c (patch)
treef1ff81c7810283b35660f223f2a2b91785468fd9 /webkit/database
parent5cce744c391924ef39aca8c2f9b27e377a69b464 (diff)
downloadchromium_src-24b538ac49c0283fe6475f00aaab5bdc76b9f11c.zip
chromium_src-24b538ac49c0283fe6475f00aaab5bdc76b9f11c.tar.gz
chromium_src-24b538ac49c0283fe6475f00aaab5bdc76b9f11c.tar.bz2
Reset the default quota limit for extensions to 5MB, but add a
unlimited_quota permission that extensions can use to request unlimited quota. TEST=ExtensionsServiceTest.StorageQuota BUG=27688 Review URL: http://codereview.chromium.org/660113 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database')
-rw-r--r--webkit/database/database_tracker.cc33
-rw-r--r--webkit/database/database_tracker.h7
-rw-r--r--webkit/database/database_util.cc7
-rw-r--r--webkit/database/database_util.h3
4 files changed, 39 insertions, 11 deletions
diff --git a/webkit/database/database_tracker.cc b/webkit/database/database_tracker.cc
index 6068836d..b407830 100644
--- a/webkit/database/database_tracker.cc
+++ b/webkit/database/database_tracker.cc
@@ -17,7 +17,6 @@
#include "net/base/net_errors.h"
#include "webkit/database/databases_table.h"
#include "webkit/database/quota_table.h"
-#include "webkit/glue/webkit_glue.h"
namespace webkit_database {
@@ -27,7 +26,6 @@ const FilePath::CharType kTrackerDatabaseFileName[] =
FILE_PATH_LITERAL("Databases.db");
const int kCurrentVersion = 2;
const int kCompatibleVersion = 1;
-const int64 kDefaultExtensionQuota = 1024 * 1024 * 1024;
const char* kExtensionOriginIdentifierPrefix = "chrome-extension_";
DatabaseTracker::DatabaseTracker(const FilePath& profile_path)
@@ -158,6 +156,7 @@ FilePath DatabaseTracker::GetFullDBFilePath(
const string16& database_name) const {
DCHECK(!origin_identifier.empty());
DCHECK(!database_name.empty());
+
int64 id = databases_table_->GetDatabaseID(
origin_identifier, database_name);
if (id < 0)
@@ -194,14 +193,26 @@ bool DatabaseTracker::GetAllOriginsInfo(std::vector<OriginInfo>* origins_info) {
void DatabaseTracker::SetOriginQuota(const string16& origin_identifier,
int64 new_quota) {
+ if (!LazyInit())
+ return;
+
if (quota_table_->SetOriginQuota(origin_identifier, new_quota) &&
(origins_info_map_.find(origin_identifier) != origins_info_map_.end())) {
origins_info_map_[origin_identifier].SetQuota(new_quota);
}
}
+void DatabaseTracker::SetOriginQuotaInMemory(const string16& origin_identifier,
+ int64 new_quota) {
+ DCHECK(new_quota >= 0);
+ in_memory_quotas_[origin_identifier] = new_quota;
+}
+
bool DatabaseTracker::DeleteClosedDatabase(const string16& origin_identifier,
const string16& database_name) {
+ if (!LazyInit())
+ return false;
+
// Check if the database is opened by any renderer.
if (database_connections_.IsDatabaseOpened(origin_identifier, database_name))
return false;
@@ -225,6 +236,9 @@ bool DatabaseTracker::DeleteClosedDatabase(const string16& origin_identifier,
}
bool DatabaseTracker::DeleteOrigin(const string16& origin_identifier) {
+ if (!LazyInit())
+ return false;
+
// Check if any database in this origin is opened by any renderer.
if (database_connections_.IsOriginUsed(origin_identifier))
return false;
@@ -354,15 +368,14 @@ DatabaseTracker::CachedOriginInfo* DatabaseTracker::GetCachedOriginInfo(
origin_info.SetDatabaseDescription(it->database_name, it->description);
}
- int64 origin_quota = quota_table_->GetOriginQuota(origin_identifier);
- if (origin_quota > 0) {
- origin_info.SetQuota(origin_quota);
- } else if (StartsWith(origin_identifier,
- ASCIIToUTF16(kExtensionOriginIdentifierPrefix),
- true)) {
- origin_info.SetQuota(kDefaultExtensionQuota);
+ if (in_memory_quotas_.find(origin_identifier) != in_memory_quotas_.end()) {
+ origin_info.SetQuota(in_memory_quotas_[origin_identifier]);
} else {
- origin_info.SetQuota(default_quota_);
+ int64 origin_quota = quota_table_->GetOriginQuota(origin_identifier);
+ if (origin_quota > 0)
+ origin_info.SetQuota(origin_quota);
+ else
+ origin_info.SetQuota(default_quota_);
}
}
diff --git a/webkit/database/database_tracker.h b/webkit/database/database_tracker.h
index 785cd98..90c9ebc 100644
--- a/webkit/database/database_tracker.h
+++ b/webkit/database/database_tracker.h
@@ -124,7 +124,10 @@ 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);
+ int64 GetDefaultQuota() { return default_quota_; }
// Sets the default quota for all origins. Should be used in tests only.
void SetDefaultQuota(int64 quota);
@@ -216,6 +219,10 @@ 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_;
+
FRIEND_TEST(DatabaseTrackerTest, TestIt);
};
diff --git a/webkit/database/database_util.cc b/webkit/database/database_util.cc
index 4866b30..bf5b901 100644
--- a/webkit/database/database_util.cc
+++ b/webkit/database/database_util.cc
@@ -5,6 +5,8 @@
#include "webkit/database/database_util.h"
#include "base/string_util.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "webkit/database/database_tracker.h"
#include "webkit/database/vfs_backend.h"
@@ -64,4 +66,9 @@ FilePath DatabaseUtil::GetFullFilePathForVfsFile(
return full_path;
}
+string16 DatabaseUtil::GetOriginIdentifier(const GURL& url) {
+ string16 spec = UTF8ToUTF16(url.spec());
+ return WebKit::WebSecurityOrigin::createFromString(spec).databaseIdentifier();
+}
+
} // namespace webkit_database
diff --git a/webkit/database/database_util.h b/webkit/database/database_util.h
index 2aa35b3..ec5c1c2b 100644
--- a/webkit/database/database_util.h
+++ b/webkit/database/database_util.h
@@ -7,6 +7,7 @@
#include "base/file_path.h"
#include "base/string16.h"
+#include "googleurl/src/gurl.h"
namespace webkit_database {
@@ -22,7 +23,7 @@ class DatabaseUtil {
string16* sqlite_suffix);
static FilePath GetFullFilePathForVfsFile(DatabaseTracker* db_tracker,
const string16& vfs_file_name);
-
+ static string16 GetOriginIdentifier(const GURL& url);
};
} // namespace webkit_database