Chromium Code Reviews| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 quota_manager_proxy->RegisterClient(CreateQuotaClient( | 128 quota_manager_proxy->RegisterClient(CreateQuotaClient( |
| 129 this, options.is_incognito())); | 129 this, options.is_incognito())); |
| 130 } | 130 } |
| 131 | 131 |
| 132 RegisterBackend(sandbox_backend_.get()); | 132 RegisterBackend(sandbox_backend_.get()); |
| 133 RegisterBackend(isolated_backend_.get()); | 133 RegisterBackend(isolated_backend_.get()); |
| 134 | 134 |
| 135 for (ScopedVector<FileSystemBackend>::const_iterator iter = | 135 for (ScopedVector<FileSystemBackend>::const_iterator iter = |
| 136 additional_backends_.begin(); | 136 additional_backends_.begin(); |
| 137 iter != additional_backends_.end(); ++iter) { | 137 iter != additional_backends_.end(); ++iter) { |
| 138 (*iter)->Initialize(this); | |
| 138 RegisterBackend(*iter); | 139 RegisterBackend(*iter); |
|
kinuko
2013/07/23 06:41:51
I'd have another loop for Initialize after this lo
nhiroki
2013/07/24 05:58:47
Done in a separate CL.
| |
| 139 } | 140 } |
| 140 | 141 |
| 141 // Additional mount points must be added before regular system-wide | 142 // Additional mount points must be added before regular system-wide |
| 142 // mount points. | 143 // mount points. |
| 143 if (external_mount_points) | 144 if (external_mount_points) |
| 144 url_crackers_.push_back(external_mount_points); | 145 url_crackers_.push_back(external_mount_points); |
| 145 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); | 146 url_crackers_.push_back(ExternalMountPoints::GetSystemInstance()); |
| 146 url_crackers_.push_back(IsolatedContext::GetInstance()); | 147 url_crackers_.push_back(IsolatedContext::GetInstance()); |
| 147 } | 148 } |
| 148 | 149 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 NOTREACHED() << "Unknown filesystem type: " << type; | 214 NOTREACHED() << "Unknown filesystem type: " << type; |
| 214 return NULL; | 215 return NULL; |
| 215 } | 216 } |
| 216 | 217 |
| 217 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { | 218 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { |
| 218 return GetQuotaUtil(type) != NULL; | 219 return GetQuotaUtil(type) != NULL; |
| 219 } | 220 } |
| 220 | 221 |
| 221 const UpdateObserverList* FileSystemContext::GetUpdateObservers( | 222 const UpdateObserverList* FileSystemContext::GetUpdateObservers( |
| 222 FileSystemType type) const { | 223 FileSystemType type) const { |
| 223 // Currently update observer is only available in SandboxFileSystemBackend | 224 // Currently update observer is only available in SandboxFileSystemBackend, |
| 224 // and TestFileSystemBackend. | 225 // 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)) | 226 if (sandbox_backend_->CanHandleType(type)) |
| 229 return sandbox_backend_->GetUpdateObservers(type); | 227 return sandbox_backend_->GetUpdateObservers(type); |
| 230 if (type != kFileSystemTypeTest) | |
| 231 return NULL; | |
| 232 FileSystemBackend* backend = GetFileSystemBackend(type); | 228 FileSystemBackend* backend = GetFileSystemBackend(type); |
| 233 return static_cast<TestFileSystemBackend*>( | 229 if (type == kFileSystemTypeSyncable || |
| 234 backend)->GetUpdateObservers(type); | 230 type == kFileSystemTypeSyncableForInternalSync) { |
| 231 return static_cast<SandboxFileSystemBackend*>( | |
| 232 backend)->GetUpdateObservers(type); | |
| 233 } | |
| 234 if (type == kFileSystemTypeTest) { | |
| 235 return static_cast<TestFileSystemBackend*>( | |
| 236 backend)->GetUpdateObservers(type); | |
| 237 } | |
|
kinuko
2013/07/23 06:41:51
Can't this be simply written like:
if (backend->G
nhiroki
2013/07/24 05:58:47
Done.
| |
| 238 return NULL; | |
| 235 } | 239 } |
| 236 | 240 |
| 237 const AccessObserverList* FileSystemContext::GetAccessObservers( | 241 const AccessObserverList* FileSystemContext::GetAccessObservers( |
| 238 FileSystemType type) const { | 242 FileSystemType type) const { |
| 239 // Currently access observer is only available in SandboxFileSystemBackend. | 243 // Currently access observer is only available in SandboxFileSystemBackend and |
| 244 // SyncFileSystemBackend. | |
| 240 if (sandbox_backend_->CanHandleType(type)) | 245 if (sandbox_backend_->CanHandleType(type)) |
| 241 return sandbox_backend_->GetAccessObservers(type); | 246 return sandbox_backend_->GetAccessObservers(type); |
| 247 if (type == kFileSystemTypeSyncable || | |
| 248 type == kFileSystemTypeSyncableForInternalSync) { | |
| 249 return static_cast<SandboxFileSystemBackend*>( | |
| 250 GetFileSystemBackend(type))->GetAccessObservers(type); | |
| 251 } | |
|
kinuko
2013/07/23 06:41:51
ditto
nhiroki
2013/07/24 05:58:47
Done.
| |
| 242 return NULL; | 252 return NULL; |
| 243 } | 253 } |
| 244 | 254 |
| 245 void FileSystemContext::GetFileSystemTypes( | 255 void FileSystemContext::GetFileSystemTypes( |
| 246 std::vector<FileSystemType>* types) const { | 256 std::vector<FileSystemType>* types) const { |
| 247 types->clear(); | 257 types->clear(); |
| 248 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); | 258 for (FileSystemBackendMap::const_iterator iter = backend_map_.begin(); |
| 249 iter != backend_map_.end(); ++iter) | 259 iter != backend_map_.end(); ++iter) |
| 250 types->push_back(iter->first); | 260 types->push_back(iter->first); |
| 251 } | 261 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 const FileSystemURL& url, | 329 const FileSystemURL& url, |
| 320 int64 offset) { | 330 int64 offset) { |
| 321 if (!url.is_valid()) | 331 if (!url.is_valid()) |
| 322 return scoped_ptr<FileStreamWriter>(); | 332 return scoped_ptr<FileStreamWriter>(); |
| 323 FileSystemBackend* backend = GetFileSystemBackend(url.type()); | 333 FileSystemBackend* backend = GetFileSystemBackend(url.type()); |
| 324 if (!backend) | 334 if (!backend) |
| 325 return scoped_ptr<FileStreamWriter>(); | 335 return scoped_ptr<FileStreamWriter>(); |
| 326 return backend->CreateFileStreamWriter(url, offset, this); | 336 return backend->CreateFileStreamWriter(url, offset, this); |
| 327 } | 337 } |
| 328 | 338 |
| 339 // TODO(nhiroki): Move into SyncFileSystemBackend (http://crbug.com/242422). | |
| 329 void FileSystemContext::SetLocalFileChangeTracker( | 340 void FileSystemContext::SetLocalFileChangeTracker( |
| 330 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | 341 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { |
| 331 DCHECK(!change_tracker_.get()); | 342 DCHECK(!change_tracker_.get()); |
| 332 DCHECK(tracker.get()); | 343 DCHECK(tracker.get()); |
| 333 change_tracker_ = tracker.Pass(); | 344 change_tracker_ = tracker.Pass(); |
| 334 sandbox_backend_->AddFileUpdateObserver( | 345 |
| 346 SandboxFileSystemBackend* backend = | |
| 347 static_cast<SandboxFileSystemBackend*>( | |
| 348 GetFileSystemBackend(kFileSystemTypeSyncable)); | |
| 349 | |
| 350 backend->AddFileUpdateObserver( | |
| 335 kFileSystemTypeSyncable, | 351 kFileSystemTypeSyncable, |
| 336 change_tracker_.get(), | 352 change_tracker_.get(), |
| 337 task_runners_->file_task_runner()); | 353 task_runners_->file_task_runner()); |
| 338 sandbox_backend_->AddFileChangeObserver( | 354 backend->AddFileChangeObserver( |
| 339 kFileSystemTypeSyncable, | 355 kFileSystemTypeSyncable, |
| 340 change_tracker_.get(), | 356 change_tracker_.get(), |
| 341 task_runners_->file_task_runner()); | 357 task_runners_->file_task_runner()); |
| 342 } | 358 } |
| 343 | 359 |
| 360 // TODO(nhiroki): Move into SyncFileSystemBackend (http://crbug.com/242422). | |
| 344 void FileSystemContext::set_sync_context( | 361 void FileSystemContext::set_sync_context( |
| 345 sync_file_system::LocalFileSyncContext* sync_context) { | 362 sync_file_system::LocalFileSyncContext* sync_context) { |
| 346 sync_context_ = sync_context; | 363 sync_context_ = sync_context; |
| 347 } | 364 } |
| 348 | 365 |
| 349 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { | 366 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { |
| 350 return CrackFileSystemURL(FileSystemURL(url)); | 367 return CrackFileSystemURL(FileSystemURL(url)); |
| 351 } | 368 } |
| 352 | 369 |
| 353 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( | 370 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 FileSystemType type = static_cast<FileSystemType>(t); | 467 FileSystemType type = static_cast<FileSystemType>(t); |
| 451 if (backend->CanHandleType(type)) { | 468 if (backend->CanHandleType(type)) { |
| 452 const bool inserted = backend_map_.insert( | 469 const bool inserted = backend_map_.insert( |
| 453 std::make_pair(type, backend)).second; | 470 std::make_pair(type, backend)).second; |
| 454 DCHECK(inserted); | 471 DCHECK(inserted); |
| 455 } | 472 } |
| 456 } | 473 } |
| 457 } | 474 } |
| 458 | 475 |
| 459 } // namespace fileapi | 476 } // namespace fileapi |
| OLD | NEW |