summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/extensions/extensions_service.cc17
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc51
-rw-r--r--chrome/common/extensions/extension.cc4
-rw-r--r--chrome/common/extensions/extension.h1
-rw-r--r--chrome/test/data/extensions/storage_quota/limited_quota/1.0/manifest.json5
-rw-r--r--chrome/test/data/extensions/storage_quota/unlimited_quota/1.0/manifest.json6
-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
10 files changed, 122 insertions, 12 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 9cf2fb9..0a5f145 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -4,9 +4,11 @@
#include "chrome/browser/extensions/extensions_service.h"
+#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/histogram.h"
+#include "base/string16.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/values.h"
@@ -38,6 +40,8 @@
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "webkit/database/database_tracker.h"
+#include "webkit/database/database_util.h"
#if defined(OS_WIN)
#include "chrome/browser/extensions/external_registry_extension_provider_win.h"
@@ -462,6 +466,19 @@ void ExtensionsService::NotifyExtensionLoaded(Extension* extension) {
extension->app_extent(),
extension->api_permissions())));
}
+
+ // Check if this permission requires unlimited storage quota
+ if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission)) {
+ string16 origin_identifier =
+ webkit_database::DatabaseUtil::GetOriginIdentifier(extension->url());
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ NewRunnableMethod(
+ profile_->GetDatabaseTracker(),
+ &webkit_database::DatabaseTracker::SetOriginQuotaInMemory,
+ origin_identifier,
+ kint64max));
+ }
}
NotificationService::current()->Notify(
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 1b29541..b2ea08a 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -7,12 +7,15 @@
#include <algorithm>
#include <vector>
+#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/json/json_reader.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "base/string16.h"
#include "base/string_util.h"
+#include "base/task.h"
#include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_creator.h"
#include "chrome/browser/extensions/extensions_service.h"
@@ -29,9 +32,13 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/url_constants.h"
#include "chrome/test/testing_profile.h"
+#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
+#include "webkit/database/database_tracker.h"
+#include "webkit/database/database_util.h"
namespace keys = extension_manifest_keys;
@@ -1633,3 +1640,47 @@ TEST(ExtensionsServiceTestSimple, Enabledness) {
loop.RunAllPending();
EXPECT_TRUE(recorder.ready());
}
+
+// Test loading extensions that require limited and unlimited storage quotas.
+TEST_F(ExtensionsServiceTest, StorageQuota) {
+ InitializeEmptyExtensionsService();
+
+ FilePath extensions_path;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
+ extensions_path = extensions_path.AppendASCII("extensions")
+ .AppendASCII("storage_quota");
+
+ FilePath limited_quota_ext = extensions_path.AppendASCII("limited_quota")
+ .AppendASCII("1.0");
+ FilePath unlimited_quota_ext = extensions_path.AppendASCII("unlimited_quota")
+ .AppendASCII("1.0");
+ service_->LoadExtension(limited_quota_ext);
+ service_->LoadExtension(unlimited_quota_ext);
+ loop_.RunAllPending();
+
+ EXPECT_EQ(2u, loaded_.size());
+ EXPECT_TRUE(profile_.get());
+ EXPECT_FALSE(profile_->IsOffTheRecord());
+
+ // Open a database in each origin to make the tracker aware
+ // of the existance of these origins and to get their quotas.
+ int64 limited_quota = -1;
+ int64 unlimited_quota = -1;
+ string16 limited_quota_identifier =
+ webkit_database::DatabaseUtil::GetOriginIdentifier(loaded_[0]->url());
+ string16 unlimited_quota_identifier =
+ webkit_database::DatabaseUtil::GetOriginIdentifier(loaded_[1]->url());
+ string16 db_name = UTF8ToUTF16("db");
+ string16 description = UTF8ToUTF16("db_description");
+ int64 database_size;
+ webkit_database::DatabaseTracker* db_tracker = profile_->GetDatabaseTracker();
+ db_tracker->DatabaseOpened(limited_quota_identifier, db_name, description,
+ 1, &database_size, &limited_quota);
+ db_tracker->DatabaseClosed(limited_quota_identifier, db_name);
+ db_tracker->DatabaseOpened(unlimited_quota_identifier, db_name, description,
+ 1, &database_size, &unlimited_quota);
+ db_tracker->DatabaseClosed(unlimited_quota_identifier, db_name);
+
+ EXPECT_EQ(profile_->GetDatabaseTracker()->GetDefaultQuota(), limited_quota);
+ EXPECT_EQ(kint64max, unlimited_quota);
+}
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 99a9dfe..39929f7 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -118,13 +118,15 @@ const char* Extension::kBookmarkPermission = "bookmarks";
const char* Extension::kNotificationPermission = "notifications";
const char* Extension::kExperimentalPermission = "experimental";
const char* Extension::kIncognitoPermission = "incognito";
+const char* Extension::kUnlimitedStoragePermission = "unlimited_storage";
const char* Extension::kPermissionNames[] = {
Extension::kTabPermission,
Extension::kBookmarkPermission,
Extension::kNotificationPermission,
Extension::kExperimentalPermission,
- Extension::kIncognitoPermission
+ Extension::kIncognitoPermission,
+ Extension::kUnlimitedStoragePermission
};
const size_t Extension::kNumPermissions =
arraysize(Extension::kPermissionNames);
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 880131d..88d093f 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -80,6 +80,7 @@ class Extension {
static const char* kNotificationPermission;
static const char* kExperimentalPermission;
static const char* kIncognitoPermission;
+ static const char* kUnlimitedStoragePermission;
static const char* kPermissionNames[];
static const size_t kNumPermissions;
diff --git a/chrome/test/data/extensions/storage_quota/limited_quota/1.0/manifest.json b/chrome/test/data/extensions/storage_quota/limited_quota/1.0/manifest.json
new file mode 100644
index 0000000..a3ce5eb
--- /dev/null
+++ b/chrome/test/data/extensions/storage_quota/limited_quota/1.0/manifest.json
@@ -0,0 +1,5 @@
+{
+ "name": "Storage_LimitedQuota",
+ "version": "1.0",
+ "description": "An extension that does not ask for unlimited storage space."
+}
diff --git a/chrome/test/data/extensions/storage_quota/unlimited_quota/1.0/manifest.json b/chrome/test/data/extensions/storage_quota/unlimited_quota/1.0/manifest.json
new file mode 100644
index 0000000..e40b38f
--- /dev/null
+++ b/chrome/test/data/extensions/storage_quota/unlimited_quota/1.0/manifest.json
@@ -0,0 +1,6 @@
+{
+ "name": "Storage_UnlimitedQuota",
+ "version": "1.0",
+ "description": "An extension that asks for unlimited storage space.",
+ "permissions": ["unlimited_storage"]
+}
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