Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: content/public/test/test_file_system_backend.cc

Issue 137923003: Change fileapi namespace to content for files that are moved under content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
13 #include "webkit/browser/blob/file_stream_reader.h" 13 #include "webkit/browser/blob/file_stream_reader.h"
14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
15 #include "webkit/browser/fileapi/file_observers.h" 15 #include "webkit/browser/fileapi/file_observers.h"
16 #include "webkit/browser/fileapi/file_system_operation.h" 16 #include "webkit/browser/fileapi/file_system_operation.h"
17 #include "webkit/browser/fileapi/file_system_operation_context.h" 17 #include "webkit/browser/fileapi/file_system_operation_context.h"
18 #include "webkit/browser/fileapi/file_system_quota_util.h" 18 #include "webkit/browser/fileapi/file_system_quota_util.h"
19 #include "webkit/browser/fileapi/local_file_util.h" 19 #include "webkit/browser/fileapi/local_file_util.h"
20 #include "webkit/browser/fileapi/native_file_util.h" 20 #include "webkit/browser/fileapi/native_file_util.h"
21 #include "webkit/browser/fileapi/quota/quota_reservation.h" 21 #include "webkit/browser/fileapi/quota/quota_reservation.h"
22 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" 22 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h"
23 #include "webkit/browser/quota/quota_manager.h" 23 #include "webkit/browser/quota/quota_manager.h"
24 #include "webkit/common/fileapi/file_system_util.h" 24 #include "webkit/common/fileapi/file_system_util.h"
25 25
26 namespace fileapi { 26 using fileapi::FileSystemContext;
27 using fileapi::FileSystemOperation;
28 using fileapi::FileSystemOperationContext;
29 using fileapi::FileSystemType;
30 using fileapi::FileSystemURL;
31
32 namespace content {
27 33
28 namespace { 34 namespace {
29 35
30 class TestFileUtil : public LocalFileUtil { 36 class TestFileUtil : public fileapi::LocalFileUtil {
31 public: 37 public:
32 explicit TestFileUtil(const base::FilePath& base_path) 38 explicit TestFileUtil(const base::FilePath& base_path)
33 : base_path_(base_path) {} 39 : base_path_(base_path) {}
34 virtual ~TestFileUtil() {} 40 virtual ~TestFileUtil() {}
35 41
36 // LocalFileUtil overrides. 42 // LocalFileUtil overrides.
37 virtual base::PlatformFileError GetLocalFilePath( 43 virtual base::PlatformFileError GetLocalFilePath(
38 FileSystemOperationContext* context, 44 FileSystemOperationContext* context,
39 const FileSystemURL& file_system_url, 45 const FileSystemURL& file_system_url,
40 base::FilePath* local_file_path) OVERRIDE { 46 base::FilePath* local_file_path) OVERRIDE {
41 *local_file_path = base_path_.Append(file_system_url.path()); 47 *local_file_path = base_path_.Append(file_system_url.path());
42 return base::PLATFORM_FILE_OK; 48 return base::PLATFORM_FILE_OK;
43 } 49 }
44 50
45 private: 51 private:
46 base::FilePath base_path_; 52 base::FilePath base_path_;
47 }; 53 };
48 54
49 } // namespace 55 } // namespace
50 56
51 // This only supports single origin. 57 // This only supports single origin.
52 class TestFileSystemBackend::QuotaUtil 58 class TestFileSystemBackend::QuotaUtil
53 : public FileSystemQuotaUtil, 59 : public fileapi::FileSystemQuotaUtil,
54 public FileUpdateObserver { 60 public fileapi::FileUpdateObserver {
55 public: 61 public:
56 explicit QuotaUtil(base::SequencedTaskRunner* task_runner) 62 explicit QuotaUtil(base::SequencedTaskRunner* task_runner)
57 : usage_(0), 63 : usage_(0),
58 task_runner_(task_runner) { 64 task_runner_(task_runner) {
59 update_observers_ = update_observers_.AddObserver(this, task_runner_.get()); 65 update_observers_ = update_observers_.AddObserver(this, task_runner_.get());
60 } 66 }
61 virtual ~QuotaUtil() {} 67 virtual ~QuotaUtil() {}
62 68
63 // FileSystemQuotaUtil overrides. 69 // FileSystemQuotaUtil overrides.
64 virtual base::PlatformFileError DeleteOriginDataOnFileTaskRunner( 70 virtual base::PlatformFileError DeleteOriginDataOnFileTaskRunner(
65 FileSystemContext* context, 71 FileSystemContext* context,
66 quota::QuotaManagerProxy* proxy, 72 quota::QuotaManagerProxy* proxy,
67 const GURL& origin_url, 73 const GURL& origin_url,
68 FileSystemType type) OVERRIDE { 74 FileSystemType type) OVERRIDE {
69 NOTREACHED(); 75 NOTREACHED();
70 return base::PLATFORM_FILE_OK; 76 return base::PLATFORM_FILE_OK;
71 } 77 }
72 78
73 virtual scoped_refptr<QuotaReservation> 79 virtual scoped_refptr<fileapi::QuotaReservation>
74 CreateQuotaReservationOnFileTaskRunner( 80 CreateQuotaReservationOnFileTaskRunner(
75 const GURL& origin_url, 81 const GURL& origin_url,
76 FileSystemType type) OVERRIDE { 82 FileSystemType type) OVERRIDE {
77 NOTREACHED(); 83 NOTREACHED();
78 return scoped_refptr<QuotaReservation>(); 84 return scoped_refptr<fileapi::QuotaReservation>();
79 } 85 }
80 86
81 virtual void GetOriginsForTypeOnFileTaskRunner( 87 virtual void GetOriginsForTypeOnFileTaskRunner(
82 FileSystemType type, 88 FileSystemType type,
83 std::set<GURL>* origins) OVERRIDE { 89 std::set<GURL>* origins) OVERRIDE {
84 NOTREACHED(); 90 NOTREACHED();
85 } 91 }
86 92
87 virtual void GetOriginsForHostOnFileTaskRunner( 93 virtual void GetOriginsForHostOnFileTaskRunner(
88 FileSystemType type, 94 FileSystemType type,
(...skipping 11 matching lines...) Expand all
100 106
101 virtual void AddFileUpdateObserver( 107 virtual void AddFileUpdateObserver(
102 FileSystemType type, 108 FileSystemType type,
103 FileUpdateObserver* observer, 109 FileUpdateObserver* observer,
104 base::SequencedTaskRunner* task_runner) OVERRIDE { 110 base::SequencedTaskRunner* task_runner) OVERRIDE {
105 NOTIMPLEMENTED(); 111 NOTIMPLEMENTED();
106 } 112 }
107 113
108 virtual void AddFileChangeObserver( 114 virtual void AddFileChangeObserver(
109 FileSystemType type, 115 FileSystemType type,
110 FileChangeObserver* observer, 116 fileapi::FileChangeObserver* observer,
111 base::SequencedTaskRunner* task_runner) OVERRIDE { 117 base::SequencedTaskRunner* task_runner) OVERRIDE {
112 change_observers_ = change_observers_.AddObserver(observer, task_runner); 118 change_observers_ = change_observers_.AddObserver(observer, task_runner);
113 } 119 }
114 120
115 virtual void AddFileAccessObserver( 121 virtual void AddFileAccessObserver(
116 FileSystemType type, 122 FileSystemType type,
117 FileAccessObserver* observer, 123 fileapi::FileAccessObserver* observer,
118 base::SequencedTaskRunner* task_runner) OVERRIDE { 124 base::SequencedTaskRunner* task_runner) OVERRIDE {
119 NOTIMPLEMENTED(); 125 NOTIMPLEMENTED();
120 } 126 }
121 127
122 virtual const UpdateObserverList* GetUpdateObservers( 128 virtual const fileapi::UpdateObserverList* GetUpdateObservers(
123 FileSystemType type) const OVERRIDE { 129 FileSystemType type) const OVERRIDE {
124 return &update_observers_; 130 return &update_observers_;
125 } 131 }
126 132
127 virtual const ChangeObserverList* GetChangeObservers( 133 virtual const fileapi::ChangeObserverList* GetChangeObservers(
128 FileSystemType type) const OVERRIDE { 134 FileSystemType type) const OVERRIDE {
129 return &change_observers_; 135 return &change_observers_;
130 } 136 }
131 137
132 virtual const AccessObserverList* GetAccessObservers( 138 virtual const fileapi::AccessObserverList* GetAccessObservers(
133 FileSystemType type) const OVERRIDE { 139 FileSystemType type) const OVERRIDE {
134 NOTIMPLEMENTED(); 140 NOTIMPLEMENTED();
135 return NULL; 141 return NULL;
136 } 142 }
137 143
138 // FileUpdateObserver overrides. 144 // FileUpdateObserver overrides.
139 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {} 145 virtual void OnStartUpdate(const FileSystemURL& url) OVERRIDE {}
140 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE { 146 virtual void OnUpdate(const FileSystemURL& url, int64 delta) OVERRIDE {
141 usage_ += delta; 147 usage_ += delta;
142 } 148 }
143 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {} 149 virtual void OnEndUpdate(const FileSystemURL& url) OVERRIDE {}
144 150
145 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); } 151 base::SequencedTaskRunner* task_runner() { return task_runner_.get(); }
146 152
147 private: 153 private:
148 int64 usage_; 154 int64 usage_;
149 155
150 scoped_refptr<base::SequencedTaskRunner> task_runner_; 156 scoped_refptr<base::SequencedTaskRunner> task_runner_;
151 157
152 UpdateObserverList update_observers_; 158 fileapi::UpdateObserverList update_observers_;
153 ChangeObserverList change_observers_; 159 fileapi::ChangeObserverList change_observers_;
154 }; 160 };
155 161
156 TestFileSystemBackend::TestFileSystemBackend( 162 TestFileSystemBackend::TestFileSystemBackend(
157 base::SequencedTaskRunner* task_runner, 163 base::SequencedTaskRunner* task_runner,
158 const base::FilePath& base_path) 164 const base::FilePath& base_path)
159 : base_path_(base_path), 165 : base_path_(base_path),
160 file_util_(new AsyncFileUtilAdapter(new TestFileUtil(base_path))), 166 file_util_(
167 new fileapi::AsyncFileUtilAdapter(new TestFileUtil(base_path))),
161 quota_util_(new QuotaUtil(task_runner)), 168 quota_util_(new QuotaUtil(task_runner)),
162 require_copy_or_move_validator_(false) { 169 require_copy_or_move_validator_(false) {
163 } 170 }
164 171
165 TestFileSystemBackend::~TestFileSystemBackend() { 172 TestFileSystemBackend::~TestFileSystemBackend() {
166 } 173 }
167 174
168 bool TestFileSystemBackend::CanHandleType(FileSystemType type) const { 175 bool TestFileSystemBackend::CanHandleType(FileSystemType type) const {
169 return (type == kFileSystemTypeTest); 176 return (type == fileapi::kFileSystemTypeTest);
170 } 177 }
171 178
172 void TestFileSystemBackend::Initialize(FileSystemContext* context) { 179 void TestFileSystemBackend::Initialize(FileSystemContext* context) {
173 } 180 }
174 181
175 void TestFileSystemBackend::OpenFileSystem( 182 void TestFileSystemBackend::OpenFileSystem(
176 const GURL& origin_url, 183 const GURL& origin_url,
177 FileSystemType type, 184 FileSystemType type,
178 OpenFileSystemMode mode, 185 fileapi::OpenFileSystemMode mode,
179 const OpenFileSystemCallback& callback) { 186 const OpenFileSystemCallback& callback) {
180 callback.Run(GetFileSystemRootURI(origin_url, type), 187 callback.Run(GetFileSystemRootURI(origin_url, type),
181 GetFileSystemName(origin_url, type), 188 GetFileSystemName(origin_url, type),
182 base::PLATFORM_FILE_OK); 189 base::PLATFORM_FILE_OK);
183 } 190 }
184 191
185 AsyncFileUtil* TestFileSystemBackend::GetAsyncFileUtil(FileSystemType type) { 192 fileapi::AsyncFileUtil* TestFileSystemBackend::GetAsyncFileUtil(
193 FileSystemType type) {
186 return file_util_.get(); 194 return file_util_.get();
187 } 195 }
188 196
189 CopyOrMoveFileValidatorFactory* 197 fileapi::CopyOrMoveFileValidatorFactory*
190 TestFileSystemBackend::GetCopyOrMoveFileValidatorFactory( 198 TestFileSystemBackend::GetCopyOrMoveFileValidatorFactory(
191 FileSystemType type, base::PlatformFileError* error_code) { 199 FileSystemType type, base::PlatformFileError* error_code) {
192 DCHECK(error_code); 200 DCHECK(error_code);
193 *error_code = base::PLATFORM_FILE_OK; 201 *error_code = base::PLATFORM_FILE_OK;
194 if (require_copy_or_move_validator_) { 202 if (require_copy_or_move_validator_) {
195 if (!copy_or_move_file_validator_factory_) 203 if (!copy_or_move_file_validator_factory_)
196 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; 204 *error_code = base::PLATFORM_FILE_ERROR_SECURITY;
197 return copy_or_move_file_validator_factory_.get(); 205 return copy_or_move_file_validator_factory_.get();
198 } 206 }
199 return NULL; 207 return NULL;
200 } 208 }
201 209
202 void TestFileSystemBackend::InitializeCopyOrMoveFileValidatorFactory( 210 void TestFileSystemBackend::InitializeCopyOrMoveFileValidatorFactory(
203 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { 211 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory) {
204 if (!copy_or_move_file_validator_factory_) 212 if (!copy_or_move_file_validator_factory_)
205 copy_or_move_file_validator_factory_ = factory.Pass(); 213 copy_or_move_file_validator_factory_ = factory.Pass();
206 } 214 }
207 215
208 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation( 216 FileSystemOperation* TestFileSystemBackend::CreateFileSystemOperation(
209 const FileSystemURL& url, 217 const FileSystemURL& url,
210 FileSystemContext* context, 218 FileSystemContext* context,
211 base::PlatformFileError* error_code) const { 219 base::PlatformFileError* error_code) const {
212 scoped_ptr<FileSystemOperationContext> operation_context( 220 scoped_ptr<FileSystemOperationContext> operation_context(
213 new FileSystemOperationContext(context)); 221 new FileSystemOperationContext(context));
(...skipping 13 matching lines...) Expand all
227 webkit_blob::FileStreamReader::CreateForFileSystemFile( 235 webkit_blob::FileStreamReader::CreateForFileSystemFile(
228 context, url, offset, expected_modification_time)); 236 context, url, offset, expected_modification_time));
229 } 237 }
230 238
231 scoped_ptr<fileapi::FileStreamWriter> 239 scoped_ptr<fileapi::FileStreamWriter>
232 TestFileSystemBackend::CreateFileStreamWriter( 240 TestFileSystemBackend::CreateFileStreamWriter(
233 const FileSystemURL& url, 241 const FileSystemURL& url,
234 int64 offset, 242 int64 offset,
235 FileSystemContext* context) const { 243 FileSystemContext* context) const {
236 return scoped_ptr<fileapi::FileStreamWriter>( 244 return scoped_ptr<fileapi::FileStreamWriter>(
237 new SandboxFileStreamWriter(context, url, offset, 245 new fileapi::SandboxFileStreamWriter(context, url, offset,
238 *GetUpdateObservers(url.type()))); 246 *GetUpdateObservers(url.type())));
239 } 247 }
240 248
241 FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() { 249 fileapi::FileSystemQuotaUtil* TestFileSystemBackend::GetQuotaUtil() {
242 return quota_util_.get(); 250 return quota_util_.get();
243 } 251 }
244 252
245 const UpdateObserverList* TestFileSystemBackend::GetUpdateObservers( 253 const fileapi::UpdateObserverList* TestFileSystemBackend::GetUpdateObservers(
246 FileSystemType type) const { 254 FileSystemType type) const {
247 return quota_util_->GetUpdateObservers(type); 255 return quota_util_->GetUpdateObservers(type);
248 } 256 }
249 257
250 void TestFileSystemBackend::AddFileChangeObserver( 258 void TestFileSystemBackend::AddFileChangeObserver(
251 FileChangeObserver* observer) { 259 fileapi::FileChangeObserver* observer) {
252 quota_util_->AddFileChangeObserver( 260 quota_util_->AddFileChangeObserver(
253 kFileSystemTypeTest, observer, quota_util_->task_runner()); 261 fileapi::kFileSystemTypeTest, observer, quota_util_->task_runner());
254 } 262 }
255 263
256 } // namespace fileapi 264 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_file_system_backend.h ('k') | content/public/test/test_file_system_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698