diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 01:47:58 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 01:47:58 +0000 |
commit | 0e7842ea75600bff6ab719a5bf196b3c5f973d88 (patch) | |
tree | 3bb16be280b7968527b72d6bd33bb6e70c80d068 /webkit/fileapi | |
parent | c5f29a5ef0ab3cf90faf97f7ae75cf14969fa2fa (diff) | |
download | chromium_src-0e7842ea75600bff6ab719a5bf196b3c5f973d88.zip chromium_src-0e7842ea75600bff6ab719a5bf196b3c5f973d88.tar.gz chromium_src-0e7842ea75600bff6ab719a5bf196b3c5f973d88.tar.bz2 |
Remove FileSystemQuotaManager class
Now that we have SpecialStoragePolicy class and are going to have QuotaFileSystemUtil, I think we're ready to get rid of this class.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6609009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_context.cc | 17 | ||||
-rw-r--r-- | webkit/fileapi/file_system_context.h | 15 | ||||
-rw-r--r-- | webkit/fileapi/file_system_context_unittest.cc | 89 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 28 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 8 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_manager.cc | 38 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_manager.h | 54 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_manager_unittest.cc | 102 | ||||
-rw-r--r-- | webkit/fileapi/webkit_fileapi.gypi | 2 |
9 files changed, 129 insertions, 224 deletions
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc index 6cb97e9..71e5ed2 100644 --- a/webkit/fileapi/file_system_context.cc +++ b/webkit/fileapi/file_system_context.cc @@ -6,8 +6,8 @@ #include "base/file_util.h" #include "base/message_loop_proxy.h" +#include "googleurl/src/gurl.h" #include "webkit/fileapi/file_system_path_manager.h" -#include "webkit/fileapi/file_system_quota_manager.h" #include "webkit/fileapi/file_system_usage_tracker.h" namespace fileapi { @@ -22,10 +22,11 @@ FileSystemContext::FileSystemContext( bool unlimited_quota) : file_message_loop_(file_message_loop), io_message_loop_(io_message_loop), + special_storage_policy_(special_storage_policy), + allow_file_access_from_files_(allow_file_access), + unlimited_quota_(unlimited_quota), path_manager_(new FileSystemPathManager( file_message_loop, profile_path, is_incognito, allow_file_access)), - quota_manager_(new FileSystemQuotaManager( - allow_file_access, unlimited_quota, special_storage_policy)), usage_tracker_(new FileSystemUsageTracker( file_message_loop, profile_path, is_incognito)) { } @@ -33,6 +34,16 @@ FileSystemContext::FileSystemContext( FileSystemContext::~FileSystemContext() { } +bool FileSystemContext::IsStorageUnlimited(const GURL& origin) { + // 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. + return unlimited_quota_ || + (allow_file_access_from_files_ && origin.SchemeIsFile()) || + (special_storage_policy_.get() && + special_storage_policy_->IsStorageUnlimited(origin)); +} + void FileSystemContext::DeleteDataForOriginOnFileThread( const GURL& origin_url) { DCHECK(path_manager_.get()); diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h index d9552946..f37c428 100644 --- a/webkit/fileapi/file_system_context.h +++ b/webkit/fileapi/file_system_context.h @@ -16,10 +16,13 @@ namespace base { class MessageLoopProxy; } +namespace quota { +class SpecialStoragePolicy; +} + namespace fileapi { class FileSystemPathManager; -class FileSystemQuotaManager; class FileSystemUsageTracker; class FileSystemContext; @@ -40,10 +43,12 @@ class FileSystemContext bool unlimited_quota); ~FileSystemContext(); + // This method can be called on any thread. + bool IsStorageUnlimited(const GURL& origin); + void DeleteDataForOriginOnFileThread(const GURL& origin_url); FileSystemPathManager* path_manager() { return path_manager_.get(); } - FileSystemQuotaManager* quota_manager() { return quota_manager_.get(); } FileSystemUsageTracker* usage_tracker() { return usage_tracker_.get(); } private: @@ -52,8 +57,12 @@ class FileSystemContext scoped_refptr<base::MessageLoopProxy> file_message_loop_; scoped_refptr<base::MessageLoopProxy> io_message_loop_; + + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; + const bool allow_file_access_from_files_; + const bool unlimited_quota_; + scoped_ptr<FileSystemPathManager> path_manager_; - scoped_ptr<FileSystemQuotaManager> quota_manager_; scoped_ptr<FileSystemUsageTracker> usage_tracker_; DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); diff --git a/webkit/fileapi/file_system_context_unittest.cc b/webkit/fileapi/file_system_context_unittest.cc new file mode 100644 index 0000000..55dfcd9 --- /dev/null +++ b/webkit/fileapi/file_system_context_unittest.cc @@ -0,0 +1,89 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/fileapi/file_system_context.h" + +#include "base/basictypes.h" +#include "base/file_path.h" +#include "base/logging.h" +#include "base/message_loop_proxy.h" +#include "base/scoped_ptr.h" +#include "base/string_number_conversions.h" +#include "googleurl/src/gurl.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webkit/quota/special_storage_policy.h" + +using namespace fileapi; + +namespace { + +static const char* const kTestOrigins[] = { + "https://a.com/", + "http://b.com/", + "http://c.com:1/", + "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]); + } +}; + +scoped_refptr<FileSystemContext> NewFileSystemContext( + bool allow_file_access, + bool unlimited_quota, + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { + return new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(), + base::MessageLoopProxy::CreateForCurrentThread(), + special_storage_policy, + FilePath(), false /* is_incognito */, + allow_file_access, unlimited_quota); +} + +} // anonymous namespace + +TEST(FileSystemContextTest, IsStorageUnlimited) { + // Regular cases. + scoped_refptr<FileSystemContext> context( + NewFileSystemContext(false, false, NULL)); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { + SCOPED_TRACE(testing::Message() << "IsStorageUnlimited w/o policy #" + << i << " " << kTestOrigins[i]); + EXPECT_FALSE(context->IsStorageUnlimited(GURL(kTestOrigins[i]))); + } + + // With allow_file_access=true cases. + context = NewFileSystemContext(true, false, NULL); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { + SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w " + "allow_file_access=true #" << i << " " << kTestOrigins[i]); + GURL origin(kTestOrigins[i]); + EXPECT_EQ(origin.SchemeIsFile(), context->IsStorageUnlimited(origin)); + } + + // With unlimited_quota=true cases. + context = NewFileSystemContext(false, true, NULL); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { + SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w " + "unlimited_quota=true #" << i << " " << kTestOrigins[i]); + EXPECT_TRUE(context->IsStorageUnlimited(GURL(kTestOrigins[i]))); + } + + // With SpecialStoragePolicy. + scoped_refptr<TestSpecialStoragePolicy> policy(new TestSpecialStoragePolicy); + context = NewFileSystemContext(false, false, policy); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { + SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #" + << i << " " << kTestOrigins[i]); + GURL origin(kTestOrigins[i]); + EXPECT_EQ(policy->IsStorageUnlimited(origin), + context->IsStorageUnlimited(origin)); + } +} diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index b01f4d5..d3d4908 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -9,7 +9,6 @@ #include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_path_manager.h" -#include "webkit/fileapi/file_system_quota_manager.h" #include "webkit/fileapi/file_writer_delegate.h" namespace fileapi { @@ -54,7 +53,7 @@ void FileSystemOperation::CreateFile(const FilePath& path, pending_operation_ = kOperationCreateFile; #endif - if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { + if (!VerifyFileSystemPathForWrite(path, true /* create */)) { delete this; return; } @@ -72,7 +71,7 @@ void FileSystemOperation::CreateDirectory(const FilePath& path, pending_operation_ = kOperationCreateDirectory; #endif - if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { + if (!VerifyFileSystemPathForWrite(path, true /* create */)) { delete this; return; } @@ -89,8 +88,7 @@ void FileSystemOperation::Copy(const FilePath& src_path, #endif if (!VerifyFileSystemPathForRead(src_path) || - !VerifyFileSystemPathForWrite(dest_path, true /* create */, - FileSystemQuotaManager::kUnknownSize)) { + !VerifyFileSystemPathForWrite(dest_path, true /* create */)) { delete this; return; } @@ -107,8 +105,7 @@ void FileSystemOperation::Move(const FilePath& src_path, #endif if (!VerifyFileSystemPathForRead(src_path) || - !VerifyFileSystemPathForWrite(dest_path, true /* create */, - FileSystemQuotaManager::kUnknownSize)) { + !VerifyFileSystemPathForWrite(dest_path, true /* create */)) { delete this; return; } @@ -180,7 +177,7 @@ void FileSystemOperation::Remove(const FilePath& path, bool recursive) { pending_operation_ = kOperationRemove; #endif - if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) { + if (!VerifyFileSystemPathForWrite(path, false /* create */)) { delete this; return; } @@ -198,8 +195,7 @@ void FileSystemOperation::Write( DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationWrite; #endif - if (!VerifyFileSystemPathForWrite(path, true /* create */, - FileSystemQuotaManager::kUnknownSize)) { + if (!VerifyFileSystemPathForWrite(path, true /* create */)) { delete this; return; } @@ -222,7 +218,7 @@ void FileSystemOperation::Truncate(const FilePath& path, int64 length) { DCHECK(kOperationNone == pending_operation_); pending_operation_ = kOperationTruncate; #endif - if (!VerifyFileSystemPathForWrite(path, false /* create */, 0)) { + if (!VerifyFileSystemPathForWrite(path, false /* create */)) { delete this; return; } @@ -239,7 +235,7 @@ void FileSystemOperation::TouchFile(const FilePath& path, pending_operation_ = kOperationTouchFile; #endif - if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) { + if (!VerifyFileSystemPathForWrite(path, true /* create */)) { delete this; return; } @@ -416,7 +412,7 @@ bool FileSystemOperation::VerifyFileSystemPathForRead( } bool FileSystemOperation::VerifyFileSystemPathForWrite( - const FilePath& path, bool create, int64 growth) { + const FilePath& path, bool create) { GURL origin_url; FilePath virtual_path; @@ -440,10 +436,8 @@ bool FileSystemOperation::VerifyFileSystemPathForWrite( dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); return false; } - // TODO(kinuko): For operations with kUnknownSize we'll eventually - // need to resolve what amount of size it's going to write. - if (!file_system_context_->quota_manager()->CheckOriginQuota( - origin_url, growth)) { + // TODO(kinuko): the check must be moved to QuotaFileSystemFileUtil. + if (!file_system_context_->IsStorageUnlimited(origin_url)) { dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); return false; } diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index 6542806..4630fe7 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -127,12 +127,11 @@ class FileSystemOperation { // Checks the validity of a given |path| for writing. // Returns true if the given |path| is a valid FileSystem path, and - // its origin embedded in the path has the right to write as much as - // the given |growth|. + // its origin embedded in the path has the right to write. // Otherwise it fires dispatcher's DidFail method with // PLATFORM_FILE_ERROR_SECURITY if the path is not valid for writing, // or with PLATFORM_FILE_ERROR_NO_SPACE if the origin is not allowed to - // increase the usage by |growth|. + // write to the storage. // In either case it returns false after firing DidFail. // If |create| flag is true this also checks if the |path| contains // any restricted names and chars. If it does, the call fires dispatcher's @@ -140,8 +139,7 @@ class FileSystemOperation { // (Note: this doesn't delete this when it calls DidFail and returns false; // it's the caller's responsibility.) bool VerifyFileSystemPathForWrite(const FilePath& path, - bool create, - int64 growth); + bool create); #ifndef NDEBUG enum OperationType { diff --git a/webkit/fileapi/file_system_quota_manager.cc b/webkit/fileapi/file_system_quota_manager.cc deleted file mode 100644 index 69ff706..0000000 --- a/webkit/fileapi/file_system_quota_manager.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/fileapi/file_system_quota_manager.h" - -#include "base/file_path.h" -#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 { - -const int64 FileSystemQuotaManager::kUnknownSize = -1; - -FileSystemQuotaManager::FileSystemQuotaManager( - bool allow_file_access_from_files, - bool unlimited_quota, - quota::SpecialStoragePolicy* special_storage_policy) - : allow_file_access_from_files_(allow_file_access_from_files), - unlimited_quota_(unlimited_quota), - special_storage_policy_(special_storage_policy) { -} - -FileSystemQuotaManager::~FileSystemQuotaManager() {} - -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. - 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 deleted file mode 100644 index b7d4d04..0000000 --- a/webkit/fileapi/file_system_quota_manager.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_ -#define WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_ - -#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 -// and just allows unlimited quota for apps. -class FileSystemQuotaManager { - public: - static const int64 kUnknownSize; - - // If |allow_file_access_from_files| is true, unlimited access is granted - // for file:/// URLs. - // 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, - quota::SpecialStoragePolicy* special_storage_policy); - ~FileSystemQuotaManager(); - - // Checks if the origin can grow its usage by |growth| bytes. - // This only performs in-memory check and returns immediately. - // For now it just returns false for any origins (regardless of the size) - // that are not in the in-memory unlimited_quota_origins map. - bool CheckOriginQuota(const GURL& origin, int64 growth); - - 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); -}; - -} // namespace fileapi - -#endif // WEBKIT_FILEAPI_FILE_SYSTEM_QUOTA_MANAGER_H_ diff --git a/webkit/fileapi/file_system_quota_manager_unittest.cc b/webkit/fileapi/file_system_quota_manager_unittest.cc deleted file mode 100644 index b22a33f9..0000000 --- a/webkit/fileapi/file_system_quota_manager_unittest.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/fileapi/file_system_quota_manager.h" - -#include "base/basictypes.h" -#include "base/logging.h" -#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; - -namespace { - -static const char* const kTestOrigins[] = { - "https://a.com/", - "http://b.com/", - "http://c.com:1/", - "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(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. - GURL origin(kTestOrigins[i]); - EXPECT_FALSE(quota.CheckOriginQuota(origin, -1)); - EXPECT_FALSE(quota.CheckOriginQuota(origin, 0)); - EXPECT_FALSE(quota.CheckOriginQuota(origin, 100)); - } -} - -TEST(FileSystemQuotaManagerTest, CheckUnlimitedFlag) { - FileSystemQuotaManager quota(false, true, NULL); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" - << i << " " << kTestOrigins[i]); - // 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(FileSystemQuotaManagerTest, CheckAllowFileFlag) { - FileSystemQuotaManager quota(true, false, NULL); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { - SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #" - << i << " " << kTestOrigins[i]); - // 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(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() << "CheckOriginQuotaNotAllowed #" - << i << " " << kTestOrigins[i]); - // 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)); - } - } -} diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi index 53a7510..564b1b7 100644 --- a/webkit/fileapi/webkit_fileapi.gypi +++ b/webkit/fileapi/webkit_fileapi.gypi @@ -23,8 +23,6 @@ 'file_system_operation.h', 'file_system_path_manager.cc', 'file_system_path_manager.h', - 'file_system_quota_manager.cc', - 'file_system_quota_manager.h', 'file_system_types.h', 'file_system_url_request_job.cc', 'file_system_url_request_job.h', |