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/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" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 NOTREACHED() << "Unknown filesystem type: " << type; | 221 NOTREACHED() << "Unknown filesystem type: " << type; |
222 return NULL; | 222 return NULL; |
223 } | 223 } |
224 | 224 |
225 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { | 225 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { |
226 return GetQuotaUtil(type) != NULL; | 226 return GetQuotaUtil(type) != NULL; |
227 } | 227 } |
228 | 228 |
229 const UpdateObserverList* FileSystemContext::GetUpdateObservers( | 229 const UpdateObserverList* FileSystemContext::GetUpdateObservers( |
230 FileSystemType type) const { | 230 FileSystemType type) const { |
231 // Currently update observer is only available in SandboxFileSystemBackend | |
232 // and TestFileSystemBackend. | |
233 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be | |
234 // added to FileSystemBackend interface and be called like | |
235 // other GetFoo() methods do. | |
236 if (sandbox_backend_->CanHandleType(type)) | |
237 return sandbox_backend_->GetUpdateObservers(type); | |
238 if (type != kFileSystemTypeTest) | |
239 return NULL; | |
240 FileSystemBackend* backend = GetFileSystemBackend(type); | 231 FileSystemBackend* backend = GetFileSystemBackend(type); |
241 return static_cast<TestFileSystemBackend*>( | 232 if (backend->GetQuotaUtil()) |
242 backend)->GetUpdateObservers(type); | 233 return backend->GetQuotaUtil()->GetUpdateObservers(type); |
| 234 return NULL; |
243 } | 235 } |
244 | 236 |
245 const AccessObserverList* FileSystemContext::GetAccessObservers( | 237 const AccessObserverList* FileSystemContext::GetAccessObservers( |
246 FileSystemType type) const { | 238 FileSystemType type) const { |
247 // Currently access observer is only available in SandboxFileSystemBackend. | 239 FileSystemBackend* backend = GetFileSystemBackend(type); |
248 if (sandbox_backend_->CanHandleType(type)) | 240 if (backend->GetQuotaUtil()) |
249 return sandbox_backend_->GetAccessObservers(type); | 241 return backend->GetQuotaUtil()->GetAccessObservers(type); |
250 return NULL; | 242 return NULL; |
251 } | 243 } |
252 | 244 |
253 void FileSystemContext::GetFileSystemTypes( | 245 void FileSystemContext::GetFileSystemTypes( |
254 std::vector<FileSystemType>* types) const { | 246 std::vector<FileSystemType>* types) const { |
255 types->clear(); | 247 types->clear(); |
256 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); | 248 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); |
257 iter != backend_map_.end(); ++iter) | 249 iter != backend_map_.end(); ++iter) |
258 types->push_back(iter->first); | 250 types->push_back(iter->first); |
259 } | 251 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 if (!backend) | 324 if (!backend) |
333 return scoped_ptr<FileStreamWriter>(); | 325 return scoped_ptr<FileStreamWriter>(); |
334 return backend->CreateFileStreamWriter(url, offset, this); | 326 return backend->CreateFileStreamWriter(url, offset, this); |
335 } | 327 } |
336 | 328 |
337 scoped_ptr<FileSystemOperationRunner> | 329 scoped_ptr<FileSystemOperationRunner> |
338 FileSystemContext::CreateFileSystemOperationRunner() { | 330 FileSystemContext::CreateFileSystemOperationRunner() { |
339 return make_scoped_ptr(new FileSystemOperationRunner(this)); | 331 return make_scoped_ptr(new FileSystemOperationRunner(this)); |
340 } | 332 } |
341 | 333 |
| 334 // TODO(nhiroki): Move into SyncFileSystemBackend (http://crbug.com/242422/). |
342 void FileSystemContext::SetLocalFileChangeTracker( | 335 void FileSystemContext::SetLocalFileChangeTracker( |
343 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | 336 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { |
344 DCHECK(!change_tracker_.get()); | 337 DCHECK(!change_tracker_.get()); |
345 DCHECK(tracker.get()); | 338 DCHECK(tracker.get()); |
346 change_tracker_ = tracker.Pass(); | 339 change_tracker_ = tracker.Pass(); |
347 sandbox_backend_->AddFileUpdateObserver( | 340 |
| 341 FileSystemBackend* backend = GetFileSystemBackend(kFileSystemTypeSyncable); |
| 342 DCHECK(backend->GetQuotaUtil()); |
| 343 backend->GetQuotaUtil()->AddFileUpdateObserver( |
348 kFileSystemTypeSyncable, | 344 kFileSystemTypeSyncable, |
349 change_tracker_.get(), | 345 change_tracker_.get(), |
350 task_runners_->file_task_runner()); | 346 task_runners_->file_task_runner()); |
351 sandbox_backend_->AddFileChangeObserver( | 347 backend->GetQuotaUtil()->AddFileChangeObserver( |
352 kFileSystemTypeSyncable, | 348 kFileSystemTypeSyncable, |
353 change_tracker_.get(), | 349 change_tracker_.get(), |
354 task_runners_->file_task_runner()); | 350 task_runners_->file_task_runner()); |
355 } | 351 } |
356 | 352 |
| 353 // TODO(nhiroki): Move into SyncFileSystemBackend (http://crbug.com/242422/). |
357 void FileSystemContext::set_sync_context( | 354 void FileSystemContext::set_sync_context( |
358 sync_file_system::LocalFileSyncContext* sync_context) { | 355 sync_file_system::LocalFileSyncContext* sync_context) { |
359 sync_context_ = sync_context; | 356 sync_context_ = sync_context; |
360 } | 357 } |
361 | 358 |
362 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { | 359 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { |
363 return CrackFileSystemURL(FileSystemURL(url)); | 360 return CrackFileSystemURL(FileSystemURL(url)); |
364 } | 361 } |
365 | 362 |
366 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( | 363 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 FileSystemType type = static_cast<FileSystemType>(t); | 460 FileSystemType type = static_cast<FileSystemType>(t); |
464 if (backend->CanHandleType(type)) { | 461 if (backend->CanHandleType(type)) { |
465 const bool inserted = backend_map_.insert( | 462 const bool inserted = backend_map_.insert( |
466 std::make_pair(type, backend)).second; | 463 std::make_pair(type, backend)).second; |
467 DCHECK(inserted); | 464 DCHECK(inserted); |
468 } | 465 } |
469 } | 466 } |
470 } | 467 } |
471 | 468 |
472 } // namespace fileapi | 469 } // namespace fileapi |
OLD | NEW |