| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/browser/fileapi/test_file_system_backend.h" | 5 #include "webkit/browser/fileapi/test_file_system_backend.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "webkit/browser/quota/quota_manager.h" | 22 #include "webkit/browser/quota/quota_manager.h" |
| 23 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
| 24 | 24 |
| 25 namespace fileapi { | 25 namespace fileapi { |
| 26 | 26 |
| 27 // This only supports single origin. | 27 // This only supports single origin. |
| 28 class TestFileSystemBackend::QuotaUtil | 28 class TestFileSystemBackend::QuotaUtil |
| 29 : public FileSystemQuotaUtil, | 29 : public FileSystemQuotaUtil, |
| 30 public FileUpdateObserver { | 30 public FileUpdateObserver { |
| 31 public: | 31 public: |
| 32 QuotaUtil() : usage_(0) {} | 32 QuotaUtil(base::SequencedTaskRunner* task_runner) |
| 33 : usage_(0), |
| 34 task_runner_(task_runner) { |
| 35 UpdateObserverList::Source source; |
| 36 source.AddObserver(this, task_runner_.get()); |
| 37 update_observers_ = UpdateObserverList(source); |
| 38 } |
| 33 virtual ~QuotaUtil() {} | 39 virtual ~QuotaUtil() {} |
| 34 | 40 |
| 35 // FileSystemQuotaUtil overrides. | 41 // FileSystemQuotaUtil overrides. |
| 36 virtual base::PlatformFileError DeleteOriginDataOnFileThread( | 42 virtual base::PlatformFileError DeleteOriginDataOnFileThread( |
| 37 FileSystemContext* context, | 43 FileSystemContext* context, |
| 38 quota::QuotaManagerProxy* proxy, | 44 quota::QuotaManagerProxy* proxy, |
| 39 const GURL& origin_url, | 45 const GURL& origin_url, |
| 40 FileSystemType type) OVERRIDE { | 46 FileSystemType type) OVERRIDE { |
| 41 NOTREACHED(); | 47 NOTREACHED(); |
| 42 return base::PLATFORM_FILE_OK; | 48 return base::PLATFORM_FILE_OK; |
| 43 } | 49 } |
| 50 |
| 44 virtual void GetOriginsForTypeOnFileThread( | 51 virtual void GetOriginsForTypeOnFileThread( |
| 45 FileSystemType type, | 52 FileSystemType type, |
| 46 std::set<GURL>* origins) OVERRIDE { | 53 std::set<GURL>* origins) OVERRIDE { |
| 47 NOTREACHED(); | 54 NOTREACHED(); |
| 48 } | 55 } |
| 56 |
| 49 virtual void GetOriginsForHostOnFileThread( | 57 virtual void GetOriginsForHostOnFileThread( |
| 50 FileSystemType type, | 58 FileSystemType type, |
| 51 const std::string& host, | 59 const std::string& host, |
| 52 std::set<GURL>* origins) OVERRIDE { | 60 std::set<GURL>* origins) OVERRIDE { |
| 53 NOTREACHED(); | 61 NOTREACHED(); |
| 54 } | 62 } |
| 63 |
| 55 virtual int64 GetOriginUsageOnFileThread( | 64 virtual int64 GetOriginUsageOnFileThread( |
| 56 FileSystemContext* context, | 65 FileSystemContext* context, |
| 57 const GURL& origin_url, | 66 const GURL& origin_url, |
| 58 FileSystemType type) OVERRIDE { | 67 FileSystemType type) OVERRIDE { |
| 59 return usage_; | 68 return usage_; |
| 60 } | 69 } |
| 70 |
| 61 virtual void InvalidateUsageCache(const GURL& origin_url, | 71 virtual void InvalidateUsageCache(const GURL& origin_url, |
| 62 FileSystemType type) OVERRIDE { | 72 FileSystemType type) OVERRIDE { |
| 63 // Do nothing. | 73 // Do nothing. |
| 64 } | 74 } |
| 75 |
| 65 virtual void StickyInvalidateUsageCache( | 76 virtual void StickyInvalidateUsageCache( |
| 66 const GURL& origin, | 77 const GURL& origin, |
| 67 FileSystemType type) OVERRIDE { | 78 FileSystemType type) OVERRIDE { |
| 68 // Do nothing. | 79 // Do nothing. |
| 69 } | 80 } |
| 70 | 81 |
| 82 virtual void AddFileUpdateObserver( |
| 83 FileSystemType type, |
| 84 FileUpdateObserver* observer, |
| 85 base::SequencedTaskRunner* task_runner) OVERRIDE { |
| 86 NOTIMPLEMENTED(); |
| 87 } |
| 88 |
| 89 virtual void AddFileChangeObserver( |
| 90 FileSystemType type, |
| 91 FileChangeObserver* observer, |
| 92 base::SequencedTaskRunner* task_runner) OVERRIDE { |
| 93 ChangeObserverList::Source source = change_observers_.source(); |
| 94 source.AddObserver(observer, task_runner); |
| 95 change_observers_ = ChangeObserverList(source); |
| 96 } |
| 97 |
| 98 virtual void AddFileAccessObserver( |
| 99 FileSystemType type, |
| 100 FileAccessObserver* observer, |
| 101 base::SequencedTaskRunner* task_runner) OVERRIDE { |
| 102 NOTIMPLEMENTED(); |
| 103 } |
| 104 |
| 105 virtual const UpdateObserverList* GetUpdateObservers( |
| 106 FileSystemType type) const OVERRIDE { |
| 107 return &update_observers_; |
| 108 } |
| 109 |
| 110 virtual const ChangeObserverList* GetChangeObservers( |
| 111 FileSystemType type) const OVERRIDE { |
| 112 return &change_observers_; |
| 113 } |
| 114 |
| 115 virtual const AccessObserverList* GetAccessObservers( |
| 116 FileSystemType type) const OVERRIDE { |
| 117 NOTIMPLEMENTED(); |
| 118 return NULL; |
| 119 } |
| 120 |
| 71 // FileUpdateObserver overrides. | 121 // FileUpdateObserver overrides. |
| 72 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} | 122 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} |
| 73 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { | 123 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { |
| 74 usage_ += delta; | 124 usage_ += delta; |
| 75 } | 125 } |
| 76 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} | 126 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} |
| 77 | 127 |
| 128 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } |
| 129 |
| 78 private: | 130 private: |
| 79 int64 usage_; | 131 int64 usage_; |
| 132 |
| 133 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 134 |
| 135 UpdateObserverList update_observers_; |
| 136 ChangeObserverList change_observers_; |
| 80 }; | 137 }; |
| 81 | 138 |
| 82 TestFileSystemBackend::TestFileSystemBackend( | 139 TestFileSystemBackend::TestFileSystemBackend( |
| 83 base::SequencedTaskRunner* task_runner, | 140 base::SequencedTaskRunner* task_runner, |
| 84 const base::FilePath& base_path) | 141 const base::FilePath& base_path) |
| 85 : base_path_(base_path), | 142 : base_path_(base_path), |
| 86 task_runner_(task_runner), | |
| 87 local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())), | 143 local_file_util_(new AsyncFileUtilAdapter(new LocalFileUtil())), |
| 88 quota_util_(new QuotaUtil), | 144 quota_util_(new QuotaUtil(task_runner)), |
| 89 require_copy_or_move_validator_(false) { | 145 require_copy_or_move_validator_(false) { |
| 90 UpdateObserverList::Source source; | |
| 91 source.AddObserver(quota_util_.get(), task_runner_.get()); | |
| 92 update_observers_ = UpdateObserverList(source); | |
| 93 } | 146 } |
| 94 | 147 |
| 95 TestFileSystemBackend::~TestFileSystemBackend() { | 148 TestFileSystemBackend::~TestFileSystemBackend() { |
| 96 } | 149 } |
| 97 | 150 |
| 98 bool TestFileSystemBackend::CanHandleType(FileSystemType type) const { | 151 bool TestFileSystemBackend::CanHandleType(FileSystemType type) const { |
| 99 return (type == kFileSystemTypeTest); | 152 return (type == kFileSystemTypeTest); |
| 100 } | 153 } |
| 101 | 154 |
| 102 void TestFileSystemBackend::OpenFileSystem( | 155 void TestFileSystemBackend::OpenFileSystem( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (!copy_or_move_file_validator_factory_) | 193 if (!copy_or_move_file_validator_factory_) |
| 141 copy_or_move_file_validator_factory_ = factory.Pass(); | 194 copy_or_move_file_validator_factory_ = factory.Pass(); |
| 142 } | 195 } |
| 143 | 196 |
| 144 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( | 197 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( |
| 145 const FileSystemURL& url, | 198 const FileSystemURL& url, |
| 146 FileSystemContext* context, | 199 FileSystemContext* context, |
| 147 base::PlatformFileError* error_code) const { | 200 base::PlatformFileError* error_code) const { |
| 148 scoped_ptr<FileSystemOperationContext> operation_context( | 201 scoped_ptr<FileSystemOperationContext> operation_context( |
| 149 new FileSystemOperationContext(context)); | 202 new FileSystemOperationContext(context)); |
| 150 operation_context->set_update_observers(update_observers_); | 203 operation_context->set_update_observers(*GetUpdateObservers(url.type())); |
| 151 operation_context->set_change_observers(change_observers_); | 204 operation_context->set_change_observers( |
| 205 *quota_util_->GetChangeObservers(url.type())); |
| 152 operation_context->set_root_path(base_path_); | 206 operation_context->set_root_path(base_path_); |
| 153 return new LocalFileSystemOperation(url, context, operation_context.Pass()); | 207 return new LocalFileSystemOperation(url, context, operation_context.Pass()); |
| 154 } | 208 } |
| 155 | 209 |
| 156 scoped_ptr<webkit_blob::FileStreamReader> | 210 scoped_ptr<webkit_blob::FileStreamReader> |
| 157 TestFileSystemBackend::CreateFileStreamReader( | 211 TestFileSystemBackend::CreateFileStreamReader( |
| 158 const FileSystemURL& url, | 212 const FileSystemURL& url, |
| 159 int64 offset, | 213 int64 offset, |
| 160 const base::Time& expected_modification_time, | 214 const base::Time& expected_modification_time, |
| 161 FileSystemContext* context) const { | 215 FileSystemContext* context) const { |
| 162 return scoped_ptr<webkit_blob::FileStreamReader>( | 216 return scoped_ptr<webkit_blob::FileStreamReader>( |
| 163 new FileSystemFileStreamReader( | 217 new FileSystemFileStreamReader( |
| 164 context, url, offset, expected_modification_time)); | 218 context, url, offset, expected_modification_time)); |
| 165 } | 219 } |
| 166 | 220 |
| 167 scoped_ptr<fileapi::FileStreamWriter> | 221 scoped_ptr<fileapi::FileStreamWriter> |
| 168 TestFileSystemBackend::CreateFileStreamWriter( | 222 TestFileSystemBackend::CreateFileStreamWriter( |
| 169 const FileSystemURL& url, | 223 const FileSystemURL& url, |
| 170 int64 offset, | 224 int64 offset, |
| 171 FileSystemContext* context) const { | 225 FileSystemContext* context) const { |
| 172 return scoped_ptr<fileapi::FileStreamWriter>( | 226 return scoped_ptr<fileapi::FileStreamWriter>( |
| 173 new SandboxFileStreamWriter(context, url, offset, update_observers_)); | 227 new SandboxFileStreamWriter(context, url, offset, |
| 228 *GetUpdateObservers(url.type()))); |
| 174 } | 229 } |
| 175 | 230 |
| 176 FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { | 231 FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { |
| 177 return quota_util_.get(); | 232 return quota_util_.get(); |
| 178 } | 233 } |
| 179 | 234 |
| 180 const UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( | 235 const UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( |
| 181 FileSystemType type) const { | 236 FileSystemType type) const { |
| 182 return &update_observers_; | 237 return quota_util_->GetUpdateObservers(type); |
| 183 } | 238 } |
| 184 | 239 |
| 185 void TestFileSystemBackend::AddFileChangeObserver( | 240 void TestFileSystemBackend::AddFileChangeObserver( |
| 186 FileChangeObserver* observer) { | 241 FileChangeObserver* observer) { |
| 187 ChangeObserverList::Source source = change_observers_.source(); | 242 quota_util_->AddFileChangeObserver( |
| 188 source.AddObserver(observer, task_runner_.get()); | 243 kFileSystemTypeTest, observer, quota_util_->task_runner()); |
| 189 change_observers_ = ChangeObserverList(source); | |
| 190 } | 244 } |
| 191 | 245 |
| 192 } // namespace fileapi | 246 } // namespace fileapi |
| OLD | NEW |