| 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/sandbox_file_system_backend.h" | 5 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "webkit/browser/blob/file_stream_reader.h" | 13 #include "storage/browser/blob/file_stream_reader.h" |
| 14 #include "webkit/browser/fileapi/async_file_util_adapter.h" | 14 #include "storage/browser/fileapi/async_file_util_adapter.h" |
| 15 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | 15 #include "storage/browser/fileapi/copy_or_move_file_validator.h" |
| 16 #include "webkit/browser/fileapi/file_stream_writer.h" | 16 #include "storage/browser/fileapi/file_stream_writer.h" |
| 17 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "storage/browser/fileapi/file_system_context.h" |
| 18 #include "webkit/browser/fileapi/file_system_operation.h" | 18 #include "storage/browser/fileapi/file_system_operation.h" |
| 19 #include "webkit/browser/fileapi/file_system_operation_context.h" | 19 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 20 #include "webkit/browser/fileapi/file_system_options.h" | 20 #include "storage/browser/fileapi/file_system_options.h" |
| 21 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 21 #include "storage/browser/fileapi/file_system_usage_cache.h" |
| 22 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 22 #include "storage/browser/fileapi/obfuscated_file_util.h" |
| 23 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" | 23 #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h" |
| 24 #include "webkit/browser/fileapi/sandbox_quota_observer.h" | 24 #include "storage/browser/fileapi/sandbox_quota_observer.h" |
| 25 #include "webkit/browser/quota/quota_manager.h" | 25 #include "storage/browser/quota/quota_manager.h" |
| 26 #include "webkit/common/fileapi/file_system_types.h" | 26 #include "storage/common/fileapi/file_system_types.h" |
| 27 #include "webkit/common/fileapi/file_system_util.h" | 27 #include "storage/common/fileapi/file_system_util.h" |
| 28 | 28 |
| 29 using quota::QuotaManagerProxy; | 29 using quota::QuotaManagerProxy; |
| 30 using quota::SpecialStoragePolicy; | 30 using quota::SpecialStoragePolicy; |
| 31 | 31 |
| 32 namespace fileapi { | 32 namespace storage { |
| 33 | 33 |
| 34 SandboxFileSystemBackend::SandboxFileSystemBackend( | 34 SandboxFileSystemBackend::SandboxFileSystemBackend( |
| 35 SandboxFileSystemBackendDelegate* delegate) | 35 SandboxFileSystemBackendDelegate* delegate) |
| 36 : delegate_(delegate), | 36 : delegate_(delegate), enable_temporary_file_system_in_incognito_(false) { |
| 37 enable_temporary_file_system_in_incognito_(false) { | |
| 38 } | 37 } |
| 39 | 38 |
| 40 SandboxFileSystemBackend::~SandboxFileSystemBackend() { | 39 SandboxFileSystemBackend::~SandboxFileSystemBackend() { |
| 41 } | 40 } |
| 42 | 41 |
| 43 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { | 42 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { |
| 44 return type == kFileSystemTypeTemporary || | 43 return type == kFileSystemTypeTemporary || type == kFileSystemTypePersistent; |
| 45 type == kFileSystemTypePersistent; | |
| 46 } | 44 } |
| 47 | 45 |
| 48 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) { | 46 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) { |
| 49 DCHECK(delegate_); | 47 DCHECK(delegate_); |
| 50 | 48 |
| 51 // Set quota observers. | 49 // Set quota observers. |
| 52 delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypeTemporary); | 50 delegate_->RegisterQuotaUpdateObserver(storage::kFileSystemTypeTemporary); |
| 53 delegate_->AddFileAccessObserver( | 51 delegate_->AddFileAccessObserver( |
| 54 fileapi::kFileSystemTypeTemporary, | 52 storage::kFileSystemTypeTemporary, delegate_->quota_observer(), NULL); |
| 55 delegate_->quota_observer(), NULL); | |
| 56 | 53 |
| 57 delegate_->RegisterQuotaUpdateObserver(fileapi::kFileSystemTypePersistent); | 54 delegate_->RegisterQuotaUpdateObserver(storage::kFileSystemTypePersistent); |
| 58 delegate_->AddFileAccessObserver( | 55 delegate_->AddFileAccessObserver( |
| 59 fileapi::kFileSystemTypePersistent, | 56 storage::kFileSystemTypePersistent, delegate_->quota_observer(), NULL); |
| 60 delegate_->quota_observer(), NULL); | |
| 61 } | 57 } |
| 62 | 58 |
| 63 void SandboxFileSystemBackend::ResolveURL( | 59 void SandboxFileSystemBackend::ResolveURL( |
| 64 const FileSystemURL& url, | 60 const FileSystemURL& url, |
| 65 OpenFileSystemMode mode, | 61 OpenFileSystemMode mode, |
| 66 const OpenFileSystemCallback& callback) { | 62 const OpenFileSystemCallback& callback) { |
| 67 DCHECK(CanHandleType(url.type())); | 63 DCHECK(CanHandleType(url.type())); |
| 68 DCHECK(delegate_); | 64 DCHECK(delegate_); |
| 69 if (delegate_->file_system_options().is_incognito() && | 65 if (delegate_->file_system_options().is_incognito() && |
| 70 !(url.type() == kFileSystemTypeTemporary && | 66 !(url.type() == kFileSystemTypeTemporary && |
| 71 enable_temporary_file_system_in_incognito_)) { | 67 enable_temporary_file_system_in_incognito_)) { |
| 72 // TODO(kinuko): return an isolated temporary directory. | 68 // TODO(kinuko): return an isolated temporary directory. |
| 73 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY); | 69 callback.Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY); |
| 74 return; | 70 return; |
| 75 } | 71 } |
| 76 | 72 |
| 77 delegate_->OpenFileSystem(url.origin(), | 73 delegate_->OpenFileSystem(url.origin(), |
| 78 url.type(), | 74 url.type(), |
| 79 mode, | 75 mode, |
| 80 callback, | 76 callback, |
| 81 GetFileSystemRootURI(url.origin(), url.type())); | 77 GetFileSystemRootURI(url.origin(), url.type())); |
| 82 } | 78 } |
| 83 | 79 |
| 84 AsyncFileUtil* SandboxFileSystemBackend::GetAsyncFileUtil( | 80 AsyncFileUtil* SandboxFileSystemBackend::GetAsyncFileUtil(FileSystemType type) { |
| 85 FileSystemType type) { | |
| 86 DCHECK(delegate_); | 81 DCHECK(delegate_); |
| 87 return delegate_->file_util(); | 82 return delegate_->file_util(); |
| 88 } | 83 } |
| 89 | 84 |
| 90 CopyOrMoveFileValidatorFactory* | 85 CopyOrMoveFileValidatorFactory* |
| 91 SandboxFileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 86 SandboxFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
| 92 FileSystemType type, | 87 FileSystemType type, |
| 93 base::File::Error* error_code) { | 88 base::File::Error* error_code) { |
| 94 DCHECK(error_code); | 89 DCHECK(error_code); |
| 95 *error_code = base::File::FILE_OK; | 90 *error_code = base::File::FILE_OK; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 112 SpecialStoragePolicy* policy = delegate_->special_storage_policy(); | 107 SpecialStoragePolicy* policy = delegate_->special_storage_policy(); |
| 113 if (policy && policy->IsStorageUnlimited(url.origin())) | 108 if (policy && policy->IsStorageUnlimited(url.origin())) |
| 114 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); | 109 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); |
| 115 else | 110 else |
| 116 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); | 111 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); |
| 117 | 112 |
| 118 return FileSystemOperation::Create(url, context, operation_context.Pass()); | 113 return FileSystemOperation::Create(url, context, operation_context.Pass()); |
| 119 } | 114 } |
| 120 | 115 |
| 121 bool SandboxFileSystemBackend::SupportsStreaming( | 116 bool SandboxFileSystemBackend::SupportsStreaming( |
| 122 const fileapi::FileSystemURL& url) const { | 117 const storage::FileSystemURL& url) const { |
| 123 return false; | 118 return false; |
| 124 } | 119 } |
| 125 | 120 |
| 126 scoped_ptr<webkit_blob::FileStreamReader> | 121 scoped_ptr<storage::FileStreamReader> |
| 127 SandboxFileSystemBackend::CreateFileStreamReader( | 122 SandboxFileSystemBackend::CreateFileStreamReader( |
| 128 const FileSystemURL& url, | 123 const FileSystemURL& url, |
| 129 int64 offset, | 124 int64 offset, |
| 130 const base::Time& expected_modification_time, | 125 const base::Time& expected_modification_time, |
| 131 FileSystemContext* context) const { | 126 FileSystemContext* context) const { |
| 132 DCHECK(CanHandleType(url.type())); | 127 DCHECK(CanHandleType(url.type())); |
| 133 DCHECK(delegate_); | 128 DCHECK(delegate_); |
| 134 return delegate_->CreateFileStreamReader( | 129 return delegate_->CreateFileStreamReader( |
| 135 url, offset, expected_modification_time, context); | 130 url, offset, expected_modification_time, context); |
| 136 } | 131 } |
| 137 | 132 |
| 138 scoped_ptr<fileapi::FileStreamWriter> | 133 scoped_ptr<storage::FileStreamWriter> |
| 139 SandboxFileSystemBackend::CreateFileStreamWriter( | 134 SandboxFileSystemBackend::CreateFileStreamWriter( |
| 140 const FileSystemURL& url, | 135 const FileSystemURL& url, |
| 141 int64 offset, | 136 int64 offset, |
| 142 FileSystemContext* context) const { | 137 FileSystemContext* context) const { |
| 143 DCHECK(CanHandleType(url.type())); | 138 DCHECK(CanHandleType(url.type())); |
| 144 DCHECK(delegate_); | 139 DCHECK(delegate_); |
| 145 return delegate_->CreateFileStreamWriter(url, offset, context, url.type()); | 140 return delegate_->CreateFileStreamWriter(url, offset, context, url.type()); |
| 146 } | 141 } |
| 147 | 142 |
| 148 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() { | 143 FileSystemQuotaUtil* SandboxFileSystemBackend::GetQuotaUtil() { |
| 149 return delegate_; | 144 return delegate_; |
| 150 } | 145 } |
| 151 | 146 |
| 152 SandboxFileSystemBackendDelegate::OriginEnumerator* | 147 SandboxFileSystemBackendDelegate::OriginEnumerator* |
| 153 SandboxFileSystemBackend::CreateOriginEnumerator() { | 148 SandboxFileSystemBackend::CreateOriginEnumerator() { |
| 154 DCHECK(delegate_); | 149 DCHECK(delegate_); |
| 155 return delegate_->CreateOriginEnumerator(); | 150 return delegate_->CreateOriginEnumerator(); |
| 156 } | 151 } |
| 157 | 152 |
| 158 } // namespace fileapi | 153 } // namespace storage |
| OLD | NEW |