| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 SandboxFileSystemBackend::SandboxFileSystemBackend( | 135 SandboxFileSystemBackend::SandboxFileSystemBackend( |
| 136 SandboxContext* sandbox_context, | 136 SandboxContext* sandbox_context, |
| 137 const FileSystemOptions& file_system_options) | 137 const FileSystemOptions& file_system_options) |
| 138 : file_system_options_(file_system_options), | 138 : file_system_options_(file_system_options), |
| 139 sandbox_context_(sandbox_context), | 139 sandbox_context_(sandbox_context), |
| 140 enable_temporary_file_system_in_incognito_(false), | 140 enable_temporary_file_system_in_incognito_(false), |
| 141 enable_usage_tracking_( | 141 enable_usage_tracking_( |
| 142 !CommandLine::ForCurrentProcess()->HasSwitch( | 142 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 143 kDisableUsageTracking)), | 143 kDisableUsageTracking)), |
| 144 weak_factory_(this) { | 144 weak_factory_(this) { |
| 145 } |
| 146 |
| 147 SandboxFileSystemBackend::~SandboxFileSystemBackend() { |
| 148 } |
| 149 |
| 150 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { |
| 151 return type == kFileSystemTypeTemporary || |
| 152 type == kFileSystemTypePersistent || |
| 153 type == kFileSystemTypeSyncable || |
| 154 type == kFileSystemTypeSyncableForInternalSync; |
| 155 } |
| 156 |
| 157 void SandboxFileSystemBackend::Initialize(const FileSystemContext* context) { |
| 145 // Set quota observers. | 158 // Set quota observers. |
| 146 if (enable_usage_tracking_) { | 159 if (enable_usage_tracking_) { |
| 147 update_observers_ = update_observers_.AddObserver( | 160 update_observers_ = update_observers_.AddObserver( |
| 148 sandbox_context_->quota_observer(), | 161 sandbox_context_->quota_observer(), |
| 149 sandbox_context_->file_task_runner()); | 162 sandbox_context_->file_task_runner()); |
| 150 access_observers_ = access_observers_.AddObserver( | 163 access_observers_ = access_observers_.AddObserver( |
| 151 sandbox_context_->quota_observer(), NULL); | 164 sandbox_context_->quota_observer(), NULL); |
| 152 } | 165 } |
| 153 | 166 |
| 154 syncable_update_observers_ = update_observers_; | 167 syncable_update_observers_ = update_observers_; |
| 155 | 168 |
| 156 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { | 169 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { |
| 157 // Post prepopulate task only if it's not already running on | 170 // Post prepopulate task only if it's not already running on |
| 158 // file_task_runner (which implies running in tests). | 171 // file_task_runner (which implies running in tests). |
| 159 sandbox_context_->file_task_runner()->PostTask( | 172 sandbox_context_->file_task_runner()->PostTask( |
| 160 FROM_HERE, | 173 FROM_HERE, |
| 161 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, | 174 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, |
| 162 base::Unretained(sandbox_sync_file_util()))); | 175 base::Unretained(sandbox_sync_file_util()))); |
| 163 } | 176 } |
| 164 } | 177 } |
| 165 | 178 |
| 166 SandboxFileSystemBackend::~SandboxFileSystemBackend() { | |
| 167 } | |
| 168 | |
| 169 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { | |
| 170 return type == kFileSystemTypeTemporary || | |
| 171 type == kFileSystemTypePersistent || | |
| 172 type == kFileSystemTypeSyncable || | |
| 173 type == kFileSystemTypeSyncableForInternalSync; | |
| 174 } | |
| 175 | |
| 176 void SandboxFileSystemBackend::InitializeFileSystem( | 179 void SandboxFileSystemBackend::InitializeFileSystem( |
| 177 const GURL& origin_url, | 180 const GURL& origin_url, |
| 178 fileapi::FileSystemType type, | 181 fileapi::FileSystemType type, |
| 179 OpenFileSystemMode mode, | 182 OpenFileSystemMode mode, |
| 180 FileSystemContext* context, | 183 FileSystemContext* context, |
| 181 const InitializeFileSystemCallback& callback) { | 184 const InitializeFileSystemCallback& callback) { |
| 182 if (file_system_options_.is_incognito() && | 185 if (file_system_options_.is_incognito() && |
| 183 !(type == kFileSystemTypeTemporary && | 186 !(type == kFileSystemTypeTemporary && |
| 184 enable_temporary_file_system_in_incognito_)) { | 187 enable_temporary_file_system_in_incognito_)) { |
| 185 // TODO(kinuko): return an isolated temporary directory. | 188 // TODO(kinuko): return an isolated temporary directory. |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 661 |
| 659 while (!(file_path_each = enumerator->Next()).empty()) { | 662 while (!(file_path_each = enumerator->Next()).empty()) { |
| 660 usage += enumerator->Size(); | 663 usage += enumerator->Size(); |
| 661 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); | 664 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); |
| 662 } | 665 } |
| 663 | 666 |
| 664 return usage; | 667 return usage; |
| 665 } | 668 } |
| 666 | 669 |
| 667 } // namespace fileapi | 670 } // namespace fileapi |
| OLD | NEW |