| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 const FileSystemURL& url, | 319 const FileSystemURL& url, |
| 328 int64 offset) { | 320 int64 offset) { |
| 329 if (!url.is_valid()) | 321 if (!url.is_valid()) |
| 330 return scoped_ptr<FileStreamWriter>(); | 322 return scoped_ptr<FileStreamWriter>(); |
| 331 FileSystemBackend* backend = GetFileSystemBackend(url.type()); | 323 FileSystemBackend* backend = GetFileSystemBackend(url.type()); |
| 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 |
| 329 // TODO(nhiroki): Move into SyncFileSystemBackend (http://crbug.com/242422). |
| 337 void FileSystemContext::SetLocalFileChangeTracker( | 330 void FileSystemContext::SetLocalFileChangeTracker( |
| 338 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | 331 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { |
| 339 DCHECK(!change_tracker_.get()); | 332 DCHECK(!change_tracker_.get()); |
| 340 DCHECK(tracker.get()); | 333 DCHECK(tracker.get()); |
| 341 change_tracker_ = tracker.Pass(); | 334 change_tracker_ = tracker.Pass(); |
| 342 sandbox_backend_->AddFileUpdateObserver( | 335 |
| 336 FileSystemBackend* backend = GetFileSystemBackend(kFileSystemTypeSyncable); |
| 337 DCHECK(backend->GetQuotaUtil()); |
| 338 backend->GetQuotaUtil()->AddFileUpdateObserver( |
| 343 kFileSystemTypeSyncable, | 339 kFileSystemTypeSyncable, |
| 344 change_tracker_.get(), | 340 change_tracker_.get(), |
| 345 task_runners_->file_task_runner()); | 341 task_runners_->file_task_runner()); |
| 346 sandbox_backend_->AddFileChangeObserver( | 342 backend->GetQuotaUtil()->AddFileChangeObserver( |
| 347 kFileSystemTypeSyncable, | 343 kFileSystemTypeSyncable, |
| 348 change_tracker_.get(), | 344 change_tracker_.get(), |
| 349 task_runners_->file_task_runner()); | 345 task_runners_->file_task_runner()); |
| 350 } | 346 } |
| 351 | 347 |
| 348 // TODO(nhiroki): Move into SyncFileSystemBackend (http://crbug.com/242422). |
| 352 void FileSystemContext::set_sync_context( | 349 void FileSystemContext::set_sync_context( |
| 353 sync_file_system::LocalFileSyncContext* sync_context) { | 350 sync_file_system::LocalFileSyncContext* sync_context) { |
| 354 sync_context_ = sync_context; | 351 sync_context_ = sync_context; |
| 355 } | 352 } |
| 356 | 353 |
| 357 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { | 354 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { |
| 358 return CrackFileSystemURL(FileSystemURL(url)); | 355 return CrackFileSystemURL(FileSystemURL(url)); |
| 359 } | 356 } |
| 360 | 357 |
| 361 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( | 358 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 FileSystemType type = static_cast<FileSystemType>(t); | 455 FileSystemType type = static_cast<FileSystemType>(t); |
| 459 if (backend->CanHandleType(type)) { | 456 if (backend->CanHandleType(type)) { |
| 460 const bool inserted = backend_map_.insert( | 457 const bool inserted = backend_map_.insert( |
| 461 std::make_pair(type, backend)).second; | 458 std::make_pair(type, backend)).second; |
| 462 DCHECK(inserted); | 459 DCHECK(inserted); |
| 463 } | 460 } |
| 464 } | 461 } |
| 465 } | 462 } |
| 466 | 463 |
| 467 } // namespace fileapi | 464 } // namespace fileapi |
| OLD | NEW |