Chromium Code Reviews| Index: webkit/fileapi/test_mount_point_provider.cc |
| diff --git a/webkit/fileapi/test_mount_point_provider.cc b/webkit/fileapi/test_mount_point_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5827e2ea6c1946ccaf4d258866d9b77485cc411d |
| --- /dev/null |
| +++ b/webkit/fileapi/test_mount_point_provider.cc |
| @@ -0,0 +1,147 @@ |
| +// Copyright (c) 2012 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/test_mount_point_provider.h" |
| + |
|
tzik
2012/05/10 08:31:00
add #include <set> and #include <string> for lint.
kinuko
2012/05/11 06:59:35
Done.
|
| +#include <vector> |
| + |
| +#include "base/file_util.h" |
| +#include "base/sequenced_task_runner.h" |
| +#include "webkit/fileapi/file_system_file_reader.h" |
| +#include "webkit/fileapi/file_system_operation.h" |
| +#include "webkit/fileapi/file_system_quota_util.h" |
| +#include "webkit/fileapi/local_file_util.h" |
| +#include "webkit/fileapi/native_file_util.h" |
| + |
| +namespace fileapi { |
| + |
| +namespace { |
| + |
| +// This only supports single origin. |
| +class TestFileSystemQuotaUtil : public FileSystemQuotaUtil { |
| + public: |
| + TestFileSystemQuotaUtil(base::SequencedTaskRunner* task_runner) |
| + : FileSystemQuotaUtil(task_runner), usage_(0) {} |
| + virtual ~TestFileSystemQuotaUtil() {} |
| + |
| + virtual void GetOriginsForTypeOnFileThread( |
| + FileSystemType type, |
| + std::set<GURL>* origins) OVERRIDE { |
| + NOTREACHED(); |
| + } |
| + virtual void GetOriginsForHostOnFileThread( |
| + FileSystemType type, |
| + const std::string& host, |
| + std::set<GURL>* origins) OVERRIDE { |
| + NOTREACHED(); |
| + } |
| + virtual int64 GetOriginUsageOnFileThread( |
| + const GURL& origin_url, |
| + FileSystemType type) OVERRIDE { |
| + return usage_; |
| + } |
| + virtual void NotifyOriginWasAccessedOnIOThread( |
| + quota::QuotaManagerProxy* proxy, |
| + const GURL& origin_url, |
| + FileSystemType type) OVERRIDE { |
| + // Do nothing. |
| + } |
| + virtual void UpdateOriginUsageOnFileThread( |
| + quota::QuotaManagerProxy* proxy, |
| + const GURL& origin_url, |
| + FileSystemType type, |
| + int64 delta) OVERRIDE { |
| + usage_ += delta; |
| + } |
| + virtual void StartUpdateOriginOnFileThread( |
| + const GURL& origin_url, |
| + FileSystemType type) OVERRIDE { |
| + // Do nothing. |
| + } |
| + virtual void EndUpdateOriginOnFileThread( |
| + const GURL& origin_url, |
| + FileSystemType type) OVERRIDE {} |
| + virtual void InvalidateUsageCache(const GURL& origin_url, |
| + FileSystemType type) OVERRIDE { |
| + // Do nothing. |
| + } |
| + |
| + private: |
| + int64 usage_; |
| +}; |
| + |
| +} // namespace |
| + |
| +TestMountPointProvider::TestMountPointProvider( |
| + base::SequencedTaskRunner* task_runner, |
| + const FilePath& base_path) |
| + : base_path_(base_path), |
| + local_file_util_(new LocalFileUtil(new NativeFileUtil())), |
| + quota_util_(new TestFileSystemQuotaUtil(task_runner)) { |
| +} |
| + |
| +TestMountPointProvider::~TestMountPointProvider() { |
| +} |
| + |
| +void TestMountPointProvider::ValidateFileSystemRoot( |
| + const GURL& origin_url, |
| + FileSystemType type, |
| + bool create, |
| + const ValidateFileSystemCallback& callback) { |
| + // This won't be called unless we add test code that opens a test |
| + // filesystem by OpenFileSystem. |
| + NOTREACHED(); |
| +} |
| + |
| +FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread( |
| + const GURL& origin_url, |
| + FileSystemType type, |
| + const FilePath& virtual_path, |
| + bool create) { |
| + DCHECK_EQ(kFileSystemTypeTest, type); |
| + if (create) |
| + file_util::CreateDirectory(base_path_); |
| + return base_path_; |
| +} |
| + |
| +bool TestMountPointProvider::IsAccessAllowed( |
| + const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { |
| + return type == fileapi::kFileSystemTypeTest; |
| +} |
| + |
| +bool TestMountPointProvider::IsRestrictedFileName( |
| + const FilePath& filename) const { |
| + return false; |
| +} |
| + |
| +std::vector<FilePath> TestMountPointProvider::GetRootDirectories() const { |
| + return std::vector<FilePath>(); |
| +} |
| + |
| +FileSystemFileUtil* TestMountPointProvider::GetFileUtil() { |
| + return local_file_util_.get(); |
| +} |
| + |
| +FilePath TestMountPointProvider::GetPathForPermissionsCheck( |
| + const FilePath& virtual_path) const { |
| + return base_path_.Append(virtual_path); |
| +} |
| + |
| +FileSystemOperationInterface* |
| +TestMountPointProvider::CreateFileSystemOperation( |
| + const GURL& origin_url, |
| + FileSystemType file_system_type, |
| + const FilePath& virtual_path, |
| + FileSystemContext* context) const { |
| + return new FileSystemOperation(context); |
| +} |
| + |
| +webkit_blob::FileReader* TestMountPointProvider::CreateFileReader( |
| + const GURL& url, |
| + int64 offset, |
| + FileSystemContext* context) const { |
| + return new FileSystemFileReader(context, url, offset); |
| +} |
| + |
| +} // namespace fileapi |