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 "webkit/browser/fileapi/sandbox_file_system_backend.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 kIncognito, | 57 kIncognito, |
58 kInvalidSchemeError, | 58 kInvalidSchemeError, |
59 kCreateDirectoryError, | 59 kCreateDirectoryError, |
60 kNotFound, | 60 kNotFound, |
61 kUnknownError, | 61 kUnknownError, |
62 kFileSystemErrorMax, | 62 kFileSystemErrorMax, |
63 }; | 63 }; |
64 | 64 |
65 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; | 65 const char kTemporaryOriginsCountLabel[] = "FileSystem.TemporaryOriginsCount"; |
66 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; | 66 const char kPersistentOriginsCountLabel[] = "FileSystem.PersistentOriginsCount"; |
67 const char kSyncableOriginsCountLabel[] = "FileSystem.SyncableOriginsCount"; | |
68 | 67 |
69 // Restricted names. | 68 // Restricted names. |
70 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions | 69 // http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions |
71 const base::FilePath::CharType* const kRestrictedNames[] = { | 70 const base::FilePath::CharType* const kRestrictedNames[] = { |
72 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), | 71 FILE_PATH_LITERAL("."), FILE_PATH_LITERAL(".."), |
73 }; | 72 }; |
74 | 73 |
75 // Restricted chars. | 74 // Restricted chars. |
76 const base::FilePath::CharType kRestrictedChars[] = { | 75 const base::FilePath::CharType kRestrictedChars[] = { |
77 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'), | 76 FILE_PATH_LITERAL('/'), FILE_PATH_LITERAL('\\'), |
(...skipping 13 matching lines...) Expand all Loading... | |
91 | 90 |
92 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { | 91 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { |
93 return enum_->HasFileSystemType(type); | 92 return enum_->HasFileSystemType(type); |
94 } | 93 } |
95 | 94 |
96 private: | 95 private: |
97 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; | 96 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; |
98 }; | 97 }; |
99 | 98 |
100 void DidOpenFileSystem( | 99 void DidOpenFileSystem( |
101 base::WeakPtr<SandboxFileSystemBackend> mount_point_provider, | 100 base::WeakPtr<SandboxFileSystemBackend> file_system_backend, |
102 const base::Callback<void(base::PlatformFileError error)>& callback, | 101 const base::Callback<void(base::PlatformFileError error)>& callback, |
103 base::PlatformFileError* error) { | 102 base::PlatformFileError* error) { |
104 if (mount_point_provider.get()) | 103 if (file_system_backend.get()) |
105 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); | 104 file_system_backend.get()->CollectOpenFileSystemMetrics(*error); |
106 callback.Run(*error); | 105 callback.Run(*error); |
107 } | 106 } |
108 | 107 |
109 void OpenFileSystemOnFileThread( | 108 void OpenFileSystemOnFileThread( |
110 ObfuscatedFileUtil* file_util, | 109 ObfuscatedFileUtil* file_util, |
111 const GURL& origin_url, | 110 const GURL& origin_url, |
112 FileSystemType type, | 111 FileSystemType type, |
113 OpenFileSystemMode mode, | 112 OpenFileSystemMode mode, |
114 base::PlatformFileError* error_ptr) { | 113 base::PlatformFileError* error_ptr) { |
115 DCHECK(error_ptr); | 114 DCHECK(error_ptr); |
(...skipping 19 matching lines...) Expand all Loading... | |
135 SandboxFileSystemBackend::SandboxFileSystemBackend( | 134 SandboxFileSystemBackend::SandboxFileSystemBackend( |
136 SandboxContext* sandbox_context, | 135 SandboxContext* sandbox_context, |
137 const FileSystemOptions& file_system_options) | 136 const FileSystemOptions& file_system_options) |
138 : file_system_options_(file_system_options), | 137 : file_system_options_(file_system_options), |
139 sandbox_context_(sandbox_context), | 138 sandbox_context_(sandbox_context), |
140 enable_temporary_file_system_in_incognito_(false), | 139 enable_temporary_file_system_in_incognito_(false), |
141 enable_usage_tracking_( | 140 enable_usage_tracking_( |
142 !CommandLine::ForCurrentProcess()->HasSwitch( | 141 !CommandLine::ForCurrentProcess()->HasSwitch( |
143 kDisableUsageTracking)), | 142 kDisableUsageTracking)), |
144 weak_factory_(this) { | 143 weak_factory_(this) { |
144 // SyncFileSystemBackend is instantiated with null context. | |
145 if (!sandbox_context) | |
146 return; | |
147 | |
145 // Set quota observers. | 148 // Set quota observers. |
146 if (enable_usage_tracking_) { | 149 if (enable_usage_tracking_) { |
147 update_observers_ = update_observers_.AddObserver( | 150 update_observers_ = update_observers_.AddObserver( |
148 sandbox_context_->quota_observer(), | 151 sandbox_context_->quota_observer(), |
149 sandbox_context_->file_task_runner()); | 152 sandbox_context_->file_task_runner()); |
150 access_observers_ = access_observers_.AddObserver( | 153 access_observers_ = access_observers_.AddObserver( |
151 sandbox_context_->quota_observer(), NULL); | 154 sandbox_context_->quota_observer(), NULL); |
152 } | 155 } |
153 | 156 |
154 syncable_update_observers_ = update_observers_; | |
155 | |
156 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { | 157 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { |
157 // Post prepopulate task only if it's not already running on | 158 // Post prepopulate task only if it's not already running on |
158 // file_task_runner (which implies running in tests). | 159 // file_task_runner (which implies running in tests). |
159 sandbox_context_->file_task_runner()->PostTask( | 160 sandbox_context_->file_task_runner()->PostTask( |
160 FROM_HERE, | 161 FROM_HERE, |
161 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, | 162 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, |
162 base::Unretained(sandbox_sync_file_util()))); | 163 base::Unretained(sandbox_sync_file_util()))); |
163 } | 164 } |
kinuko
2013/07/23 06:41:51
It'd be more consistent to move all sandbox_contex
nhiroki
2013/07/24 05:58:47
Done in the separate CL.
| |
164 } | 165 } |
165 | 166 |
166 SandboxFileSystemBackend::~SandboxFileSystemBackend() { | 167 SandboxFileSystemBackend::~SandboxFileSystemBackend() { |
167 } | 168 } |
168 | 169 |
169 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { | 170 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { |
170 return type == kFileSystemTypeTemporary || | 171 return type == kFileSystemTypeTemporary || |
171 type == kFileSystemTypePersistent || | 172 type == kFileSystemTypePersistent; |
172 type == kFileSystemTypeSyncable || | 173 } |
173 type == kFileSystemTypeSyncableForInternalSync; | 174 |
175 void SandboxFileSystemBackend::Initialize(const FileSystemContext* context) { | |
174 } | 176 } |
175 | 177 |
176 void SandboxFileSystemBackend::InitializeFileSystem( | 178 void SandboxFileSystemBackend::InitializeFileSystem( |
177 const GURL& origin_url, | 179 const GURL& origin_url, |
178 fileapi::FileSystemType type, | 180 fileapi::FileSystemType type, |
179 OpenFileSystemMode mode, | 181 OpenFileSystemMode mode, |
180 FileSystemContext* context, | 182 FileSystemContext* context, |
181 const InitializeFileSystemCallback& callback) { | 183 const InitializeFileSystemCallback& callback) { |
182 if (file_system_options_.is_incognito() && | 184 if (file_system_options_.is_incognito() && |
183 !(type == kFileSystemTypeTemporary && | 185 !(type == kFileSystemTypeTemporary && |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 const FileSystemURL& url, | 255 const FileSystemURL& url, |
254 FileSystemContext* context, | 256 FileSystemContext* context, |
255 base::PlatformFileError* error_code) const { | 257 base::PlatformFileError* error_code) const { |
256 if (!IsAccessValid(url)) { | 258 if (!IsAccessValid(url)) { |
257 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 259 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
258 return NULL; | 260 return NULL; |
259 } | 261 } |
260 | 262 |
261 scoped_ptr<FileSystemOperationContext> operation_context( | 263 scoped_ptr<FileSystemOperationContext> operation_context( |
262 new FileSystemOperationContext(context)); | 264 new FileSystemOperationContext(context)); |
263 | |
264 // Copy the observer lists (assuming we only have small number of observers). | |
265 if (url.type() == kFileSystemTypeSyncable) { | |
266 operation_context->set_update_observers(syncable_update_observers_); | |
267 operation_context->set_change_observers(syncable_change_observers_); | |
268 return new sync_file_system::SyncableFileSystemOperation( | |
269 url, context, operation_context.Pass()); | |
270 } | |
271 | |
272 // For regular sandboxed types. | |
273 operation_context->set_update_observers(update_observers_); | 265 operation_context->set_update_observers(update_observers_); |
274 operation_context->set_change_observers(change_observers_); | 266 operation_context->set_change_observers(change_observers_); |
275 | 267 |
276 SpecialStoragePolicy* policy = sandbox_context_->special_storage_policy(); | 268 SpecialStoragePolicy* policy = sandbox_context_->special_storage_policy(); |
277 if (policy && policy->IsStorageUnlimited(url.origin())) | 269 if (policy && policy->IsStorageUnlimited(url.origin())) |
278 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); | 270 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeUnlimited); |
279 else | 271 else |
280 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); | 272 operation_context->set_quota_limit_type(quota::kQuotaLimitTypeLimited); |
281 | 273 |
282 return new LocalFileSystemOperation(url, context, operation_context.Pass()); | 274 return new LocalFileSystemOperation(url, context, operation_context.Pass()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 if (enumerator->HasFileSystemType(type)) | 352 if (enumerator->HasFileSystemType(type)) |
361 origins->insert(origin); | 353 origins->insert(origin); |
362 } | 354 } |
363 switch (type) { | 355 switch (type) { |
364 case kFileSystemTypeTemporary: | 356 case kFileSystemTypeTemporary: |
365 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size()); | 357 UMA_HISTOGRAM_COUNTS(kTemporaryOriginsCountLabel, origins->size()); |
366 break; | 358 break; |
367 case kFileSystemTypePersistent: | 359 case kFileSystemTypePersistent: |
368 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size()); | 360 UMA_HISTOGRAM_COUNTS(kPersistentOriginsCountLabel, origins->size()); |
369 break; | 361 break; |
370 case kFileSystemTypeSyncable: | |
371 UMA_HISTOGRAM_COUNTS(kSyncableOriginsCountLabel, origins->size()); | |
372 break; | |
373 default: | 362 default: |
374 break; | 363 break; |
375 } | 364 } |
376 } | 365 } |
377 | 366 |
378 void SandboxFileSystemBackend::GetOriginsForHostOnFileThread( | 367 void SandboxFileSystemBackend::GetOriginsForHostOnFileThread( |
379 fileapi::FileSystemType type, const std::string& host, | 368 fileapi::FileSystemType type, const std::string& host, |
380 std::set<GURL>* origins) { | 369 std::set<GURL>* origins) { |
381 DCHECK(CanHandleType(type)); | 370 DCHECK(CanHandleType(type)); |
382 DCHECK(origins); | 371 DCHECK(origins); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 sandbox_context_->quota_observer()->SetUsageCacheEnabled(origin, type, false); | 440 sandbox_context_->quota_observer()->SetUsageCacheEnabled(origin, type, false); |
452 InvalidateUsageCache(origin, type); | 441 InvalidateUsageCache(origin, type); |
453 } | 442 } |
454 | 443 |
455 void SandboxFileSystemBackend::AddFileUpdateObserver( | 444 void SandboxFileSystemBackend::AddFileUpdateObserver( |
456 FileSystemType type, | 445 FileSystemType type, |
457 FileUpdateObserver* observer, | 446 FileUpdateObserver* observer, |
458 base::SequencedTaskRunner* task_runner) { | 447 base::SequencedTaskRunner* task_runner) { |
459 DCHECK(CanHandleType(type)); | 448 DCHECK(CanHandleType(type)); |
460 UpdateObserverList* list = &update_observers_; | 449 UpdateObserverList* list = &update_observers_; |
461 if (type == kFileSystemTypeSyncable) | |
462 list = &syncable_update_observers_; | |
463 *list = list->AddObserver(observer, task_runner); | 450 *list = list->AddObserver(observer, task_runner); |
464 } | 451 } |
465 | 452 |
466 void SandboxFileSystemBackend::AddFileChangeObserver( | 453 void SandboxFileSystemBackend::AddFileChangeObserver( |
467 FileSystemType type, | 454 FileSystemType type, |
468 FileChangeObserver* observer, | 455 FileChangeObserver* observer, |
469 base::SequencedTaskRunner* task_runner) { | 456 base::SequencedTaskRunner* task_runner) { |
470 DCHECK(CanHandleType(type)); | 457 DCHECK(CanHandleType(type)); |
471 ChangeObserverList* list = &change_observers_; | 458 ChangeObserverList* list = &change_observers_; |
472 if (type == kFileSystemTypeSyncable) | |
473 list = &syncable_change_observers_; | |
474 *list = list->AddObserver(observer, task_runner); | 459 *list = list->AddObserver(observer, task_runner); |
475 } | 460 } |
476 | 461 |
477 void SandboxFileSystemBackend::AddFileAccessObserver( | 462 void SandboxFileSystemBackend::AddFileAccessObserver( |
478 FileSystemType type, | 463 FileSystemType type, |
479 FileAccessObserver* observer, | 464 FileAccessObserver* observer, |
480 base::SequencedTaskRunner* task_runner) { | 465 base::SequencedTaskRunner* task_runner) { |
481 DCHECK(CanHandleType(type)); | 466 DCHECK(CanHandleType(type)); |
482 access_observers_ = access_observers_.AddObserver(observer, task_runner); | 467 access_observers_ = access_observers_.AddObserver(observer, task_runner); |
483 } | 468 } |
484 | 469 |
485 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers( | 470 const UpdateObserverList* SandboxFileSystemBackend::GetUpdateObservers( |
486 FileSystemType type) const { | 471 FileSystemType type) const { |
487 DCHECK(CanHandleType(type)); | 472 DCHECK(CanHandleType(type)); |
488 if (type == kFileSystemTypeSyncable) | |
489 return &syncable_update_observers_; | |
490 return &update_observers_; | 473 return &update_observers_; |
491 } | 474 } |
492 | 475 |
493 const ChangeObserverList* SandboxFileSystemBackend::GetChangeObservers( | 476 const ChangeObserverList* SandboxFileSystemBackend::GetChangeObservers( |
494 FileSystemType type) const { | 477 FileSystemType type) const { |
495 DCHECK(CanHandleType(type)); | 478 DCHECK(CanHandleType(type)); |
496 if (type == kFileSystemTypeSyncable) | |
497 return &syncable_change_observers_; | |
498 return &change_observers_; | 479 return &change_observers_; |
499 } | 480 } |
500 | 481 |
501 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers( | 482 const AccessObserverList* SandboxFileSystemBackend::GetAccessObservers( |
502 FileSystemType type) const { | 483 FileSystemType type) const { |
503 DCHECK(CanHandleType(type)); | 484 DCHECK(CanHandleType(type)); |
504 return &access_observers_; | 485 return &access_observers_; |
505 } | 486 } |
506 | 487 |
507 void SandboxFileSystemBackend::CollectOpenFileSystemMetrics( | 488 void SandboxFileSystemBackend::CollectOpenFileSystemMetrics( |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 | 639 |
659 while (!(file_path_each = enumerator->Next()).empty()) { | 640 while (!(file_path_each = enumerator->Next()).empty()) { |
660 usage += enumerator->Size(); | 641 usage += enumerator->Size(); |
661 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); | 642 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); |
662 } | 643 } |
663 | 644 |
664 return usage; | 645 return usage; |
665 } | 646 } |
666 | 647 |
667 } // namespace fileapi | 648 } // namespace fileapi |
OLD | NEW |