| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/public/test/test_file_system_backend.h" | 5 #include "content/public/test/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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Stub implementation of storage::LocalFileUtil. | 40 // Stub implementation of storage::LocalFileUtil. |
| 41 class TestFileUtil : public storage::LocalFileUtil { | 41 class TestFileUtil : public storage::LocalFileUtil { |
| 42 public: | 42 public: |
| 43 explicit TestFileUtil(const base::FilePath& base_path) | 43 explicit TestFileUtil(const base::FilePath& base_path) |
| 44 : base_path_(base_path) {} | 44 : base_path_(base_path) {} |
| 45 virtual ~TestFileUtil() {} | 45 ~TestFileUtil() override {} |
| 46 | 46 |
| 47 // LocalFileUtil overrides. | 47 // LocalFileUtil overrides. |
| 48 virtual base::File::Error GetLocalFilePath( | 48 base::File::Error GetLocalFilePath(FileSystemOperationContext* context, |
| 49 FileSystemOperationContext* context, | 49 const FileSystemURL& file_system_url, |
| 50 const FileSystemURL& file_system_url, | 50 base::FilePath* local_file_path) override { |
| 51 base::FilePath* local_file_path) override { | |
| 52 *local_file_path = base_path_.Append(file_system_url.path()); | 51 *local_file_path = base_path_.Append(file_system_url.path()); |
| 53 return base::File::FILE_OK; | 52 return base::File::FILE_OK; |
| 54 } | 53 } |
| 55 | 54 |
| 56 private: | 55 private: |
| 57 base::FilePath base_path_; | 56 base::FilePath base_path_; |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 // Stub implementation of storage::WatcherManager. Emits a fake notification | 59 // Stub implementation of storage::WatcherManager. Emits a fake notification |
| 61 // after a directory watcher is set successfully. | 60 // after a directory watcher is set successfully. |
| 62 class TestWatcherManager : public storage::WatcherManager { | 61 class TestWatcherManager : public storage::WatcherManager { |
| 63 public: | 62 public: |
| 64 TestWatcherManager() : weak_ptr_factory_(this) {} | 63 TestWatcherManager() : weak_ptr_factory_(this) {} |
| 65 virtual ~TestWatcherManager() {} | 64 ~TestWatcherManager() override {} |
| 66 | 65 |
| 67 // storage::WatcherManager overrides. | 66 // storage::WatcherManager overrides. |
| 68 virtual void AddObserver(Observer* observer) override { | 67 void AddObserver(Observer* observer) override { |
| 69 observers_.AddObserver(observer); | 68 observers_.AddObserver(observer); |
| 70 } | 69 } |
| 71 | 70 |
| 72 virtual void RemoveObserver(Observer* observer) override { | 71 void RemoveObserver(Observer* observer) override { |
| 73 observers_.RemoveObserver(observer); | 72 observers_.RemoveObserver(observer); |
| 74 } | 73 } |
| 75 | 74 |
| 76 virtual bool HasObserver(Observer* observer) const override { | 75 bool HasObserver(Observer* observer) const override { |
| 77 return observers_.HasObserver(observer); | 76 return observers_.HasObserver(observer); |
| 78 } | 77 } |
| 79 | 78 |
| 80 virtual void WatchDirectory(const storage::FileSystemURL& url, | 79 void WatchDirectory(const storage::FileSystemURL& url, |
| 81 bool recursive, | 80 bool recursive, |
| 82 const StatusCallback& callback) override { | 81 const StatusCallback& callback) override { |
| 83 if (recursive) { | 82 if (recursive) { |
| 84 base::ThreadTaskRunnerHandle::Get()->PostTask( | 83 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 85 FROM_HERE, | 84 FROM_HERE, |
| 86 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); | 85 base::Bind(callback, base::File::FILE_ERROR_INVALID_OPERATION)); |
| 87 return; | 86 return; |
| 88 } | 87 } |
| 89 | 88 |
| 90 const GURL gurl = url.ToGURL(); | 89 const GURL gurl = url.ToGURL(); |
| 91 if (watched_urls_.find(gurl) != watched_urls_.end()) { | 90 if (watched_urls_.find(gurl) != watched_urls_.end()) { |
| 92 base::ThreadTaskRunnerHandle::Get()->PostTask( | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 106 url)); | 105 url)); |
| 107 | 106 |
| 108 // Send a fake removed notification. | 107 // Send a fake removed notification. |
| 109 base::ThreadTaskRunnerHandle::Get()->PostTask( | 108 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 110 FROM_HERE, | 109 FROM_HERE, |
| 111 base::Bind(&TestWatcherManager::SendFakeRemoveNotification, | 110 base::Bind(&TestWatcherManager::SendFakeRemoveNotification, |
| 112 weak_ptr_factory_.GetWeakPtr(), | 111 weak_ptr_factory_.GetWeakPtr(), |
| 113 url)); | 112 url)); |
| 114 } | 113 } |
| 115 | 114 |
| 116 virtual void UnwatchEntry(const storage::FileSystemURL& url, | 115 void UnwatchEntry(const storage::FileSystemURL& url, |
| 117 const StatusCallback& callback) override { | 116 const StatusCallback& callback) override { |
| 118 const GURL gurl = url.ToGURL(); | 117 const GURL gurl = url.ToGURL(); |
| 119 if (watched_urls_.find(gurl) == watched_urls_.end()) { | 118 if (watched_urls_.find(gurl) == watched_urls_.end()) { |
| 120 base::ThreadTaskRunnerHandle::Get()->PostTask( | 119 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 121 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); | 120 FROM_HERE, base::Bind(callback, base::File::FILE_ERROR_NOT_FOUND)); |
| 122 return; | 121 return; |
| 123 } | 122 } |
| 124 | 123 |
| 125 watched_urls_.erase(gurl); | 124 watched_urls_.erase(gurl); |
| 126 base::ThreadTaskRunnerHandle::Get()->PostTask( | 125 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 127 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); | 126 FROM_HERE, base::Bind(callback, base::File::FILE_OK)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 152 base::WeakPtrFactory<TestWatcherManager> weak_ptr_factory_; | 151 base::WeakPtrFactory<TestWatcherManager> weak_ptr_factory_; |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 } // namespace | 154 } // namespace |
| 156 | 155 |
| 157 // This only supports single origin. | 156 // This only supports single origin. |
| 158 class TestFileSystemBackend::QuotaUtil : public storage::FileSystemQuotaUtil, | 157 class TestFileSystemBackend::QuotaUtil : public storage::FileSystemQuotaUtil, |
| 159 public storage::FileUpdateObserver { | 158 public storage::FileUpdateObserver { |
| 160 public: | 159 public: |
| 161 QuotaUtil() : usage_(0) {} | 160 QuotaUtil() : usage_(0) {} |
| 162 virtual ~QuotaUtil() {} | 161 ~QuotaUtil() override {} |
| 163 | 162 |
| 164 // FileSystemQuotaUtil overrides. | 163 // FileSystemQuotaUtil overrides. |
| 165 virtual base::File::Error DeleteOriginDataOnFileTaskRunner( | 164 base::File::Error DeleteOriginDataOnFileTaskRunner( |
| 166 FileSystemContext* context, | 165 FileSystemContext* context, |
| 167 storage::QuotaManagerProxy* proxy, | 166 storage::QuotaManagerProxy* proxy, |
| 168 const GURL& origin_url, | 167 const GURL& origin_url, |
| 169 storage::FileSystemType type) override { | 168 storage::FileSystemType type) override { |
| 170 NOTREACHED(); | 169 NOTREACHED(); |
| 171 return base::File::FILE_OK; | 170 return base::File::FILE_OK; |
| 172 } | 171 } |
| 173 | 172 |
| 174 virtual scoped_refptr<storage::QuotaReservation> | 173 scoped_refptr<storage::QuotaReservation> |
| 175 CreateQuotaReservationOnFileTaskRunner( | 174 CreateQuotaReservationOnFileTaskRunner( |
| 176 const GURL& origin_url, | 175 const GURL& origin_url, |
| 177 storage::FileSystemType type) override { | 176 storage::FileSystemType type) override { |
| 178 NOTREACHED(); | 177 NOTREACHED(); |
| 179 return scoped_refptr<storage::QuotaReservation>(); | 178 return scoped_refptr<storage::QuotaReservation>(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 virtual void GetOriginsForTypeOnFileTaskRunner( | 181 void GetOriginsForTypeOnFileTaskRunner(storage::FileSystemType type, |
| 183 storage::FileSystemType type, | 182 std::set<GURL>* origins) override { |
| 184 std::set<GURL>* origins) override { | |
| 185 NOTREACHED(); | 183 NOTREACHED(); |
| 186 } | 184 } |
| 187 | 185 |
| 188 virtual void GetOriginsForHostOnFileTaskRunner( | 186 void GetOriginsForHostOnFileTaskRunner(storage::FileSystemType type, |
| 189 storage::FileSystemType type, | 187 const std::string& host, |
| 190 const std::string& host, | 188 std::set<GURL>* origins) override { |
| 191 std::set<GURL>* origins) override { | |
| 192 NOTREACHED(); | 189 NOTREACHED(); |
| 193 } | 190 } |
| 194 | 191 |
| 195 virtual int64 GetOriginUsageOnFileTaskRunner( | 192 int64 GetOriginUsageOnFileTaskRunner(FileSystemContext* context, |
| 196 FileSystemContext* context, | 193 const GURL& origin_url, |
| 197 const GURL& origin_url, | 194 storage::FileSystemType type) override { |
| 198 storage::FileSystemType type) override { | |
| 199 return usage_; | 195 return usage_; |
| 200 } | 196 } |
| 201 | 197 |
| 202 // FileUpdateObserver overrides. | 198 // FileUpdateObserver overrides. |
| 203 virtual void OnStartUpdate(const FileSystemURL& url) override {} | 199 void OnStartUpdate(const FileSystemURL& url) override {} |
| 204 virtual void OnUpdate(const FileSystemURL& url, int64 delta) override { | 200 void OnUpdate(const FileSystemURL& url, int64 delta) override { |
| 205 usage_ += delta; | 201 usage_ += delta; |
| 206 } | 202 } |
| 207 virtual void OnEndUpdate(const FileSystemURL& url) override {} | 203 void OnEndUpdate(const FileSystemURL& url) override {} |
| 208 | 204 |
| 209 private: | 205 private: |
| 210 int64 usage_; | 206 int64 usage_; |
| 211 DISALLOW_COPY_AND_ASSIGN(QuotaUtil); | 207 DISALLOW_COPY_AND_ASSIGN(QuotaUtil); |
| 212 }; | 208 }; |
| 213 | 209 |
| 214 TestFileSystemBackend::TestFileSystemBackend( | 210 TestFileSystemBackend::TestFileSystemBackend( |
| 215 base::SequencedTaskRunner* task_runner, | 211 base::SequencedTaskRunner* task_runner, |
| 216 const base::FilePath& base_path) | 212 const base::FilePath& base_path) |
| 217 : base_path_(base_path), | 213 : base_path_(base_path), |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return NULL; | 331 return NULL; |
| 336 } | 332 } |
| 337 | 333 |
| 338 void TestFileSystemBackend::AddFileChangeObserver( | 334 void TestFileSystemBackend::AddFileChangeObserver( |
| 339 storage::FileChangeObserver* observer) { | 335 storage::FileChangeObserver* observer) { |
| 340 change_observers_ = | 336 change_observers_ = |
| 341 change_observers_.AddObserver(observer, task_runner_.get()); | 337 change_observers_.AddObserver(observer, task_runner_.get()); |
| 342 } | 338 } |
| 343 | 339 |
| 344 } // namespace content | 340 } // namespace content |
| OLD | NEW |