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" |
| 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_mount_point_provider.h" | 25 #include "webkit/browser/fileapi/isolated_mount_point_provider.h" |
| 26 #include "webkit/browser/fileapi/mount_points.h" | 26 #include "webkit/browser/fileapi/mount_points.h" |
| 27 #include "webkit/browser/fileapi/sandbox_mount_point_provider.h" | 27 #include "webkit/browser/fileapi/sandbox_mount_point_provider.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/syncable/syncable_file_system_util.h" | |
| 31 #include "webkit/browser/fileapi/test_mount_point_provider.h" | 28 #include "webkit/browser/fileapi/test_mount_point_provider.h" |
| 32 #include "webkit/browser/quota/quota_manager.h" | 29 #include "webkit/browser/quota/quota_manager.h" |
| 33 #include "webkit/browser/quota/special_storage_policy.h" | 30 #include "webkit/browser/quota/special_storage_policy.h" |
| 34 #include "webkit/common/fileapi/file_system_util.h" | 31 #include "webkit/common/fileapi/file_system_util.h" |
| 35 | 32 |
| 36 using quota::QuotaClient; | 33 using quota::QuotaClient; |
| 37 | 34 |
| 38 namespace fileapi { | 35 namespace fileapi { |
| 39 | 36 |
| 40 namespace { | 37 namespace { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 NOTREACHED() << "Unknown filesystem type: " << type; | 214 NOTREACHED() << "Unknown filesystem type: " << type; |
| 218 return NULL; | 215 return NULL; |
| 219 } | 216 } |
| 220 | 217 |
| 221 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { | 218 bool FileSystemContext::IsSandboxFileSystem(FileSystemType type) const { |
| 222 return GetQuotaUtil(type) != NULL; | 219 return GetQuotaUtil(type) != NULL; |
| 223 } | 220 } |
| 224 | 221 |
| 225 const UpdateObserverList* FileSystemContext::GetUpdateObservers( | 222 const UpdateObserverList* FileSystemContext::GetUpdateObservers( |
| 226 FileSystemType type) const { | 223 FileSystemType type) const { |
| 227 // Currently update observer is only available in SandboxMountPointProvider | 224 return GetMountPointProvider(type)->GetUpdateObservers(type); |
| 228 // and TestMountPointProvider. | |
| 229 // TODO(kinuko): Probably GetUpdateObservers() virtual method should be | |
| 230 // added to FileSystemMountPointProvider interface and be called like | |
| 231 // other GetFoo() methods do. | |
| 232 if (sandbox_provider_->CanHandleType(type)) | |
| 233 return sandbox_provider_->GetUpdateObservers(type); | |
| 234 if (type != kFileSystemTypeTest) | |
| 235 return NULL; | |
| 236 FileSystemMountPointProvider* mount_point_provider = | |
| 237 GetMountPointProvider(type); | |
| 238 return static_cast<TestMountPointProvider*>( | |
| 239 mount_point_provider)->GetUpdateObservers(type); | |
| 240 } | 225 } |
| 241 | 226 |
| 242 const AccessObserverList* FileSystemContext::GetAccessObservers( | 227 const AccessObserverList* FileSystemContext::GetAccessObservers( |
| 243 FileSystemType type) const { | 228 FileSystemType type) const { |
| 244 // Currently access observer is only available in SandboxMountPointProvider. | 229 // Currently access observer is only available in SandboxMountPointProvider. |
| 245 if (sandbox_provider_->CanHandleType(type)) | 230 if (sandbox_provider_->CanHandleType(type)) |
| 246 return sandbox_provider_->GetAccessObservers(type); | 231 return sandbox_provider_->GetAccessObservers(type); |
| 247 return NULL; | 232 return NULL; |
| 248 } | 233 } |
| 249 | 234 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 268 const OpenFileSystemCallback& callback) { | 253 const OpenFileSystemCallback& callback) { |
| 269 DCHECK(!callback.is_null()); | 254 DCHECK(!callback.is_null()); |
| 270 | 255 |
| 271 FileSystemMountPointProvider* mount_point_provider = | 256 FileSystemMountPointProvider* mount_point_provider = |
| 272 GetMountPointProvider(type); | 257 GetMountPointProvider(type); |
| 273 if (!mount_point_provider) { | 258 if (!mount_point_provider) { |
| 274 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); | 259 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, std::string(), GURL()); |
| 275 return; | 260 return; |
| 276 } | 261 } |
| 277 | 262 |
| 278 GURL root_url; | 263 GURL root_url = mount_point_provider->GetRootURI(origin_url, type); |
|
kinuko
2013/07/08 12:31:20
Can't each mount point provider create the root_ur
nhiroki
2013/07/22 04:34:14
Done in http://crrev.com/211318/
| |
| 279 if (type == kFileSystemTypeSyncable) | |
| 280 root_url = sync_file_system::GetSyncableFileSystemRootURI(origin_url); | |
| 281 else | |
| 282 root_url = GetFileSystemRootURI(origin_url, type); | |
| 283 std::string name = GetFileSystemName(origin_url, type); | 264 std::string name = GetFileSystemName(origin_url, type); |
| 284 | 265 |
| 285 mount_point_provider->OpenFileSystem( | 266 mount_point_provider->OpenFileSystem( |
| 286 origin_url, type, mode, | 267 origin_url, type, mode, |
| 287 base::Bind(&DidOpenFileSystem, callback, root_url, name)); | 268 base::Bind(&DidOpenFileSystem, callback, root_url, name)); |
| 288 } | 269 } |
| 289 | 270 |
| 290 void FileSystemContext::DeleteFileSystem( | 271 void FileSystemContext::DeleteFileSystem( |
| 291 const GURL& origin_url, | 272 const GURL& origin_url, |
| 292 FileSystemType type, | 273 FileSystemType type, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 int64 offset) { | 317 int64 offset) { |
| 337 if (!url.is_valid()) | 318 if (!url.is_valid()) |
| 338 return scoped_ptr<FileStreamWriter>(); | 319 return scoped_ptr<FileStreamWriter>(); |
| 339 FileSystemMountPointProvider* mount_point_provider = | 320 FileSystemMountPointProvider* mount_point_provider = |
| 340 GetMountPointProvider(url.type()); | 321 GetMountPointProvider(url.type()); |
| 341 if (!mount_point_provider) | 322 if (!mount_point_provider) |
| 342 return scoped_ptr<FileStreamWriter>(); | 323 return scoped_ptr<FileStreamWriter>(); |
| 343 return mount_point_provider->CreateFileStreamWriter(url, offset, this); | 324 return mount_point_provider->CreateFileStreamWriter(url, offset, this); |
| 344 } | 325 } |
| 345 | 326 |
| 346 void FileSystemContext::SetLocalFileChangeTracker( | |
| 347 scoped_ptr<sync_file_system::LocalFileChangeTracker> tracker) { | |
| 348 DCHECK(!change_tracker_.get()); | |
| 349 DCHECK(tracker.get()); | |
| 350 change_tracker_ = tracker.Pass(); | |
| 351 sandbox_provider_->AddFileUpdateObserver( | |
| 352 kFileSystemTypeSyncable, | |
| 353 change_tracker_.get(), | |
| 354 task_runners_->file_task_runner()); | |
| 355 sandbox_provider_->AddFileChangeObserver( | |
| 356 kFileSystemTypeSyncable, | |
| 357 change_tracker_.get(), | |
| 358 task_runners_->file_task_runner()); | |
| 359 } | |
| 360 | |
| 361 void FileSystemContext::set_sync_context( | |
| 362 sync_file_system::LocalFileSyncContext* sync_context) { | |
| 363 sync_context_ = sync_context; | |
| 364 } | |
| 365 | |
| 366 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { | 327 FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { |
| 367 return CrackFileSystemURL(FileSystemURL(url)); | 328 return CrackFileSystemURL(FileSystemURL(url)); |
| 368 } | 329 } |
| 369 | 330 |
| 370 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( | 331 FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( |
| 371 const GURL& origin, | 332 const GURL& origin, |
| 372 FileSystemType type, | 333 FileSystemType type, |
| 373 const base::FilePath& path) const { | 334 const base::FilePath& path) const { |
| 374 return CrackFileSystemURL(FileSystemURL(origin, type, path)); | 335 return CrackFileSystemURL(FileSystemURL(origin, type, path)); |
| 375 } | 336 } |
| 376 | 337 |
| 377 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) | 338 #if defined(OS_CHROMEOS) && defined(GOOGLE_CHROME_BUILD) |
| 378 void FileSystemContext::EnableTemporaryFileSystemInIncognito() { | 339 void FileSystemContext::EnableTemporaryFileSystemInIncognito() { |
| 379 sandbox_provider_->set_enable_temporary_file_system_in_incognito(true); | 340 sandbox_provider_->set_enable_temporary_file_system_in_incognito(true); |
| 380 } | 341 } |
| 381 #endif | 342 #endif |
| 382 | 343 |
| 383 FileSystemContext::~FileSystemContext() { | 344 FileSystemContext::~FileSystemContext() { |
| 384 task_runners_->file_task_runner()->DeleteSoon( | |
| 385 FROM_HERE, change_tracker_.release()); | |
| 386 } | 345 } |
| 387 | 346 |
| 388 void FileSystemContext::DeleteOnCorrectThread() const { | 347 void FileSystemContext::DeleteOnCorrectThread() const { |
| 389 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && | 348 if (!task_runners_->io_task_runner()->RunsTasksOnCurrentThread() && |
| 390 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { | 349 task_runners_->io_task_runner()->DeleteSoon(FROM_HERE, this)) { |
| 391 return; | 350 return; |
| 392 } | 351 } |
| 393 delete this; | 352 delete this; |
| 394 } | 353 } |
| 395 | 354 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 FileSystemType type = static_cast<FileSystemType>(t); | 427 FileSystemType type = static_cast<FileSystemType>(t); |
| 469 if (provider->CanHandleType(type)) { | 428 if (provider->CanHandleType(type)) { |
| 470 const bool inserted = provider_map_.insert( | 429 const bool inserted = provider_map_.insert( |
| 471 std::make_pair(type, provider)).second; | 430 std::make_pair(type, provider)).second; |
| 472 DCHECK(inserted); | 431 DCHECK(inserted); |
| 473 } | 432 } |
| 474 } | 433 } |
| 475 } | 434 } |
| 476 | 435 |
| 477 } // namespace fileapi | 436 } // namespace fileapi |
| OLD | NEW |