Chromium Code Reviews| 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 <vector> | |
| 8 | |
| 9 #include "base/file_util.h" | |
| 10 #include "base/sequenced_task_runner.h" | |
| 11 #include "webkit/fileapi/file_system_file_reader.h" | |
| 12 #include "webkit/fileapi/file_system_operation.h" | |
| 13 #include "webkit/fileapi/file_system_quota_util.h" | |
| 14 #include "webkit/fileapi/local_file_util.h" | |
| 15 #include "webkit/fileapi/native_file_util.h" | |
| 16 | |
| 17 namespace fileapi { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // This only supports single origin. | |
| 22 class TestFileSystemQuotaUtil : public FileSystemQuotaUtil { | |
| 23 public: | |
| 24 TestFileSystemQuotaUtil(base::SequencedTaskRunner* task_runner) | |
|
tzik
2012/05/10 08:31:00
need explicit?
kinuko
2012/05/11 06:59:34
Done.
| |
| 25 : FileSystemQuotaUtil(task_runner), usage_(0) {} | |
| 26 virtual ~TestFileSystemQuotaUtil() {} | |
| 27 | |
| 28 virtual void GetOriginsForTypeOnFileThread( | |
| 29 FileSystemType type, | |
| 30 std::set<GURL>* origins) OVERRIDE { | |
| 31 NOTREACHED(); | |
| 32 } | |
| 33 virtual void GetOriginsForHostOnFileThread( | |
| 34 FileSystemType type, | |
| 35 const std::string& host, | |
| 36 std::set<GURL>* origins) OVERRIDE { | |
| 37 NOTREACHED(); | |
| 38 } | |
| 39 virtual int64 GetOriginUsageOnFileThread( | |
| 40 const GURL& origin_url, | |
| 41 FileSystemType type) OVERRIDE { | |
| 42 return usage_; | |
| 43 } | |
| 44 virtual void NotifyOriginWasAccessedOnIOThread( | |
| 45 quota::QuotaManagerProxy* proxy, | |
| 46 const GURL& origin_url, | |
| 47 FileSystemType type) OVERRIDE { | |
| 48 // Do nothing. | |
| 49 } | |
| 50 virtual void UpdateOriginUsageOnFileThread( | |
| 51 quota::QuotaManagerProxy* proxy, | |
| 52 const GURL& origin_url, | |
| 53 FileSystemType type, | |
| 54 int64 delta) OVERRIDE { | |
| 55 usage_ += delta; | |
| 56 } | |
| 57 virtual void StartUpdateOriginOnFileThread( | |
| 58 const GURL& origin_url, | |
| 59 FileSystemType type) OVERRIDE { | |
| 60 // Do nothing. | |
| 61 } | |
| 62 virtual void EndUpdateOriginOnFileThread( | |
| 63 const GURL& origin_url, | |
| 64 FileSystemType type) OVERRIDE {} | |
| 65 virtual void InvalidateUsageCache(const GURL& origin_url, | |
| 66 FileSystemType type) OVERRIDE { | |
| 67 usage_ = 0; | |
|
tzik
2012/05/10 08:31:00
This method should not reset usage.
Could you leav
kinuko
2012/05/11 06:59:34
Done.
| |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 int64 usage_; | |
| 72 }; | |
| 73 | |
| 74 } // namespace | |
| 75 | |
| 76 TestMountPointProvider::TestMountPointProvider( | |
| 77 base::SequencedTaskRunner* task_runner, | |
| 78 const FilePath& base_path) | |
| 79 : base_path_(base_path), | |
| 80 local_file_util_(new LocalFileUtil(new NativeFileUtil())), | |
| 81 quota_util_(new TestFileSystemQuotaUtil(task_runner)) { | |
| 82 } | |
| 83 | |
| 84 TestMountPointProvider::~TestMountPointProvider() { | |
| 85 } | |
| 86 | |
| 87 void TestMountPointProvider::ValidateFileSystemRoot( | |
| 88 const GURL& origin_url, | |
| 89 FileSystemType type, | |
| 90 bool create, | |
| 91 const ValidateFileSystemCallback& callback) { | |
| 92 // This won't be called unless we add test code that opens a test | |
| 93 // filesystem by OpenFileSystem. | |
| 94 NOTREACHED(); | |
| 95 } | |
| 96 | |
| 97 FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread( | |
| 98 const GURL& origin_url, | |
| 99 FileSystemType type, | |
| 100 const FilePath& virtual_path, | |
| 101 bool create) { | |
| 102 DCHECK_EQ(kFileSystemTypeTest, type); | |
|
tzik
2012/05/10 08:31:00
Maybe, we should check if the directory exists, an
kinuko
2012/05/11 06:59:34
Done.
| |
| 103 if (create) | |
| 104 file_util::CreateDirectory(base_path_); | |
| 105 return base_path_; | |
| 106 } | |
| 107 | |
| 108 bool TestMountPointProvider::IsAccessAllowed( | |
| 109 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { | |
| 110 return type == fileapi::kFileSystemTypeTest; | |
| 111 } | |
| 112 | |
| 113 bool TestMountPointProvider::IsRestrictedFileName( | |
| 114 const FilePath& filename) const { | |
| 115 return false; | |
| 116 } | |
| 117 | |
| 118 std::vector<FilePath> TestMountPointProvider::GetRootDirectories() const { | |
| 119 return std::vector<FilePath>(); | |
|
tzik
2012/05/10 08:31:00
extra space?
kinuko
2012/05/11 06:59:34
Fixed.
| |
| 120 } | |
| 121 | |
| 122 FileSystemFileUtil* TestMountPointProvider::GetFileUtil() { | |
| 123 return local_file_util_.get(); | |
| 124 } | |
| 125 | |
| 126 FilePath TestMountPointProvider::GetPathForPermissionsCheck( | |
| 127 const FilePath& virtual_path) const { | |
| 128 return base_path_.Append(virtual_path); | |
| 129 } | |
| 130 | |
| 131 FileSystemOperationInterface* | |
| 132 TestMountPointProvider::CreateFileSystemOperation( | |
| 133 const GURL& origin_url, | |
| 134 FileSystemType file_system_type, | |
| 135 const FilePath& virtual_path, | |
| 136 FileSystemContext* context) const { | |
| 137 return new FileSystemOperation(context); | |
| 138 } | |
| 139 | |
| 140 webkit_blob::FileReader* TestMountPointProvider::CreateFileReader( | |
| 141 const GURL& url, | |
| 142 int64 offset, | |
| 143 FileSystemContext* context) const { | |
| 144 return new FileSystemFileReader(context, url, offset); | |
| 145 } | |
| 146 | |
| 147 } // namespace fileapi | |
| OLD | NEW |