diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:28:43 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:28:43 +0000 |
commit | 19eb8015c483fff874bf1eddb80bd26cf4167f33 (patch) | |
tree | be896411dde17d24eb8dbcd67e7b4c5cad2ef1b6 /webkit/fileapi | |
parent | f02074331bddc7d89b20e6b3a8fb934e6891207c (diff) | |
download | chromium_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/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_context.cc | 13 | ||||
-rw-r--r-- | webkit/fileapi/file_system_context.h | 6 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_manager.cc | 31 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_manager.h | 14 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_manager_unittest.cc | 154 |
5 files changed, 76 insertions, 142 deletions
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc index 5007fff..6cb97e9 100644 --- a/webkit/fileapi/file_system_context.cc +++ b/webkit/fileapi/file_system_context.cc @@ -15,6 +15,7 @@ namespace fileapi { FileSystemContext::FileSystemContext( scoped_refptr<base::MessageLoopProxy> file_message_loop, scoped_refptr<base::MessageLoopProxy> io_message_loop, + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, const FilePath& profile_path, bool is_incognito, bool allow_file_access, @@ -24,7 +25,7 @@ FileSystemContext::FileSystemContext( path_manager_(new FileSystemPathManager( file_message_loop, profile_path, is_incognito, allow_file_access)), quota_manager_(new FileSystemQuotaManager( - allow_file_access, unlimited_quota)), + allow_file_access, unlimited_quota, special_storage_policy)), usage_tracker_(new FileSystemUsageTracker( file_message_loop, profile_path, is_incognito)) { } @@ -45,16 +46,6 @@ void FileSystemContext::DeleteDataForOriginOnFileThread( file_util::Delete(path_for_origin, true /* recursive */); } -void FileSystemContext::SetOriginQuotaUnlimited(const GURL& url) { - DCHECK(io_message_loop_->BelongsToCurrentThread()); - quota_manager()->SetOriginQuotaUnlimited(url); -} - -void FileSystemContext::ResetOriginQuotaUnlimited(const GURL& url) { - DCHECK(io_message_loop_->BelongsToCurrentThread()); - quota_manager()->ResetOriginQuotaUnlimited(url); -} - void FileSystemContext::DeleteOnCorrectThread() const { if (!io_message_loop_->BelongsToCurrentThread()) { io_message_loop_->DeleteSoon(FROM_HERE, this); diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h index 5c94c5f..d9552946 100644 --- a/webkit/fileapi/file_system_context.h +++ b/webkit/fileapi/file_system_context.h @@ -7,6 +7,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "webkit/quota/special_storage_policy.h" class FilePath; class GURL; @@ -32,6 +33,7 @@ class FileSystemContext FileSystemContext( scoped_refptr<base::MessageLoopProxy> file_message_loop, scoped_refptr<base::MessageLoopProxy> io_message_loop, + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, const FilePath& profile_path, bool is_incognito, bool allow_file_access_from_files, @@ -40,10 +42,6 @@ class FileSystemContext void DeleteDataForOriginOnFileThread(const GURL& origin_url); - // Quota related methods. - void SetOriginQuotaUnlimited(const GURL& url); - void ResetOriginQuotaUnlimited(const GURL& url); - FileSystemPathManager* path_manager() { return path_manager_.get(); } FileSystemQuotaManager* quota_manager() { return quota_manager_.get(); } FileSystemUsageTracker* usage_tracker() { return usage_tracker_.get(); } diff --git a/webkit/fileapi/file_system_quota_manager.cc b/webkit/fileapi/file_system_quota_manager.cc index 13a33f6..69ff706 100644 --- a/webkit/fileapi/file_system_quota_manager.cc +++ b/webkit/fileapi/file_system_quota_manager.cc @@ -8,6 +8,7 @@ #include "base/file_util_proxy.h" #include "base/ref_counted.h" #include "base/scoped_callback_factory.h" +#include "webkit/quota/special_storage_policy.h" namespace fileapi { @@ -15,9 +16,11 @@ const int64 FileSystemQuotaManager::kUnknownSize = -1; FileSystemQuotaManager::FileSystemQuotaManager( bool allow_file_access_from_files, - bool unlimited_quota) + bool unlimited_quota, + quota::SpecialStoragePolicy* special_storage_policy) : allow_file_access_from_files_(allow_file_access_from_files), - unlimited_quota_(unlimited_quota) { + unlimited_quota_(unlimited_quota), + special_storage_policy_(special_storage_policy) { } FileSystemQuotaManager::~FileSystemQuotaManager() {} @@ -26,26 +29,10 @@ bool FileSystemQuotaManager::CheckOriginQuota(const GURL& origin, int64) { // If allow-file-access-from-files flag is explicitly given and the scheme // is file, or if unlimited quota for this process was explicitly requested, // return true. - if (unlimited_quota_ || - (origin.SchemeIsFile() && allow_file_access_from_files_)) - return true; - return CheckIfOriginGrantedUnlimitedQuota(origin); -} - -void FileSystemQuotaManager::SetOriginQuotaUnlimited(const GURL& origin) { - DCHECK(origin == origin.GetOrigin()); - unlimited_quota_origins_.insert(origin); -} - -void FileSystemQuotaManager::ResetOriginQuotaUnlimited(const GURL& origin) { - DCHECK(origin == origin.GetOrigin()); - unlimited_quota_origins_.erase(origin); -} - -bool FileSystemQuotaManager::CheckIfOriginGrantedUnlimitedQuota( - const GURL& origin) { - std::set<GURL>::const_iterator found = unlimited_quota_origins_.find(origin); - return (found != unlimited_quota_origins_.end()); + return unlimited_quota_ || + (allow_file_access_from_files_ && origin.SchemeIsFile()) || + (special_storage_policy_.get() && + special_storage_policy_->IsStorageUnlimited(origin)); } } // namespace fileapi diff --git a/webkit/fileapi/file_system_quota_manager.h b/webkit/fileapi/file_system_quota_manager.h index f1c94e1..b7d4d04 100644 --- a/webkit/fileapi/file_system_quota_manager.h +++ b/webkit/fileapi/file_system_quota_manager.h @@ -8,8 +8,13 @@ #include <set> #include "base/basictypes.h" +#include "base/ref_counted.h" #include "googleurl/src/gurl.h" +namespace quota { +class SpecialStoragePolicy; +} + namespace fileapi { // A quota manager for FileSystem. For now it has little implementation @@ -23,7 +28,8 @@ class FileSystemQuotaManager { // If |unlimited_quota| is true, unlimited access is granted for every // origin. This flag must be used only for testing. FileSystemQuotaManager(bool allow_file_access_from_files, - bool unlimited_quota); + bool unlimited_quota, + quota::SpecialStoragePolicy* special_storage_policy); ~FileSystemQuotaManager(); // Checks if the origin can grow its usage by |growth| bytes. @@ -32,17 +38,13 @@ class FileSystemQuotaManager { // that are not in the in-memory unlimited_quota_origins map. bool CheckOriginQuota(const GURL& origin, int64 growth); - // Maintains origins in memory that are allowed to have unlimited quota. - void SetOriginQuotaUnlimited(const GURL& origin); - void ResetOriginQuotaUnlimited(const GURL& origin); - bool CheckIfOriginGrantedUnlimitedQuota(const GURL& origin); - private: // For some extensions/apps we allow unlimited quota. std::set<GURL> unlimited_quota_origins_; const bool allow_file_access_from_files_; const bool unlimited_quota_; + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaManager); }; diff --git a/webkit/fileapi/file_system_quota_manager_unittest.cc b/webkit/fileapi/file_system_quota_manager_unittest.cc index 3bc7ac3..b22a33f9 100644 --- a/webkit/fileapi/file_system_quota_manager_unittest.cc +++ b/webkit/fileapi/file_system_quota_manager_unittest.cc @@ -9,24 +9,10 @@ #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/quota/special_storage_policy.h" using namespace fileapi; -class FileSystemQuotaManagerTest : public testing::Test { - public: - FileSystemQuotaManagerTest() { } - - void SetUp() { - quota_.reset(new FileSystemQuotaManager(false, false)); - } - - FileSystemQuotaManager* quota() const { return quota_.get(); } - - protected: - scoped_ptr<FileSystemQuotaManager> quota_; - DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaManagerTest); -}; - namespace { static const char* const kTestOrigins[] = { @@ -36,111 +22,81 @@ static const char* const kTestOrigins[] = { "file:///", }; +class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy { + public: + virtual bool IsStorageProtected(const GURL& origin) { + return false; + } + + virtual bool IsStorageUnlimited(const GURL& origin) { + return origin == GURL(kTestOrigins[1]); + } +}; + } // anonymous namespace -TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaNotAllowed) { +TEST(FileSystemQuotaManagerTest, CheckNotAllowed) { + FileSystemQuotaManager quota(false, false, NULL); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" << i << " " << kTestOrigins[i]); // Should fail no matter how much size is requested. - EXPECT_FALSE(quota()->CheckOriginQuota(GURL(kTestOrigins[i]), -1)); - EXPECT_FALSE(quota()->CheckOriginQuota(GURL(kTestOrigins[i]), 0)); - EXPECT_FALSE(quota()->CheckOriginQuota(GURL(kTestOrigins[i]), 100)); + GURL origin(kTestOrigins[i]); + EXPECT_FALSE(quota.CheckOriginQuota(origin, -1)); + EXPECT_FALSE(quota.CheckOriginQuota(origin, 0)); + EXPECT_FALSE(quota.CheckOriginQuota(origin, 100)); } } -TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaUnlimited) { - // Tests if SetOriginQuotaUnlimited and ResetOriginQuotaUnlimited - // are working as expected. +TEST(FileSystemQuotaManagerTest, CheckUnlimitedFlag) { + FileSystemQuotaManager quota(false, true, NULL); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - SCOPED_TRACE(testing::Message() << "CheckOriginQuotaUnlimited #" - << i << " " << kTestOrigins[i]); - GURL url(kTestOrigins[i]); - EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url)); - EXPECT_FALSE(quota()->CheckOriginQuota(url, 0)); - - quota()->SetOriginQuotaUnlimited(url); - EXPECT_TRUE(quota()->CheckIfOriginGrantedUnlimitedQuota(url)); - EXPECT_TRUE(quota()->CheckOriginQuota(url, -1)); - EXPECT_TRUE(quota()->CheckOriginQuota(url, 0)); - EXPECT_TRUE(quota()->CheckOriginQuota(url, 100)); - - quota()->ResetOriginQuotaUnlimited(url); - EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url)); - EXPECT_FALSE(quota()->CheckOriginQuota(url, -1)); - EXPECT_FALSE(quota()->CheckOriginQuota(url, 0)); - EXPECT_FALSE(quota()->CheckOriginQuota(url, 100)); - } -} - -TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaWithMixedSet) { - // Tests setting unlimited quota for some urls doesn't affect - // other urls. - GURL test_url1("http://foo.bar.com/"); - GURL test_url2("http://example.com/"); - quota()->SetOriginQuotaUnlimited(test_url1); - quota()->SetOriginQuotaUnlimited(test_url2); - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - SCOPED_TRACE(testing::Message() << "CheckOriginQuotaMixedSet #" + SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" << i << " " << kTestOrigins[i]); - GURL url(kTestOrigins[i]); - EXPECT_FALSE(quota()->CheckOriginQuota(url, 0)); - EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url)); + // Should succeed no matter how much size is requested. + GURL origin(kTestOrigins[i]); + EXPECT_TRUE(quota.CheckOriginQuota(origin, -1)); + EXPECT_TRUE(quota.CheckOriginQuota(origin, 0)); + EXPECT_TRUE(quota.CheckOriginQuota(origin, 100)); } } -TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaMixedWithDifferentScheme) { - // Tests setting unlimited quota for urls doesn't affect - // pages in the same hosts but with different scheme. +TEST(FileSystemQuotaManagerTest, CheckAllowFileFlag) { + FileSystemQuotaManager quota(true, false, NULL); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - GURL url(kTestOrigins[i]); - if (url.SchemeIsFile()) - continue; - ASSERT_TRUE(url == url.GetOrigin()); - std::string new_scheme = "https"; - if (url.SchemeIsSecure()) - new_scheme = "http"; - else - ASSERT_TRUE(url.SchemeIs("http")); - std::string new_url_string = new_scheme + "://" + url.host(); - if (url.has_port()) - new_url_string += ":" + url.port(); - quota()->SetOriginQuotaUnlimited(GURL(new_url_string)); - } - - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - SCOPED_TRACE(testing::Message() - << "CheckOriginQuotaMixedWithDifferentScheme #" + SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" << i << " " << kTestOrigins[i]); - GURL url(kTestOrigins[i]); - EXPECT_FALSE(quota()->CheckOriginQuota(url, 0)); - EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url)); + // Should succeed only for file:// urls + GURL origin(kTestOrigins[i]); + if (origin.SchemeIsFile()) { + EXPECT_TRUE(quota.CheckOriginQuota(origin, -1)); + EXPECT_TRUE(quota.CheckOriginQuota(origin, 0)); + EXPECT_TRUE(quota.CheckOriginQuota(origin, 100)); + } else { + EXPECT_FALSE(quota.CheckOriginQuota(origin, -1)); + EXPECT_FALSE(quota.CheckOriginQuota(origin, 0)); + EXPECT_FALSE(quota.CheckOriginQuota(origin, 100)); + } } } -TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaMixedWithDifferentPort) { - // Tests setting unlimited quota for urls doesn't affect - // pages in the same scheme/hosts but with different port number. - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - GURL url(kTestOrigins[i]); - if (url.SchemeIsFile()) - continue; - ASSERT_TRUE(url == url.GetOrigin()); - int port = 81; - if (url.has_port()) - port = url.IntPort() + 1; - GURL new_url(url.scheme() + "://" + url.host() + ":" + - base::IntToString(port)); - quota()->SetOriginQuotaUnlimited(new_url); - } +TEST(FileSystemQuotaManagerTest, CheckSpecialPolicy) { + scoped_refptr<TestSpecialStoragePolicy> policy(new TestSpecialStoragePolicy); + FileSystemQuotaManager quota(false, false, policy); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - SCOPED_TRACE(testing::Message() - << "CheckOriginQuotaMixedWithDifferentPort #" + SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" << i << " " << kTestOrigins[i]); - GURL url(kTestOrigins[i]); - EXPECT_FALSE(quota()->CheckOriginQuota(url, 0)); - EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url)); + // Should succeed only for unlimited origins according to the policy. + GURL origin(kTestOrigins[i]); + if (policy->IsStorageUnlimited(origin)) { + EXPECT_TRUE(quota.CheckOriginQuota(origin, -1)); + EXPECT_TRUE(quota.CheckOriginQuota(origin, 0)); + EXPECT_TRUE(quota.CheckOriginQuota(origin, 100)); + } else { + EXPECT_FALSE(quota.CheckOriginQuota(origin, -1)); + EXPECT_FALSE(quota.CheckOriginQuota(origin, 0)); + EXPECT_FALSE(quota.CheckOriginQuota(origin, 100)); + } } } |