summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
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 /chrome/browser/extensions
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 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_service.cc147
-rw-r--r--chrome/browser/extensions/extension_service.h22
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc54
3 files changed, 36 insertions, 187 deletions
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 5a19f48..b3bb620 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/extensions/extension_management_api.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_processes_api.h"
+#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/extensions/extension_web_ui.h"
#include "chrome/browser/extensions/extension_webnavigation_api.h"
@@ -106,35 +107,6 @@ ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) {
return NOT_NEEDED;
}
-void GetExplicitOriginsInExtent(const Extension* extension,
- std::vector<GURL>* origins) {
- typedef std::vector<URLPattern> PatternList;
- std::set<GURL> set;
- const PatternList& patterns = extension->web_extent().patterns();
- for (PatternList::const_iterator pattern = patterns.begin();
- pattern != patterns.end(); ++pattern) {
- if (pattern->match_subdomains() || pattern->match_all_urls())
- continue;
- // Wildcard URL schemes won't parse into a valid GURL, so explicit schemes
- // must be used.
- PatternList explicit_patterns = pattern->ConvertToExplicitSchemes();
- for (PatternList::const_iterator explicit_p = explicit_patterns.begin();
- explicit_p != explicit_patterns.end(); ++explicit_p) {
- GURL origin = GURL(explicit_p->GetAsString()).GetOrigin();
- if (origin.is_valid()) {
- set.insert(origin);
- } else {
- NOTREACHED();
- }
- }
- }
-
- for (std::set<GURL>::const_iterator unique = set.begin();
- unique != set.end(); ++unique) {
- origins->push_back(*unique);
- }
-}
-
} // namespace
PendingExtensionInfo::PendingExtensionInfo(
@@ -1090,15 +1062,8 @@ void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
// extension.
if (profile_) {
profile_->RegisterExtensionWithRequestContexts(extension);
-
- // Check if this permission requires unlimited storage quota
- if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission))
- GrantUnlimitedStorage(extension);
-
- // If the extension is an app, protect its local storage from
- // "Clear browsing data."
- if (extension->is_app())
- GrantProtectedStorage(extension);
+ profile_->GetExtensionSpecialStoragePolicy()->
+ GrantRightsForExtension(extension);
}
NotificationService::current()->Notify(
@@ -1117,106 +1082,8 @@ void ExtensionService::NotifyExtensionUnloaded(
if (profile_) {
profile_->UnregisterExtensionWithRequestContexts(extension);
-
- // Check if this permission required unlimited storage quota, reset its
- // in-memory quota.
- if (extension->HasApiPermission(Extension::kUnlimitedStoragePermission))
- RevokeUnlimitedStorage(extension);
-
- // If this is an app, then stop protecting its storage so it can be deleted.
- if (extension->is_app())
- RevokeProtectedStorage(extension);
- }
-}
-
-void ExtensionService::GrantProtectedStorage(const Extension* extension) {
- DCHECK(extension->is_app()) << "Only Apps are allowed protected storage.";
- std::vector<GURL> origins;
- GetExplicitOriginsInExtent(extension, &origins);
- for (size_t i = 0; i < origins.size(); ++i)
- ++protected_storage_map_[origins[i]];
-}
-
-void ExtensionService::RevokeProtectedStorage(const Extension* extension) {
- DCHECK(extension->is_app()) << "Attempting to revoke protected storage from "
- << " a non-app extension.";
- std::vector<GURL> origins;
- GetExplicitOriginsInExtent(extension, &origins);
- for (size_t i = 0; i < origins.size(); ++i) {
- const GURL& origin = origins[i];
- DCHECK(protected_storage_map_[origin] > 0);
- if (--protected_storage_map_[origin] <= 0)
- protected_storage_map_.erase(origin);
- }
-}
-
-void ExtensionService::GrantUnlimitedStorage(const Extension* extension) {
- DCHECK(extension->HasApiPermission(Extension::kUnlimitedStoragePermission));
- std::vector<GURL> origins;
- GetExplicitOriginsInExtent(extension, &origins);
- origins.push_back(extension->url());
-
- for (size_t i = 0; i < origins.size(); ++i) {
- const GURL& origin = origins[i];
- if (++unlimited_storage_map_[origin] == 1) {
- string16 origin_identifier =
- webkit_database::DatabaseUtil::GetOriginIdentifier(origin);
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- profile_->GetDatabaseTracker(),
- &webkit_database::DatabaseTracker::SetOriginQuotaInMemory,
- origin_identifier,
- kint64max));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- profile_->GetAppCacheService(),
- &ChromeAppCacheService::SetOriginQuotaInMemory,
- origin,
- kint64max));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- profile_->GetFileSystemContext(),
- &fileapi::FileSystemContext::SetOriginQuotaUnlimited,
- origin));
- }
- }
-}
-
-void ExtensionService::RevokeUnlimitedStorage(const Extension* extension) {
- DCHECK(extension->HasApiPermission(Extension::kUnlimitedStoragePermission));
- std::vector<GURL> origins;
- GetExplicitOriginsInExtent(extension, &origins);
- origins.push_back(extension->url());
-
- for (size_t i = 0; i < origins.size(); ++i) {
- const GURL& origin = origins[i];
- DCHECK(unlimited_storage_map_[origin] > 0);
- if (--unlimited_storage_map_[origin] == 0) {
- unlimited_storage_map_.erase(origin);
- string16 origin_identifier =
- webkit_database::DatabaseUtil::GetOriginIdentifier(origin);
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- profile_->GetDatabaseTracker(),
- &webkit_database::DatabaseTracker::ResetOriginQuotaInMemory,
- origin_identifier));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- profile_->GetAppCacheService(),
- &ChromeAppCacheService::ResetOriginQuotaInMemory,
- origin));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(
- profile_->GetFileSystemContext(),
- &fileapi::FileSystemContext::ResetOriginQuotaUnlimited,
- origin));
- }
+ profile_->GetExtensionSpecialStoragePolicy()->
+ RevokeRightsForExtension(extension);
}
}
@@ -1454,6 +1321,10 @@ void ExtensionService::UnloadExtension(
}
void ExtensionService::UnloadAllExtensions() {
+ if (profile_) {
+ profile_->GetExtensionSpecialStoragePolicy()->
+ RevokeRightsForAllExtensions();
+ }
extensions_.clear();
disabled_extensions_.clear();
terminated_extension_ids_.clear();
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 67a59be..402f644 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -408,10 +408,6 @@ class ExtensionService
return browser_event_router_.get();
}
- const std::map<GURL, int>& protected_storage_map() const {
- return protected_storage_map_;
- }
-
// Notify the frontend that there was an error loading an extension.
// This method is public because ExtensionServiceBackend can post to here.
void ReportExtensionLoadError(const FilePath& extension_path,
@@ -516,12 +512,6 @@ class ExtensionService
// Helper method. Loads extension from prefs.
void LoadInstalledExtension(const ExtensionInfo& info, bool write_to_prefs);
- // Helper methods to configure the storage services accordingly.
- void GrantProtectedStorage(const Extension* extension);
- void RevokeProtectedStorage(const Extension* extension);
- void GrantUnlimitedStorage(const Extension* extension);
- void RevokeUnlimitedStorage(const Extension* extension);
-
// The profile this ExtensionService is part of.
Profile* profile_;
@@ -603,18 +593,6 @@ class ExtensionService
typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions;
RegisteredComponentExtensions component_extension_manifests_;
- // Collection of origins we've granted unlimited storage to. This is a
- // map from origin to the number of extensions requiring unlimited
- // storage within that origin.
- typedef std::map<GURL, int> UnlimitedStorageMap;
- UnlimitedStorageMap unlimited_storage_map_;
-
- // Collection of origins whose storage is protected by "Clear browsing data."
- // A map from origin to the number of Apps currently installed and therefore
- // intrinsically protected.
- typedef std::map<GURL, int> ProtectedStorageMap;
- ProtectedStorageMap protected_storage_map_;
-
// Manages the installation of default apps and the promotion of them in the
// app launcher.
DefaultApps default_apps_;
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index c5d35e6..b2b1623 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/extensions/extension_creator.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/external_extension_provider_interface.h"
#include "chrome/browser/extensions/external_extension_provider_impl.h"
#include "chrome/browser/extensions/external_pref_extension_loader.h"
@@ -341,11 +342,13 @@ class ExtensionTestingProfile : public TestingProfile {
appcache_service_ = new ChromeAppCacheService;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(appcache_service_.get(),
- &ChromeAppCacheService::InitializeOnIOThread,
- GetPath(), IsOffTheRecord(),
- make_scoped_refptr(GetHostContentSettingsMap()),
- false));
+ NewRunnableMethod(
+ appcache_service_.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ GetPath(), IsOffTheRecord(),
+ make_scoped_refptr(GetHostContentSettingsMap()),
+ make_scoped_refptr(GetExtensionSpecialStoragePolicy()),
+ false));
}
return appcache_service_;
}
@@ -353,7 +356,7 @@ class ExtensionTestingProfile : public TestingProfile {
virtual fileapi::FileSystemContext* GetFileSystemContext() {
if (!file_system_context_)
file_system_context_ = CreateFileSystemContext(
- GetPath(), IsOffTheRecord());
+ GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy());
return file_system_context_;
}
@@ -1674,13 +1677,11 @@ TEST_F(ExtensionServiceTest, UpdateApps) {
TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
InitializeEmptyExtensionService();
EXPECT_TRUE(service_->extensions()->empty());
- EXPECT_TRUE(service_->unlimited_storage_map_.empty());
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
int pref_count = 0;
- ChromeAppCacheService* appcache_service = profile_->GetAppCacheService();
// Install app1 with unlimited storage.
PackAndInstallExtension(extensions_path.AppendASCII("app1"), true);
@@ -1693,9 +1694,8 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
EXPECT_TRUE(extension->web_extent().ContainsURL(
extension->GetFullLaunchURL()));
const GURL origin1(extension->GetFullLaunchURL().GetOrigin());
- EXPECT_EQ(kint64max,
- appcache_service->storage()->GetOriginQuotaInMemory(origin1));
- EXPECT_FALSE(service_->unlimited_storage_map_.empty());
+ EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageUnlimited(origin1));
// Install app2 from the same origin with unlimited storage.
PackAndInstallExtension(extensions_path.AppendASCII("app2"), true);
@@ -1709,32 +1709,30 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimtedStorage) {
extension->GetFullLaunchURL()));
const GURL origin2(extension->GetFullLaunchURL().GetOrigin());
EXPECT_EQ(origin1, origin2);
- EXPECT_EQ(kint64max,
- appcache_service->storage()->GetOriginQuotaInMemory(origin2));
- EXPECT_FALSE(service_->unlimited_storage_map_.empty());
+ EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageUnlimited(origin2));
+
// Uninstall one of them, unlimited storage should still be granted
// to the origin.
service_->UninstallExtension(id1, false);
loop_.RunAllPending();
EXPECT_EQ(1u, service_->extensions()->size());
- EXPECT_EQ(kint64max,
- appcache_service->storage()->GetOriginQuotaInMemory(origin1));
- EXPECT_FALSE(service_->unlimited_storage_map_.empty());
+ EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageUnlimited(origin1));
+
// Uninstall the other, unlimited storage should be revoked.
service_->UninstallExtension(id2, false);
loop_.RunAllPending();
EXPECT_EQ(0u, service_->extensions()->size());
- EXPECT_EQ(-1L,
- appcache_service->storage()->GetOriginQuotaInMemory(origin2));
- EXPECT_TRUE(service_->unlimited_storage_map_.empty());
+ EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageUnlimited(origin2));
}
TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
InitializeEmptyExtensionService();
EXPECT_TRUE(service_->extensions()->empty());
- EXPECT_TRUE(service_->protected_storage_map_.empty());
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
@@ -1747,9 +1745,9 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
const Extension* extension = service_->extensions()->at(0);
EXPECT_TRUE(extension->is_app());
const std::string id1 = extension->id();
- EXPECT_FALSE(service_->protected_storage_map_.empty());
const GURL origin1(extension->GetFullLaunchURL().GetOrigin());
- ASSERT_EQ(1, service_->protected_storage_map_[origin1]);
+ EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageProtected(origin1));
// App 4 has a different origin (maps.google.com).
PackAndInstallExtension(extensions_path.AppendASCII("app4"), true);
@@ -1757,21 +1755,23 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
ASSERT_EQ(2u, service_->extensions()->size());
extension = service_->extensions()->at(1);
const std::string id2 = extension->id();
- EXPECT_FALSE(service_->protected_storage_map_.empty());
const GURL origin2(extension->GetFullLaunchURL().GetOrigin());
ASSERT_NE(origin1, origin2);
- ASSERT_EQ(1, service_->protected_storage_map_[origin2]);
+ EXPECT_TRUE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageProtected(origin2));
service_->UninstallExtension(id1, false);
loop_.RunAllPending();
EXPECT_EQ(1u, service_->extensions()->size());
- EXPECT_FALSE(service_->protected_storage_map_.empty());
service_->UninstallExtension(id2, false);
loop_.RunAllPending();
EXPECT_TRUE(service_->extensions()->empty());
- EXPECT_TRUE(service_->protected_storage_map_.empty());
+ EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageProtected(origin1));
+ EXPECT_FALSE(profile_->GetExtensionSpecialStoragePolicy()->
+ IsStorageProtected(origin2));
}
// Test that when an extension version is reinstalled, nothing happens.