OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/fileapi/test_mount_point_provider.h" |
| 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/file_util.h" |
| 12 #include "base/sequenced_task_runner.h" |
| 13 #include "webkit/fileapi/file_system_file_reader.h" |
| 14 #include "webkit/fileapi/file_system_operation.h" |
| 15 #include "webkit/fileapi/file_system_quota_util.h" |
| 16 #include "webkit/fileapi/local_file_util.h" |
| 17 #include "webkit/fileapi/native_file_util.h" |
| 18 #include "webkit/fileapi/file_system_util.h" |
| 19 #include "webkit/quota/quota_manager.h" |
| 20 |
| 21 namespace fileapi { |
| 22 |
| 23 namespace { |
| 24 |
| 25 // This only supports single origin. |
| 26 class TestFileSystemQuotaUtil : public FileSystemQuotaUtil { |
| 27 public: |
| 28 explicit TestFileSystemQuotaUtil(base::SequencedTaskRunner* task_runner) |
| 29 : FileSystemQuotaUtil(task_runner), usage_(0) {} |
| 30 virtual ~TestFileSystemQuotaUtil() {} |
| 31 |
| 32 virtual void GetOriginsForTypeOnFileThread( |
| 33 FileSystemType type, |
| 34 std::set<GURL>* origins) OVERRIDE { |
| 35 NOTREACHED(); |
| 36 } |
| 37 virtual void GetOriginsForHostOnFileThread( |
| 38 FileSystemType type, |
| 39 const std::string& host, |
| 40 std::set<GURL>* origins) OVERRIDE { |
| 41 NOTREACHED(); |
| 42 } |
| 43 virtual int64 GetOriginUsageOnFileThread( |
| 44 const GURL& origin_url, |
| 45 FileSystemType type) OVERRIDE { |
| 46 return usage_; |
| 47 } |
| 48 virtual void NotifyOriginWasAccessedOnIOThread( |
| 49 quota::QuotaManagerProxy* proxy, |
| 50 const GURL& origin_url, |
| 51 FileSystemType type) OVERRIDE { |
| 52 // Do nothing. |
| 53 } |
| 54 virtual void UpdateOriginUsageOnFileThread( |
| 55 quota::QuotaManagerProxy* proxy, |
| 56 const GURL& origin_url, |
| 57 FileSystemType type, |
| 58 int64 delta) OVERRIDE { |
| 59 usage_ += delta; |
| 60 if (proxy) { |
| 61 proxy->NotifyStorageModified( |
| 62 quota::QuotaClient::kFileSystem, |
| 63 origin_url, |
| 64 FileSystemTypeToQuotaStorageType(type), |
| 65 delta); |
| 66 } |
| 67 } |
| 68 virtual void StartUpdateOriginOnFileThread( |
| 69 const GURL& origin_url, |
| 70 FileSystemType type) OVERRIDE { |
| 71 // Do nothing. |
| 72 } |
| 73 virtual void EndUpdateOriginOnFileThread( |
| 74 const GURL& origin_url, |
| 75 FileSystemType type) OVERRIDE {} |
| 76 virtual void InvalidateUsageCache(const GURL& origin_url, |
| 77 FileSystemType type) OVERRIDE { |
| 78 // Do nothing. |
| 79 } |
| 80 |
| 81 private: |
| 82 int64 usage_; |
| 83 }; |
| 84 |
| 85 } // namespace |
| 86 |
| 87 TestMountPointProvider::TestMountPointProvider( |
| 88 base::SequencedTaskRunner* task_runner, |
| 89 const FilePath& base_path) |
| 90 : base_path_(base_path), |
| 91 local_file_util_(new LocalFileUtil(new NativeFileUtil())), |
| 92 quota_util_(new TestFileSystemQuotaUtil(task_runner)) { |
| 93 } |
| 94 |
| 95 TestMountPointProvider::~TestMountPointProvider() { |
| 96 } |
| 97 |
| 98 void TestMountPointProvider::ValidateFileSystemRoot( |
| 99 const GURL& origin_url, |
| 100 FileSystemType type, |
| 101 bool create, |
| 102 const ValidateFileSystemCallback& callback) { |
| 103 // This won't be called unless we add test code that opens a test |
| 104 // filesystem by OpenFileSystem. |
| 105 NOTREACHED(); |
| 106 } |
| 107 |
| 108 FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 109 const GURL& origin_url, |
| 110 FileSystemType type, |
| 111 const FilePath& virtual_path, |
| 112 bool create) { |
| 113 DCHECK_EQ(kFileSystemTypeTest, type); |
| 114 bool success = true; |
| 115 if (create) |
| 116 success = file_util::CreateDirectory(base_path_); |
| 117 else |
| 118 success = file_util::DirectoryExists(base_path_); |
| 119 return success ? base_path_ : FilePath(); |
| 120 } |
| 121 |
| 122 bool TestMountPointProvider::IsAccessAllowed( |
| 123 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { |
| 124 return type == fileapi::kFileSystemTypeTest; |
| 125 } |
| 126 |
| 127 bool TestMountPointProvider::IsRestrictedFileName( |
| 128 const FilePath& filename) const { |
| 129 return false; |
| 130 } |
| 131 |
| 132 std::vector<FilePath> TestMountPointProvider::GetRootDirectories() const { |
| 133 return std::vector<FilePath>(); |
| 134 } |
| 135 |
| 136 FileSystemFileUtil* TestMountPointProvider::GetFileUtil() { |
| 137 return local_file_util_.get(); |
| 138 } |
| 139 |
| 140 FilePath TestMountPointProvider::GetPathForPermissionsCheck( |
| 141 const FilePath& virtual_path) const { |
| 142 return base_path_.Append(virtual_path); |
| 143 } |
| 144 |
| 145 FileSystemOperationInterface* |
| 146 TestMountPointProvider::CreateFileSystemOperation( |
| 147 const GURL& origin_url, |
| 148 FileSystemType file_system_type, |
| 149 const FilePath& virtual_path, |
| 150 FileSystemContext* context) const { |
| 151 return new FileSystemOperation(context); |
| 152 } |
| 153 |
| 154 webkit_blob::FileReader* TestMountPointProvider::CreateFileReader( |
| 155 const GURL& url, |
| 156 int64 offset, |
| 157 FileSystemContext* context) const { |
| 158 return new FileSystemFileReader(context, url, offset); |
| 159 } |
| 160 |
| 161 FileSystemQuotaUtil* TestMountPointProvider::GetQuotaUtil() { |
| 162 return quota_util_.get(); |
| 163 } |
| 164 |
| 165 } // namespace fileapi |
OLD | NEW |