summaryrefslogtreecommitdiffstats
path: root/chrome
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
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')
-rw-r--r--chrome/browser/browsing_data_remover.cc67
-rw-r--r--chrome/browser/browsing_data_remover.h17
-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
-rw-r--r--chrome/browser/profiles/profile.cc38
-rw-r--r--chrome/browser/profiles/profile.h5
-rw-r--r--chrome/browser/profiles/profile_impl.cc24
-rw-r--r--chrome/browser/profiles/profile_impl.h3
-rw-r--r--chrome/test/testing_profile.cc14
-rw-r--r--chrome/test/testing_profile.h5
11 files changed, 129 insertions, 267 deletions
diff --git a/chrome/browser/browsing_data_remover.cc b/chrome/browser/browsing_data_remover.cc
index 6361e30..f926126 100644
--- a/chrome/browser/browsing_data_remover.cc
+++ b/chrome/browser/browsing_data_remover.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/metrics/user_metrics.h"
@@ -49,6 +50,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
base::Time delete_begin,
base::Time delete_end)
: profile_(profile),
+ special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
delete_begin_(delete_begin),
delete_end_(delete_end),
ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_(
@@ -76,6 +78,7 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile,
TimePeriod time_period,
base::Time delete_end)
: profile_(profile),
+ special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()),
delete_begin_(CalculateBeginDeleteTime(time_period)),
delete_end_(delete_end),
ALLOW_THIS_IN_INITIALIZER_LIST(database_cleared_callback_(
@@ -108,25 +111,6 @@ void BrowsingDataRemover::Remove(int remove_mask) {
DCHECK(!removing_);
removing_ = true;
- std::vector<GURL> origin_whitelist;
- ExtensionService* extensions_service = profile_->GetExtensionService();
- if (extensions_service && extensions_service->HasInstalledExtensions()) {
- std::map<GURL, int> whitelist_map =
- extensions_service->protected_storage_map();
- for (std::map<GURL, int>::const_iterator iter = whitelist_map.begin();
- iter != whitelist_map.end(); ++iter) {
- origin_whitelist.push_back(iter->first);
- }
- }
-
- std::vector<string16> webkit_db_whitelist;
- for (size_t i = 0; i < origin_whitelist.size(); ++i) {
- webkit_db_whitelist.push_back(
- webkit_database::DatabaseUtil::GetOriginIdentifier(
- origin_whitelist[i]));
- }
-
-
if (remove_mask & REMOVE_HISTORY) {
HistoryService* history_service =
profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
@@ -194,8 +178,9 @@ void BrowsingDataRemover::Remove(int remove_mask) {
// REMOVE_COOKIES is actually "cookies and other site data" so we make sure
// to remove other data such local databases, STS state, etc.
- profile_->GetWebKitContext()->DeleteDataModifiedSince(
- delete_begin_, chrome::kExtensionScheme, webkit_db_whitelist);
+ // We assume the end time is now.
+
+ profile_->GetWebKitContext()->DeleteDataModifiedSince(delete_begin_);
database_tracker_ = profile_->GetDatabaseTracker();
if (database_tracker_.get()) {
@@ -204,26 +189,24 @@ void BrowsingDataRemover::Remove(int remove_mask) {
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
this,
- &BrowsingDataRemover::ClearDatabasesOnFILEThread,
- delete_begin_,
- webkit_db_whitelist));
+ &BrowsingDataRemover::ClearDatabasesOnFILEThread));
}
+ waiting_for_clear_appcache_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- profile_->GetTransportSecurityState(),
- &net::TransportSecurityState::DeleteSince,
- delete_begin_));
+ this,
+ &BrowsingDataRemover::ClearAppCacheOnIOThread));
+
+ // TODO(michaeln): delete temporary file system data too
- waiting_for_clear_appcache_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
NewRunnableMethod(
- this,
- &BrowsingDataRemover::ClearAppCacheOnIOThread,
- delete_begin_, // we assume end time == now
- origin_whitelist));
+ profile_->GetTransportSecurityState(),
+ &net::TransportSecurityState::DeleteSince,
+ delete_begin_));
}
if (remove_mask & REMOVE_PASSWORDS) {
@@ -464,13 +447,11 @@ void BrowsingDataRemover::OnClearedDatabases(int rv) {
NotifyAndDeleteIfDone();
}
-void BrowsingDataRemover::ClearDatabasesOnFILEThread(base::Time delete_begin,
- const std::vector<string16>& webkit_db_whitelist) {
+void BrowsingDataRemover::ClearDatabasesOnFILEThread() {
// This function should be called on the FILE thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
int rv = database_tracker_->DeleteDataModifiedSince(
- delete_begin, webkit_db_whitelist, &database_cleared_callback_);
+ delete_begin_, &database_cleared_callback_);
if (rv != net::ERR_IO_PENDING)
OnClearedDatabases(rv);
}
@@ -483,17 +464,13 @@ void BrowsingDataRemover::OnClearedAppCache() {
DCHECK(result);
return;
}
- appcache_whitelist_.clear();
waiting_for_clear_appcache_ = false;
NotifyAndDeleteIfDone();
}
-void BrowsingDataRemover::ClearAppCacheOnIOThread(base::Time delete_begin,
- const std::vector<GURL>& origin_whitelist) {
+void BrowsingDataRemover::ClearAppCacheOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(waiting_for_clear_appcache_);
-
- appcache_whitelist_ = origin_whitelist;
appcache_info_ = new appcache::AppCacheInfoCollection;
GetAppCacheService()->GetAllAppCacheInfo(
appcache_info_, &appcache_got_info_callback_);
@@ -507,14 +484,8 @@ void BrowsingDataRemover::OnGotAppCacheInfo(int rv) {
for (InfoByOrigin::const_iterator origin =
appcache_info_->infos_by_origin.begin();
origin != appcache_info_->infos_by_origin.end(); ++origin) {
- bool found_in_whitelist = false;
- for (size_t i = 0; i < appcache_whitelist_.size(); ++i) {
- if (appcache_whitelist_[i] == origin->first)
- found_in_whitelist = true;
- }
- if (found_in_whitelist)
+ if (special_storage_policy_->IsStorageProtected(origin->first))
continue;
-
for (AppCacheInfoVector::const_iterator info = origin->second.begin();
info != origin->second.end(); ++info) {
if (info->creation_time > delete_begin_) {
diff --git a/chrome/browser/browsing_data_remover.h b/chrome/browser/browsing_data_remover.h
index f9667ca..56d19dd7 100644
--- a/chrome/browser/browsing_data_remover.h
+++ b/chrome/browser/browsing_data_remover.h
@@ -16,6 +16,7 @@
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/cancelable_request.h"
+class ExtensionSpecialStoragePolicy;
class IOThread;
class PluginDataRemover;
class Profile;
@@ -138,19 +139,15 @@ class BrowsingDataRemover : public NotificationObserver,
// NotifyAndDeleteIfDone.
void OnClearedDatabases(int rv);
- // Invoked on the FILE thread to delete HTML5 databases. Ignores any within
- // the |webkit_db_whitelist|.
- void ClearDatabasesOnFILEThread(base::Time delete_begin,
- const std::vector<string16>& webkit_db_whitelist);
+ // Invoked on the FILE thread to delete HTML5 databases.
+ void ClearDatabasesOnFILEThread();
// Callback when the appcache has been cleared. Invokes
// NotifyAndDeleteIfDone.
void OnClearedAppCache();
- // Invoked on the IO thread to delete from the AppCache, ignoring data from
- // any origins within the |origin_whitelist|.
- void ClearAppCacheOnIOThread(base::Time delete_begin,
- const std::vector<GURL>& origin_whitelist);
+ // Invoked on the IO thread to delete from the AppCache.
+ void ClearAppCacheOnIOThread();
// Lower level helpers.
void OnGotAppCacheInfo(int rv);
@@ -174,6 +171,9 @@ class BrowsingDataRemover : public NotificationObserver,
// Profile we're to remove from.
Profile* profile_;
+ // 'Protected' origins are not subject to data removal.
+ scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
+
// Start time to delete from.
const base::Time delete_begin_;
@@ -193,7 +193,6 @@ class BrowsingDataRemover : public NotificationObserver,
net::CompletionCallbackImpl<BrowsingDataRemover> appcache_got_info_callback_;
net::CompletionCallbackImpl<BrowsingDataRemover> appcache_deleted_callback_;
scoped_refptr<appcache::AppCacheInfoCollection> appcache_info_;
- std::vector<GURL> appcache_whitelist_;
int appcaches_to_be_deleted_count_;
// Used to delete data from the HTTP caches.
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.
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index db1579b..3d202cd 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extension_pref_store.h"
#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/net/pref_proxy_config_service.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -157,9 +158,7 @@ class OffTheRecordProfileImpl : public Profile,
: profile_(real_profile),
prefs_(real_profile->GetOffTheRecordPrefs()),
ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)),
- start_time_(Time::Now()),
- db_tracker_(new webkit_database::DatabaseTracker(
- profile_->GetPath(), true)) {
+ start_time_(Time::Now()) {
extension_process_manager_.reset(ExtensionProcessManager::Create(this));
BrowserList::AddObserver(this);
@@ -183,11 +182,12 @@ class OffTheRecordProfileImpl : public Profile,
Source<Profile>(this),
NotificationService::NoDetails());
// Clean up all DB files/directories
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- db_tracker_.get(),
- &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory));
+ if (db_tracker_)
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(
+ db_tracker_.get(),
+ &webkit_database::DatabaseTracker::DeleteIncognitoDBDirectory));
BrowserList::RemoveObserver(this);
@@ -227,16 +227,22 @@ class OffTheRecordProfileImpl : public Profile,
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_;
}
virtual webkit_database::DatabaseTracker* GetDatabaseTracker() {
+ if (!db_tracker_.get()) {
+ db_tracker_ = new webkit_database::DatabaseTracker(
+ GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy());
+ }
return db_tracker_;
}
@@ -284,6 +290,10 @@ class OffTheRecordProfileImpl : public Profile,
return GetOriginalProfile()->GetExtensionIOEventRouter();
}
+ virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() {
+ return GetOriginalProfile()->GetExtensionSpecialStoragePolicy();
+ }
+
virtual SSLHostState* GetSSLHostState() {
if (!ssl_host_state_.get())
ssl_host_state_.reset(new SSLHostState());
@@ -380,7 +390,7 @@ class OffTheRecordProfileImpl : public Profile,
virtual fileapi::FileSystemContext* GetFileSystemContext() {
if (!file_system_context_)
file_system_context_ = CreateFileSystemContext(
- GetPath(), IsOffTheRecord());
+ GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy());
DCHECK(file_system_context_.get());
return file_system_context_.get();
}
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 42252da..c45b072 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -68,6 +68,7 @@ class ExtensionMessageService;
class ExtensionPrefValueMap;
class ExtensionProcessManager;
class ExtensionService;
+class ExtensionSpecialStoragePolicy;
class FaviconService;
class FilePath;
class FindBarState;
@@ -229,6 +230,10 @@ class Profile {
// Accessor. The instance is created at startup.
virtual ExtensionIOEventRouter* GetExtensionIOEventRouter() = 0;
+ // Accessor. The instance is created upon first access.
+ virtual ExtensionSpecialStoragePolicy*
+ GetExtensionSpecialStoragePolicy() = 0;
+
// Retrieves a pointer to the SSLHostState associated with this profile.
// The SSLHostState is lazily created the first time that this method is
// called.
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 4b51e82..f639147 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -36,6 +36,7 @@
#include "chrome/browser/extensions/extension_pref_store.h"
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/extensions/user_script_master.h"
#include "chrome/browser/favicon_service.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
@@ -642,11 +643,13 @@ ChromeAppCacheService* ProfileImpl::GetAppCacheService() {
appcache_service_ = new ChromeAppCacheService;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(appcache_service_.get(),
- &ChromeAppCacheService::InitializeOnIOThread,
- GetPath(), IsOffTheRecord(),
- make_scoped_refptr(GetHostContentSettingsMap()),
- clear_local_state_on_exit_));
+ NewRunnableMethod(
+ appcache_service_.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ GetPath(), IsOffTheRecord(),
+ make_scoped_refptr(GetHostContentSettingsMap()),
+ make_scoped_refptr(GetExtensionSpecialStoragePolicy()),
+ clear_local_state_on_exit_));
}
return appcache_service_;
}
@@ -654,7 +657,7 @@ ChromeAppCacheService* ProfileImpl::GetAppCacheService() {
webkit_database::DatabaseTracker* ProfileImpl::GetDatabaseTracker() {
if (!db_tracker_) {
db_tracker_ = new webkit_database::DatabaseTracker(
- GetPath(), IsOffTheRecord());
+ GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy());
}
return db_tracker_;
}
@@ -709,6 +712,13 @@ ExtensionIOEventRouter* ProfileImpl::GetExtensionIOEventRouter() {
return extension_io_event_router_.get();
}
+ExtensionSpecialStoragePolicy*
+ ProfileImpl::GetExtensionSpecialStoragePolicy() {
+ if (!extension_special_storage_policy_.get())
+ extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy();
+ return extension_special_storage_policy_.get();
+}
+
SSLHostState* ProfileImpl::GetSSLHostState() {
if (!ssl_host_state_.get())
ssl_host_state_.reset(new SSLHostState());
@@ -1065,7 +1075,7 @@ PersonalDataManager* ProfileImpl::GetPersonalDataManager() {
fileapi::FileSystemContext* ProfileImpl::GetFileSystemContext() {
if (!file_system_context_.get())
file_system_context_ = CreateFileSystemContext(
- GetPath(), IsOffTheRecord());
+ GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy());
DCHECK(file_system_context_.get());
return file_system_context_.get();
}
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 5eea88cb..ef35079 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -63,6 +63,7 @@ class ProfileImpl : public Profile,
virtual ExtensionMessageService* GetExtensionMessageService();
virtual ExtensionEventRouter* GetExtensionEventRouter();
virtual ExtensionIOEventRouter* GetExtensionIOEventRouter();
+ virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy();
virtual FaviconService* GetFaviconService(ServiceAccessType sat);
virtual HistoryService* GetHistoryService(ServiceAccessType sat);
virtual HistoryService* GetHistoryServiceWithoutCreating();
@@ -201,6 +202,8 @@ class ProfileImpl : public Profile,
scoped_refptr<ExtensionMessageService> extension_message_service_;
scoped_ptr<ExtensionEventRouter> extension_event_router_;
scoped_refptr<ExtensionIOEventRouter> extension_io_event_router_;
+ scoped_refptr<ExtensionSpecialStoragePolicy>
+ extension_special_storage_policy_;
scoped_ptr<SSLHostState> ssl_host_state_;
scoped_refptr<net::TransportSecurityState>
transport_security_state_;
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index a9baafd..892a29e 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
#include "chrome/browser/extensions/extension_pref_value_map.h"
#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_special_storage_policy.h"
#include "chrome/browser/favicon_service.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
#include "chrome/browser/geolocation/geolocation_permission_context.h"
@@ -396,8 +397,10 @@ ChromeAppCacheService* TestingProfile::GetAppCacheService() {
}
webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
- if (!db_tracker_)
- db_tracker_ = new webkit_database::DatabaseTracker(GetPath(), false);
+ if (!db_tracker_) {
+ db_tracker_ = new webkit_database::DatabaseTracker(
+ GetPath(), false, GetExtensionSpecialStoragePolicy());
+ }
return db_tracker_;
}
@@ -433,6 +436,13 @@ ExtensionIOEventRouter* TestingProfile::GetExtensionIOEventRouter() {
return NULL;
}
+ExtensionSpecialStoragePolicy*
+TestingProfile::GetExtensionSpecialStoragePolicy() {
+ if (!extension_special_storage_policy_)
+ extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy();
+ return extension_special_storage_policy_;
+}
+
SSLHostState* TestingProfile::GetSSLHostState() {
return NULL;
}
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index a8a610a..5517553 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -28,6 +28,7 @@ class DesktopNotificationService;
class ExtensionPrefs;
class ExtensionPrefStore;
class ExtensionPrefValueMap;
+class ExtensionSpecialStoragePolicy;
class FaviconService;
class FindBarState;
class GeolocationContentSettingsMap;
@@ -153,6 +154,7 @@ class TestingProfile : public Profile {
virtual ExtensionMessageService* GetExtensionMessageService();
virtual ExtensionEventRouter* GetExtensionEventRouter();
virtual ExtensionIOEventRouter* GetExtensionIOEventRouter();
+ virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy();
virtual SSLHostState* GetSSLHostState();
virtual net::TransportSecurityState* GetTransportSecurityState();
virtual FaviconService* GetFaviconService(ServiceAccessType access);
@@ -392,6 +394,9 @@ class TestingProfile : public Profile {
scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_;
+ scoped_refptr<ExtensionSpecialStoragePolicy>
+ extension_special_storage_policy_;
+
// The proxy prefs tracker.
scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;