diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 07:21:07 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-20 07:21:07 +0000 |
commit | 81484d75873e69e14282c54c9d5d1a6dd0907dcd (patch) | |
tree | 04eaa02fb6b032471d31cd46b34d58e2af33816e /webkit/fileapi | |
parent | 8813990fdba0923ef32ccac1431fb8a02898d8c0 (diff) | |
download | chromium_src-81484d75873e69e14282c54c9d5d1a6dd0907dcd.zip chromium_src-81484d75873e69e14282c54c9d5d1a6dd0907dcd.tar.gz chromium_src-81484d75873e69e14282c54c9d5d1a6dd0907dcd.tar.bz2 |
Obsoleting --unlimited-quota-for-files
BUG=94360
TEST=existing tests should pass
Review URL: http://codereview.chromium.org/7839027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101928 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 | 6 | ||||
-rw-r--r-- | webkit/fileapi/file_system_context_unittest.cc | 75 | ||||
-rw-r--r-- | webkit/fileapi/file_system_dir_url_request_job_unittest.cc | 3 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.cc | 97 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation.h | 2 | ||||
-rw-r--r-- | webkit/fileapi/file_system_operation_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/file_system_quota_client_unittest.cc | 3 | ||||
-rw-r--r-- | webkit/fileapi/file_system_test_helper.cc | 1 | ||||
-rw-r--r-- | webkit/fileapi/file_system_url_request_job_unittest.cc | 3 | ||||
-rw-r--r-- | webkit/fileapi/file_writer_delegate.cc | 19 | ||||
-rw-r--r-- | webkit/fileapi/file_writer_delegate_unittest.cc | 28 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util_unittest.cc | 1 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_mount_point_provider_unittest.cc | 1 |
14 files changed, 36 insertions, 222 deletions
diff --git a/webkit/fileapi/file_system_context.cc b/webkit/fileapi/file_system_context.cc index 82da15e..a88afce 100644 --- a/webkit/fileapi/file_system_context.cc +++ b/webkit/fileapi/file_system_context.cc @@ -33,20 +33,16 @@ FileSystemContext::FileSystemContext( quota::QuotaManagerProxy* quota_manager_proxy, const FilePath& profile_path, bool is_incognito, - bool allow_file_access, - bool unlimited_quota, + bool allow_file_access_from_files, FileSystemPathManager* path_manager) : file_message_loop_(file_message_loop), io_message_loop_(io_message_loop), - special_storage_policy_(special_storage_policy), quota_manager_proxy_(quota_manager_proxy), - allow_file_access_from_files_(allow_file_access), - unlimited_quota_(unlimited_quota), path_manager_(path_manager) { if (!path_manager) { path_manager_.reset(new FileSystemPathManager( file_message_loop, profile_path, special_storage_policy, - is_incognito, allow_file_access)); + is_incognito, allow_file_access_from_files)); } if (quota_manager_proxy) { quota_manager_proxy->RegisterClient(CreateQuotaClient( @@ -57,15 +53,6 @@ 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_ || - (special_storage_policy_.get() && - special_storage_policy_->IsStorageUnlimited(origin)); -} - bool FileSystemContext::DeleteDataForOriginOnFileThread( const GURL& origin_url) { DCHECK(file_message_loop_->BelongsToCurrentThread()); diff --git a/webkit/fileapi/file_system_context.h b/webkit/fileapi/file_system_context.h index ef99df8..fa6b30c 100644 --- a/webkit/fileapi/file_system_context.h +++ b/webkit/fileapi/file_system_context.h @@ -45,13 +45,10 @@ class FileSystemContext const FilePath& profile_path, bool is_incognito, bool allow_file_access_from_files, - bool unlimited_quota, FileSystemPathManager* path_manager); ~FileSystemContext(); // This method can be called on any thread. - bool IsStorageUnlimited(const GURL& origin); - bool DeleteDataForOriginOnFileThread(const GURL& origin_url); bool DeleteDataForOriginAndTypeOnFileThread(const GURL& origin_url, FileSystemType type); @@ -74,10 +71,7 @@ class FileSystemContext scoped_refptr<base::MessageLoopProxy> file_message_loop_; scoped_refptr<base::MessageLoopProxy> io_message_loop_; - scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; - const bool allow_file_access_from_files_; - const bool unlimited_quota_; scoped_ptr<FileSystemPathManager> path_manager_; diff --git a/webkit/fileapi/file_system_context_unittest.cc b/webkit/fileapi/file_system_context_unittest.cc deleted file mode 100644 index f5d6983e..0000000 --- a/webkit/fileapi/file_system_context_unittest.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2011 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/memory/scoped_ptr.h" -#include "base/message_loop_proxy.h" -#include "base/string_number_conversions.h" -#include "googleurl/src/gurl.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/quota/mock_special_storage_policy.h" -#include "webkit/quota/quota_manager.h" - -namespace fileapi { -namespace { - -static const char* const kTestOrigins[] = { - "https://a.com/", - "http://b.com/", - "http://c.com:1/", - "file:///", -}; - -scoped_refptr<FileSystemContext> NewFileSystemContext( - bool allow_file_access, - bool unlimited_quota, - scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { - return new FileSystemContext(base::MessageLoopProxy::current(), - base::MessageLoopProxy::current(), - special_storage_policy, - NULL /* quota manager */, - FilePath(), false /* is_incognito */, - allow_file_access, unlimited_quota, NULL); -} - -} // 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 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<quota::MockSpecialStoragePolicy> policy( - new quota::MockSpecialStoragePolicy); - policy->AddUnlimited(GURL(kTestOrigins[1])); - - 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)); - } -} - -} // namespace fileapi diff --git a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc index 2598c27..4b70f25 100644 --- a/webkit/fileapi/file_system_dir_url_request_job_unittest.cc +++ b/webkit/fileapi/file_system_dir_url_request_job_unittest.cc @@ -62,8 +62,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), special_storage_policy_, NULL, - FilePath(), false /* is_incognito */, - false, true, + FilePath(), false /* is_incognito */, true /* allow_file_access */, new FileSystemPathManager( file_thread_proxy_, temp_dir_.path(), NULL, false, false)); diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc index 070d8540..7d2dcb0 100644 --- a/webkit/fileapi/file_system_operation.cc +++ b/webkit/fileapi/file_system_operation.cc @@ -126,14 +126,7 @@ void FileSystemOperation::CreateFile(const GURL& path, void FileSystemOperation::DelayedCreateFileForQuota( quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->src_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -178,14 +171,7 @@ void FileSystemOperation::CreateDirectory(const GURL& path, void FileSystemOperation::DelayedCreateDirectoryForQuota( quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->src_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -237,14 +223,7 @@ void FileSystemOperation::Copy(const GURL& src_path, void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->dest_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -295,14 +274,7 @@ void FileSystemOperation::Move(const GURL& src_path, void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->dest_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -476,14 +448,7 @@ void FileSystemOperation::Write( void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->src_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -525,14 +490,7 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) { void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->src_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -622,14 +580,7 @@ void FileSystemOperation::OpenFile(const GURL& path, void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, int64 usage, int64 quota) { - if (file_system_context()->IsStorageUnlimited( - file_system_operation_context()->dest_origin_url()) || - quota == QuotaFileUtil::kNoLimit) { - file_system_operation_context_.set_allowed_bytes_growth( - QuotaFileUtil::kNoLimit); - } else { - file_system_operation_context_.set_allowed_bytes_growth(quota - usage); - } + file_system_operation_context_.set_allowed_bytes_growth(quota - usage); quota_util_helper_.reset(new ScopedQuotaUtilHelper( file_system_context(), @@ -678,29 +629,27 @@ void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { } } -bool FileSystemOperation::GetUsageAndQuotaThenCallback( +void FileSystemOperation::GetUsageAndQuotaThenCallback( const GURL& origin_url, quota::QuotaManager::GetUsageAndQuotaCallback* callback) { quota::QuotaManagerProxy* quota_manager_proxy = file_system_context()->quota_manager_proxy(); - if (quota_manager_proxy && quota_manager_proxy->quota_manager() && - file_system_operation_context_.src_type() != kFileSystemTypeExternal) { - quota_manager_proxy->quota_manager()->GetUsageAndQuota( - file_system_operation_context_.src_origin_url(), - FileSystemTypeToQuotaStorageType( - file_system_operation_context_.src_type()), - callback); - } else { - if (file_system_context()->IsStorageUnlimited(origin_url)) { - callback->Run(quota::kQuotaStatusOk, 0, QuotaFileUtil::kNoLimit); - delete callback; - } else { - dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); - delete callback; - return false; - } + if (!quota_manager_proxy || + !file_system_context()->GetQuotaUtil( + file_system_operation_context_.src_type())) { + // If we don't have the quota manager or the requested filesystem type + // does not support quota, we should be able to let it go. + callback->Run(quota::kQuotaStatusOk, 0, kint64max); + delete callback; + return; } - return true; + DCHECK(quota_manager_proxy); + DCHECK(quota_manager_proxy->quota_manager()); + quota_manager_proxy->quota_manager()->GetUsageAndQuota( + file_system_operation_context_.src_origin_url(), + FileSystemTypeToQuotaStorageType( + file_system_operation_context_.src_type()), + callback); } void FileSystemOperation::DidGetRootPath( diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h index cc1e34a..b38633a 100644 --- a/webkit/fileapi/file_system_operation.h +++ b/webkit/fileapi/file_system_operation.h @@ -109,7 +109,7 @@ class FileSystemOperation { friend class FileSystemTestOriginHelper; friend class FileSystemQuotaTest; - bool GetUsageAndQuotaThenCallback( + void GetUsageAndQuotaThenCallback( const GURL& origin_url, quota::QuotaManager::GetUsageAndQuotaCallback* callback); diff --git a/webkit/fileapi/file_system_operation_unittest.cc b/webkit/fileapi/file_system_operation_unittest.cc index 90f0031..a0c67d3 100644 --- a/webkit/fileapi/file_system_operation_unittest.cc +++ b/webkit/fileapi/file_system_operation_unittest.cc @@ -46,7 +46,7 @@ class MockQuotaManager : public QuotaManager { origin_(origin), type_(type), usage_(0), - quota_(QuotaFileUtil::kNoLimit), + quota_(kint64max), accessed_(0) {} virtual void GetUsageAndQuota( diff --git a/webkit/fileapi/file_system_quota_client_unittest.cc b/webkit/fileapi/file_system_quota_client_unittest.cc index 6d32938..59d11dd 100644 --- a/webkit/fileapi/file_system_quota_client_unittest.cc +++ b/webkit/fileapi/file_system_quota_client_unittest.cc @@ -57,8 +57,7 @@ class FileSystemQuotaClientTest : public testing::Test { base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), NULL, NULL, - FilePath(), false /* is_incognito */, - false, true, + FilePath(), false /* is_incognito */, true /* allow_file_access */, new MockFileSystemPathManager(data_dir_.path())); } diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc index 55e56c3..6422f66 100644 --- a/webkit/fileapi/file_system_test_helper.cc +++ b/webkit/fileapi/file_system_test_helper.cc @@ -79,7 +79,6 @@ void FileSystemTestOriginHelper::SetUp( base_dir, incognito_mode, true /* allow_file_access_from_files */, - unlimited_quota, NULL); DCHECK(file_system_context_->path_manager()); diff --git a/webkit/fileapi/file_system_url_request_job_unittest.cc b/webkit/fileapi/file_system_url_request_job_unittest.cc index bd5b288..0070033 100644 --- a/webkit/fileapi/file_system_url_request_job_unittest.cc +++ b/webkit/fileapi/file_system_url_request_job_unittest.cc @@ -81,8 +81,7 @@ class FileSystemURLRequestJobTest : public testing::Test { base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), special_storage_policy_, NULL, - FilePath(), false /* is_incognito */, - false, true, + FilePath(), false /* is_incognito */, true /* allow_file_access */, new FileSystemPathManager( base::MessageLoopProxy::current(), temp_dir_.path(), NULL, false, false)); diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc index 1051277..db28a22 100644 --- a/webkit/fileapi/file_writer_delegate.cc +++ b/webkit/fileapi/file_writer_delegate.cc @@ -112,19 +112,12 @@ void FileWriterDelegate::OnGetFileInfoAndCallStartUpdate( } int64 allowed_bytes_growth = file_system_operation_context()->allowed_bytes_growth(); - if (allowed_bytes_growth == QuotaFileUtil::kNoLimit || - file_system_operation_->file_system_context()->IsStorageUnlimited( - file_system_operation_context()->src_origin_url())) { - // TODO(kinuko): kNoLimit is kint64max therefore all the calculation/ - // comparison with the value should just work, but we should drop - // such implicit assumption and should use an explicit boolean flag - // or something. - allowed_bytes_to_write_ = QuotaFileUtil::kNoLimit; - } else { - if (allowed_bytes_growth < 0) - allowed_bytes_growth = 0; - allowed_bytes_to_write_ = file_info.size - offset_ + allowed_bytes_growth; - } + if (allowed_bytes_growth < 0) + allowed_bytes_growth = 0; + int64 overlap = file_info.size - offset_; + allowed_bytes_to_write_ = allowed_bytes_growth; + if (kint64max - overlap > allowed_bytes_growth) + allowed_bytes_to_write_ += overlap; size_ = file_info.size; file_stream_.reset(new net::FileStream(file_, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | diff --git a/webkit/fileapi/file_writer_delegate_unittest.cc b/webkit/fileapi/file_writer_delegate_unittest.cc index 7713085..e0f8310 100644 --- a/webkit/fileapi/file_writer_delegate_unittest.cc +++ b/webkit/fileapi/file_writer_delegate_unittest.cc @@ -455,32 +455,4 @@ class FileWriterDelegateUnlimitedTest : public FileWriterDelegateTest { virtual void SetUpTestHelper(const FilePath& path) OVERRIDE; }; -void FileWriterDelegateUnlimitedTest::SetUpTestHelper(const FilePath& path) { - quota_file_util_.reset(QuotaFileUtil::CreateDefault()); - test_helper_.SetUp( - path, - false /* incognito */, - true /* unlimited */, - NULL /* quota manager proxy */, - quota_file_util_.get()); -} - -TEST_F(FileWriterDelegateUnlimitedTest, WriteWithQuota) { - const GURL kBlobURL("blob:with-unlimited"); - content_ = kData; - - // Set small allowed_growth bytes - PrepareForWrite(kBlobURL, 0, 10); - - // We shouldn't fail as the context is configured as 'unlimited'. - file_writer_delegate_->Start(file_, request_.get()); - MessageLoop::current()->Run(); - EXPECT_EQ(kDataSize, test_helper_.GetCachedOriginUsage()); - EXPECT_EQ(ComputeCurrentOriginUsage(), - test_helper_.GetCachedOriginUsage()); - EXPECT_EQ(kDataSize, result_->bytes_written()); - EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status()); - EXPECT_TRUE(result_->complete()); -} - } // namespace fileapi diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index ec40c67..8b9f14c 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -160,7 +160,6 @@ class ObfuscatedFileUtilTest : public testing::Test { data_dir_.path(), false /* incognito */, true /* allow_file_access_from_files */, - false /* unlimited_quota */, NULL /* path_manager */); obfuscated_file_util_ = static_cast<ObfuscatedFileUtil*>( diff --git a/webkit/fileapi/sandbox_mount_point_provider_unittest.cc b/webkit/fileapi/sandbox_mount_point_provider_unittest.cc index 6b17ea2..77f9d24 100644 --- a/webkit/fileapi/sandbox_mount_point_provider_unittest.cc +++ b/webkit/fileapi/sandbox_mount_point_provider_unittest.cc @@ -151,7 +151,6 @@ class SandboxMountPointProviderMigrationTest : public testing::Test { data_dir_.path(), false, // incognito true, // allow_file_access_from_files - true, // unlimited quota path_manager_); } |