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

Side by Side Diff: webkit/browser/fileapi/file_system_context.cc

Issue 18668003: SyncFS: Introduce SyncFileSystemBackend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lazy initialization Created 7 years, 5 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 (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/file_system_context.h" 5 #include "webkit/browser/fileapi/file_system_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
11 #include "url/gurl.h" 11 #include "url/gurl.h"
12 #include "webkit/browser/blob/file_stream_reader.h" 12 #include "webkit/browser/blob/file_stream_reader.h"
13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 13 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
14 #include "webkit/browser/fileapi/external_mount_points.h" 14 #include "webkit/browser/fileapi/external_mount_points.h"
15 #include "webkit/browser/fileapi/file_permission_policy.h" 15 #include "webkit/browser/fileapi/file_permission_policy.h"
16 #include "webkit/browser/fileapi/file_stream_writer.h" 16 #include "webkit/browser/fileapi/file_stream_writer.h"
17 #include "webkit/browser/fileapi/file_system_file_util.h" 17 #include "webkit/browser/fileapi/file_system_file_util.h"
18 #include "webkit/browser/fileapi/file_system_operation.h" 18 #include "webkit/browser/fileapi/file_system_operation.h"
19 #include "webkit/browser/fileapi/file_system_operation_runner.h" 19 #include "webkit/browser/fileapi/file_system_operation_runner.h"
20 #include "webkit/browser/fileapi/file_system_options.h" 20 #include "webkit/browser/fileapi/file_system_options.h"
21 #include "webkit/browser/fileapi/file_system_quota_client.h" 21 #include "webkit/browser/fileapi/file_system_quota_client.h"
22 #include "webkit/browser/fileapi/file_system_task_runners.h" 22 #include "webkit/browser/fileapi/file_system_task_runners.h"
23 #include "webkit/browser/fileapi/file_system_url.h" 23 #include "webkit/browser/fileapi/file_system_url.h"
24 #include "webkit/browser/fileapi/isolated_context.h" 24 #include "webkit/browser/fileapi/isolated_context.h"
25 #include "webkit/browser/fileapi/isolated_file_system_backend.h" 25 #include "webkit/browser/fileapi/isolated_file_system_backend.h"
26 #include "webkit/browser/fileapi/mount_points.h" 26 #include "webkit/browser/fileapi/mount_points.h"
27 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" 27 #include "webkit/browser/fileapi/sandbox_file_system_backend.h"
28 #include "webkit/browser/fileapi/syncable/local_file_change_tracker.h"
29 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h"
30 #include "webkit/browser/fileapi/test_file_system_backend.h" 28 #include "webkit/browser/fileapi/test_file_system_backend.h"
31 #include "webkit/browser/quota/quota_manager.h" 29 #include "webkit/browser/quota/quota_manager.h"
32 #include "webkit/browser/quota/special_storage_policy.h" 30 #include "webkit/browser/quota/special_storage_policy.h"
33 #include "webkit/common/fileapi/file_system_util.h" 31 #include "webkit/common/fileapi/file_system_util.h"
34 32
35 using quota::QuotaClient; 33 using quota::QuotaClient;
36 34
37 namespace fileapi { 35 namespace fileapi {
38 36
39 namespace { 37 namespace {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 const FileSystemOptions& options) 107 const FileSystemOptions& options)
110 : task_runners_(task_runners.Pass()), 108 : task_runners_(task_runners.Pass()),
111 quota_manager_proxy_(quota_manager_proxy), 109 quota_manager_proxy_(quota_manager_proxy),
112 sandbox_context_(new SandboxContext( 110 sandbox_context_(new SandboxContext(
113 quota_manager_proxy, 111 quota_manager_proxy,
114 task_runners_->file_task_runner(), 112 task_runners_->file_task_runner(),
115 partition_path, 113 partition_path,
116 special_storage_policy)), 114 special_storage_policy)),
117 sandbox_backend_(new SandboxFileSystemBackend( 115 sandbox_backend_(new SandboxFileSystemBackend(
118 sandbox_context_.get(), 116 sandbox_context_.get(),
117 task_runners_->file_task_runner(),
119 options)), 118 options)),
120 isolated_backend_(new IsolatedFileSystemBackend()), 119 isolated_backend_(new IsolatedFileSystemBackend()),
121 additional_backends_(additional_backends.Pass()), 120 additional_backends_(additional_backends.Pass()),
122 external_mount_points_(external_mount_points), 121 external_mount_points_(external_mount_points),
123 partition_path_(partition_path), 122 partition_path_(partition_path),
124 operation_runner_(new FileSystemOperationRunner(this)) { 123 operation_runner_(new FileSystemOperationRunner(this)) {
125 DCHECK(task_runners_.get()); 124 DCHECK(task_runners_.get());
126 125
127 if (quota_manager_proxy) { 126 if (quota_manager_proxy) {
128 quota_manager_proxy->RegisterClient(CreateQuotaClient( 127 quota_manager_proxy->RegisterClient(CreateQuotaClient(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (!backend) 174 if (!backend)
176 return NULL; 175 return NULL;
177 return backend->GetQuotaUtil(); 176 return backend->GetQuotaUtil();
178 } 177 }
179 178
180 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil( 179 AsyncFileUtil* FileSystemContext::GetAsyncFileUtil(
181 FileSystemType type) const { 180 FileSystemType type) const {
182 FileSystemBackend* backend = GetFileSystemBackend(type); 181 FileSystemBackend* backend = GetFileSystemBackend(type);
183 if (!backend) 182 if (!backend)
184 return NULL; 183 return NULL;
185 return backend->GetAsyncFileUtil(type); 184 return backend->GetAsyncFileUtil(type, this);
186 } 185 }
187 186
188 FileSystemFileUtil* FileSystemContext::GetFileUtil( 187 FileSystemFileUtil* FileSystemContext::GetFileUtil(
189 FileSystemType type) const { 188 FileSystemType type) const {
190 FileSystemBackend* backend = GetFileSystemBackend(type); 189 FileSystemBackend* backend = GetFileSystemBackend(type);
191 if (!backend) 190 if (!backend)
192 return NULL; 191 return NULL;
193 return backend->GetFileUtil(type); 192 return backend->GetFileUtil(type, this);
194 } 193 }
195 194
196 CopyOrMoveFileValidatorFactory* 195 CopyOrMoveFileValidatorFactory*
197 FileSystemContext::GetCopyOrMoveFileValidatorFactory( 196 FileSystemContext::GetCopyOrMoveFileValidatorFactory(
198 FileSystemType type, base::PlatformFileError* error_code) const { 197 FileSystemType type, base::PlatformFileError* error_code) const {
199 DCHECK(error_code); 198 DCHECK(error_code);
200 *error_code = base::PLATFORM_FILE_OK; 199 *error_code = base::PLATFORM_FILE_OK;
201 FileSystemBackend* backend = GetFileSystemBackend(type); 200 FileSystemBackend* backend = GetFileSystemBackend(type);
202 if (!backend) 201 if (!backend)
203 return NULL; 202 return NULL;
204 return backend->GetCopyOrMoveFileValidatorFactory( 203 return backend->GetCopyOrMoveFileValidatorFactory(
205 type, error_code); 204 type, error_code);
206 } 205 }
207 206
208 FileSystemBackend* FileSystemContext::GetFileSystemBackend( 207 FileSystemBackend* FileSystemContext::GetFileSystemBackend(
209 FileSystemType type) const { 208 FileSystemType type) const {
210 FileSystemBackendMap::const_iterator found = backend_map_.find(type); 209 FileSystemBackendMap::const_iterator found = backend_map_.find(type);
211 if (found != backend_map_.end()) 210 if (found != backend_map_.end())
212 return found->second; 211 return found->second;
213 NOTREACHED() << "Unknown filesystem type: " << type; 212 NOTREACHED() << "Unknown filesystem type: " << type;
214 return NULL; 213 return NULL;
215 } 214 }
216 215
217 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { 216 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const {
218 return GetQuotaUtil(type) != NULL; 217 return GetQuotaUtil(type) != NULL;
219 } 218 }
220 219
221 const UpdateObserverList* FileSystemContext::GetUpdateObservers( 220 const UpdateObserverList* FileSystemContext::GetUpdateObservers(
222 FileSystemType type) const { 221 FileSystemType type) const {
223 // Currently update observer is only available in SandboxFileSystemBackend 222 // Currently update observer is only available in SandboxFileSystemBackend,
224 // and TestFileSystemBackend. 223 // SyncFileSystemBackend and TestFileSystemBackend.
225 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be
226 // added to FileSystemBackend interface and be called like
227 // other GetFoo() methods do.
228 if (sandbox_backend_->CanHandleType(type)) 224 if (sandbox_backend_->CanHandleType(type))
229 return sandbox_backend_->GetUpdateObservers(type); 225 return sandbox_backend_->GetUpdateObservers(type);
230 if (type != kFileSystemTypeTest)
231 return NULL;
232 FileSystemBackend* backend = GetFileSystemBackend(type); 226 FileSystemBackend* backend = GetFileSystemBackend(type);
233 return static_cast<TestFileSystemBackend*>( 227 if (type == kFileSystemTypeSyncable ||
234 backend)->GetUpdateObservers(type); 228 type == kFileSystemTypeSyncableForInternalSync) {
229 return static_cast<SandboxFileSystemBackend*>(
230 backend)->GetUpdateObservers(type);
231 }
232 if (type == kFileSystemTypeTest) {
233 return static_cast<TestFileSystemBackend*>(
234 backend)->GetUpdateObservers(type);
235 }
236 return NULL;
235 } 237 }
236 238
237 const AccessObserverList* FileSystemContext::GetAccessObservers( 239 const AccessObserverList* FileSystemContext::GetAccessObservers(
238 FileSystemType type) const { 240 FileSystemType type) const {
239 // Currently access observer is only available in SandboxFileSystemBackend. 241 // Currently access observer is only available in SandboxFileSystemBackend and
242 // SyncFileSystemBackend.
240 if (sandbox_backend_->CanHandleType(type)) 243 if (sandbox_backend_->CanHandleType(type))
241 return sandbox_backend_->GetAccessObservers(type); 244 return sandbox_backend_->GetAccessObservers(type);
245 if (type == kFileSystemTypeSyncable ||
246 type == kFileSystemTypeSyncableForInternalSync) {
247 return static_cast<SandboxFileSystemBackend*>(
248 GetFileSystemBackend(type))->GetAccessObservers(type);
249 }
242 return NULL; 250 return NULL;
243 } 251 }
244 252
245 void FileSystemContext::GetFileSystemTypes( 253 void FileSystemContext::GetFileSystemTypes(
246 std::vector<FileSystemType>* types) const { 254 std::vector<FileSystemType>* types) const {
247 types->clear(); 255 types->clear();
248 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); 256 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin();
249 iter != backend_map_.end(); ++iter) 257 iter != backend_map_.end(); ++iter)
250 types->push_back(iter->first); 258 types->push_back(iter->first);
251 } 259 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 const FileSystemURL& url, 327 const FileSystemURL& url,
320 int64 offset) { 328 int64 offset) {
321 if (!url.is_valid()) 329 if (!url.is_valid())
322 return scoped_ptr<FileStreamWriter>(); 330 return scoped_ptr<FileStreamWriter>();
323 FileSystemBackend* backend = GetFileSystemBackend(url.type()); 331 FileSystemBackend* backend = GetFileSystemBackend(url.type());
324 if (!backend) 332 if (!backend)
325 return scoped_ptr<FileStreamWriter>(); 333 return scoped_ptr<FileStreamWriter>();
326 return backend->CreateFileStreamWriter(url, offset, this); 334 return backend->CreateFileStreamWriter(url, offset, this);
327 } 335 }
328 336
329 void FileSystemContext::SetLocalFileChangeTracker(
330 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) {
331 DCHECK(!change_tracker_.get());
332 DCHECK(tracker.get());
333 change_tracker_ = tracker.Pass();
334 sandbox_backend_->AddFileUpdateObserver(
335 kFileSystemTypeSyncable,
336 change_tracker_.get(),
337 task_runners_->file_task_runner());
338 sandbox_backend_->AddFileChangeObserver(
339 kFileSystemTypeSyncable,
340 change_tracker_.get(),
341 task_runners_->file_task_runner());
342 }
343
344 void FileSystemContext::set_sync_context(
345 sync_file_system::LocalFileSyncContext* sync_context) {
346 sync_context_ = sync_context;
347 }
348
349 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { 337 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const {
350 return CrackFileSystemURL(FileSystemURL(url)); 338 return CrackFileSystemURL(FileSystemURL(url));
351 } 339 }
352 340
353 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( 341 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL(
354 const GURL& origin, 342 const GURL& origin,
355 FileSystemType type, 343 FileSystemType type,
356 const base::FilePath& path) const { 344 const base::FilePath& path) const {
357 return CrackFileSystemURL(FileSystemURL(origin, type, path)); 345 return CrackFileSystemURL(FileSystemURL(origin, type, path));
358 } 346 }
359 347
360 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) 348 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD)
361 void FileSystemContext::EnableTemporaryFileSystemInIncognito() { 349 void FileSystemContext::EnableTemporaryFileSystemInIncognito() {
362 sandbox_backend_->set_enable_temporary_file_system_in_incognito(true); 350 sandbox_backend_->set_enable_temporary_file_system_in_incognito(true);
363 } 351 }
364 #endif 352 #endif
365 353
366 FileSystemContext::~FileSystemContext() { 354 FileSystemContext::~FileSystemContext() {
367 task_runners_->file_task_runner()->DeleteSoon(
368 FROM_HERE, change_tracker_.release());
369 } 355 }
370 356
371 void FileSystemContext::DeleteOnCorrectThread() const { 357 void FileSystemContext::DeleteOnCorrectThread() const {
372 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && 358 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() &&
373 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { 359 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) {
374 return; 360 return;
375 } 361 }
376 delete this; 362 delete this;
377 } 363 }
378 364
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 FileSystemType type = static_cast<FileSystemType>(t); 436 FileSystemType type = static_cast<FileSystemType>(t);
451 if (backend->CanHandleType(type)) { 437 if (backend->CanHandleType(type)) {
452 const bool inserted = backend_map_.insert( 438 const bool inserted = backend_map_.insert(
453 std::make_pair(type, backend)).second; 439 std::make_pair(type, backend)).second;
454 DCHECK(inserted); 440 DCHECK(inserted);
455 } 441 }
456 } 442 }
457 } 443 }
458 444
459 } // namespace fileapi 445 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698