OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_delegate.h" | 5 #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "webkit/browser/fileapi/obfuscated_file_util.h" | 21 #include "webkit/browser/fileapi/obfuscated_file_util.h" |
22 #include "webkit/browser/fileapi/quota/quota_backend_impl.h" | 22 #include "webkit/browser/fileapi/quota/quota_backend_impl.h" |
23 #include "webkit/browser/fileapi/quota/quota_reservation.h" | 23 #include "webkit/browser/fileapi/quota/quota_reservation.h" |
24 #include "webkit/browser/fileapi/quota/quota_reservation_manager.h" | 24 #include "webkit/browser/fileapi/quota/quota_reservation_manager.h" |
25 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" | 25 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" |
26 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 26 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
27 #include "webkit/browser/fileapi/sandbox_quota_observer.h" | 27 #include "webkit/browser/fileapi/sandbox_quota_observer.h" |
28 #include "webkit/browser/quota/quota_manager_proxy.h" | 28 #include "webkit/browser/quota/quota_manager_proxy.h" |
29 #include "webkit/common/fileapi/file_system_util.h" | 29 #include "webkit/common/fileapi/file_system_util.h" |
30 | 30 |
31 namespace fileapi { | 31 namespace storage { |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; | 35 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; |
36 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; | 36 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; |
37 | 37 |
38 const char kOpenFileSystemLabel[] = "FileSystem.OpenFileSystem"; | 38 const char kOpenFileSystemLabel[] = "FileSystem.OpenFileSystem"; |
39 const char kOpenFileSystemDetailLabel[] = "FileSystem.OpenFileSystemDetail"; | 39 const char kOpenFileSystemDetailLabel[] = "FileSystem.OpenFileSystemDetail"; |
40 const char kOpenFileSystemDetailNonThrottledLabel[] = | 40 const char kOpenFileSystemDetailNonThrottledLabel[] = |
41 "FileSystem.OpenFileSystemDetailNonthrottled"; | 41 "FileSystem.OpenFileSystemDetailNonthrottled"; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 case kFileSystemTypeSyncableForInternalSync: | 163 case kFileSystemTypeSyncableForInternalSync: |
164 return kSyncableDirectoryName; | 164 return kSyncableDirectoryName; |
165 case kFileSystemTypeUnknown: | 165 case kFileSystemTypeUnknown: |
166 default: | 166 default: |
167 NOTREACHED() << "Unknown filesystem type requested:" << type; | 167 NOTREACHED() << "Unknown filesystem type requested:" << type; |
168 return std::string(); | 168 return std::string(); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate( | 172 SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate( |
173 quota::QuotaManagerProxy* quota_manager_proxy, | 173 storage::QuotaManagerProxy* quota_manager_proxy, |
174 base::SequencedTaskRunner* file_task_runner, | 174 base::SequencedTaskRunner* file_task_runner, |
175 const base::FilePath& profile_path, | 175 const base::FilePath& profile_path, |
176 quota::SpecialStoragePolicy* special_storage_policy, | 176 storage::SpecialStoragePolicy* special_storage_policy, |
177 const FileSystemOptions& file_system_options) | 177 const FileSystemOptions& file_system_options) |
178 : file_task_runner_(file_task_runner), | 178 : file_task_runner_(file_task_runner), |
179 sandbox_file_util_(new AsyncFileUtilAdapter( | 179 sandbox_file_util_(new AsyncFileUtilAdapter( |
180 new ObfuscatedFileUtil( | 180 new ObfuscatedFileUtil(special_storage_policy, |
181 special_storage_policy, | 181 profile_path.Append(kFileSystemDirectory), |
182 profile_path.Append(kFileSystemDirectory), | 182 file_system_options.env_override(), |
183 file_system_options.env_override(), | 183 file_task_runner, |
184 file_task_runner, | 184 base::Bind(&GetTypeStringForURL), |
185 base::Bind(&GetTypeStringForURL), | 185 GetKnownTypeStrings(), |
186 GetKnownTypeStrings(), | 186 this))), |
187 this))), | |
188 file_system_usage_cache_(new FileSystemUsageCache(file_task_runner)), | 187 file_system_usage_cache_(new FileSystemUsageCache(file_task_runner)), |
189 quota_observer_(new SandboxQuotaObserver( | 188 quota_observer_(new SandboxQuotaObserver(quota_manager_proxy, |
190 quota_manager_proxy, | 189 file_task_runner, |
191 file_task_runner, | 190 obfuscated_file_util(), |
192 obfuscated_file_util(), | 191 usage_cache())), |
193 usage_cache())), | |
194 quota_reservation_manager_(new QuotaReservationManager( | 192 quota_reservation_manager_(new QuotaReservationManager( |
195 scoped_ptr<QuotaReservationManager::QuotaBackend>( | 193 scoped_ptr<QuotaReservationManager::QuotaBackend>( |
196 new QuotaBackendImpl(file_task_runner_, | 194 new QuotaBackendImpl(file_task_runner_, |
197 obfuscated_file_util(), | 195 obfuscated_file_util(), |
198 usage_cache(), | 196 usage_cache(), |
199 quota_manager_proxy)))), | 197 quota_manager_proxy)))), |
200 special_storage_policy_(special_storage_policy), | 198 special_storage_policy_(special_storage_policy), |
201 file_system_options_(file_system_options), | 199 file_system_options_(file_system_options), |
202 is_filesystem_opened_(false), | 200 is_filesystem_opened_(false), |
203 weak_factory_(this) { | 201 weak_factory_(this) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 288 |
291 scoped_ptr<FileSystemOperationContext> operation_context( | 289 scoped_ptr<FileSystemOperationContext> operation_context( |
292 new FileSystemOperationContext(context)); | 290 new FileSystemOperationContext(context)); |
293 operation_context->set_update_observers(*update_observers); | 291 operation_context->set_update_observers(*update_observers); |
294 operation_context->set_change_observers( | 292 operation_context->set_change_observers( |
295 change_observers ? *change_observers : ChangeObserverList()); | 293 change_observers ? *change_observers : ChangeObserverList()); |
296 | 294 |
297 return operation_context.Pass(); | 295 return operation_context.Pass(); |
298 } | 296 } |
299 | 297 |
300 scoped_ptr<webkit_blob::FileStreamReader> | 298 scoped_ptr<storage::FileStreamReader> |
301 SandboxFileSystemBackendDelegate::CreateFileStreamReader( | 299 SandboxFileSystemBackendDelegate::CreateFileStreamReader( |
302 const FileSystemURL& url, | 300 const FileSystemURL& url, |
303 int64 offset, | 301 int64 offset, |
304 const base::Time& expected_modification_time, | 302 const base::Time& expected_modification_time, |
305 FileSystemContext* context) const { | 303 FileSystemContext* context) const { |
306 if (!IsAccessValid(url)) | 304 if (!IsAccessValid(url)) |
307 return scoped_ptr<webkit_blob::FileStreamReader>(); | 305 return scoped_ptr<storage::FileStreamReader>(); |
308 return scoped_ptr<webkit_blob::FileStreamReader>( | 306 return scoped_ptr<storage::FileStreamReader>( |
309 webkit_blob::FileStreamReader::CreateForFileSystemFile( | 307 storage::FileStreamReader::CreateForFileSystemFile( |
310 context, url, offset, expected_modification_time)); | 308 context, url, offset, expected_modification_time)); |
311 } | 309 } |
312 | 310 |
313 scoped_ptr<FileStreamWriter> | 311 scoped_ptr<FileStreamWriter> |
314 SandboxFileSystemBackendDelegate::CreateFileStreamWriter( | 312 SandboxFileSystemBackendDelegate::CreateFileStreamWriter( |
315 const FileSystemURL& url, | 313 const FileSystemURL& url, |
316 int64 offset, | 314 int64 offset, |
317 FileSystemContext* context, | 315 FileSystemContext* context, |
318 FileSystemType type) const { | 316 FileSystemType type) const { |
319 if (!IsAccessValid(url)) | 317 if (!IsAccessValid(url)) |
320 return scoped_ptr<FileStreamWriter>(); | 318 return scoped_ptr<FileStreamWriter>(); |
321 const UpdateObserverList* observers = GetUpdateObservers(type); | 319 const UpdateObserverList* observers = GetUpdateObservers(type); |
322 DCHECK(observers); | 320 DCHECK(observers); |
323 return scoped_ptr<FileStreamWriter>( | 321 return scoped_ptr<FileStreamWriter>( |
324 new SandboxFileStreamWriter(context, url, offset, *observers)); | 322 new SandboxFileStreamWriter(context, url, offset, *observers)); |
325 } | 323 } |
326 | 324 |
327 base::File::Error | 325 base::File::Error |
328 SandboxFileSystemBackendDelegate::DeleteOriginDataOnFileTaskRunner( | 326 SandboxFileSystemBackendDelegate::DeleteOriginDataOnFileTaskRunner( |
329 FileSystemContext* file_system_context, | 327 FileSystemContext* file_system_context, |
330 quota::QuotaManagerProxy* proxy, | 328 storage::QuotaManagerProxy* proxy, |
331 const GURL& origin_url, | 329 const GURL& origin_url, |
332 FileSystemType type) { | 330 FileSystemType type) { |
333 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 331 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
334 int64 usage = GetOriginUsageOnFileTaskRunner( | 332 int64 usage = GetOriginUsageOnFileTaskRunner( |
335 file_system_context, origin_url, type); | 333 file_system_context, origin_url, type); |
336 usage_cache()->CloseCacheFiles(); | 334 usage_cache()->CloseCacheFiles(); |
337 bool result = obfuscated_file_util()->DeleteDirectoryForOriginAndType( | 335 bool result = obfuscated_file_util()->DeleteDirectoryForOriginAndType( |
338 origin_url, GetTypeString(type)); | 336 origin_url, GetTypeString(type)); |
339 if (result && proxy) { | 337 if (result && proxy) { |
340 proxy->NotifyStorageModified( | 338 proxy->NotifyStorageModified(storage::QuotaClient::kFileSystem, |
341 quota::QuotaClient::kFileSystem, | 339 origin_url, |
342 origin_url, | 340 FileSystemTypeToQuotaStorageType(type), |
343 FileSystemTypeToQuotaStorageType(type), | 341 -usage); |
344 -usage); | |
345 } | 342 } |
346 | 343 |
347 if (result) | 344 if (result) |
348 return base::File::FILE_OK; | 345 return base::File::FILE_OK; |
349 return base::File::FILE_ERROR_FAILED; | 346 return base::File::FILE_ERROR_FAILED; |
350 } | 347 } |
351 | 348 |
352 void SandboxFileSystemBackendDelegate::GetOriginsForTypeOnFileTaskRunner( | 349 void SandboxFileSystemBackendDelegate::GetOriginsForTypeOnFileTaskRunner( |
353 FileSystemType type, std::set<GURL>* origins) { | 350 FileSystemType type, std::set<GURL>* origins) { |
354 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); | 351 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 #undef REPORT | 650 #undef REPORT |
654 } | 651 } |
655 | 652 |
656 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { | 653 ObfuscatedFileUtil* SandboxFileSystemBackendDelegate::obfuscated_file_util() { |
657 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); | 654 return static_cast<ObfuscatedFileUtil*>(sync_file_util()); |
658 } | 655 } |
659 | 656 |
660 // Declared in obfuscated_file_util.h. | 657 // Declared in obfuscated_file_util.h. |
661 // static | 658 // static |
662 ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting( | 659 ObfuscatedFileUtil* ObfuscatedFileUtil::CreateForTesting( |
663 quota::SpecialStoragePolicy* special_storage_policy, | 660 storage::SpecialStoragePolicy* special_storage_policy, |
664 const base::FilePath& file_system_directory, | 661 const base::FilePath& file_system_directory, |
665 leveldb::Env* env_override, | 662 leveldb::Env* env_override, |
666 base::SequencedTaskRunner* file_task_runner) { | 663 base::SequencedTaskRunner* file_task_runner) { |
667 return new ObfuscatedFileUtil(special_storage_policy, | 664 return new ObfuscatedFileUtil(special_storage_policy, |
668 file_system_directory, | 665 file_system_directory, |
669 env_override, | 666 env_override, |
670 file_task_runner, | 667 file_task_runner, |
671 base::Bind(&GetTypeStringForURL), | 668 base::Bind(&GetTypeStringForURL), |
672 GetKnownTypeStrings(), | 669 GetKnownTypeStrings(), |
673 NULL); | 670 NULL); |
674 } | 671 } |
675 | 672 |
676 } // namespace fileapi | 673 } // namespace storage |
OLD | NEW |