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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 } // anonymous namespace | 129 } // anonymous namespace |
130 | 130 |
131 SandboxFileSystemBackend::SandboxFileSystemBackend( | 131 SandboxFileSystemBackend::SandboxFileSystemBackend( |
132 SandboxContext* sandbox_context, | 132 SandboxContext* sandbox_context, |
133 const FileSystemOptions& file_system_options) | 133 const FileSystemOptions& file_system_options) |
134 : file_system_options_(file_system_options), | 134 : file_system_options_(file_system_options), |
135 sandbox_context_(sandbox_context), | 135 sandbox_context_(sandbox_context), |
136 enable_temporary_file_system_in_incognito_(false), | 136 enable_temporary_file_system_in_incognito_(false), |
137 weak_factory_(this) { | 137 weak_factory_(this) { |
| 138 } |
| 139 |
| 140 SandboxFileSystemBackend::~SandboxFileSystemBackend() { |
| 141 } |
| 142 |
| 143 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { |
| 144 return type == kFileSystemTypeTemporary || |
| 145 type == kFileSystemTypePersistent || |
| 146 type == kFileSystemTypeSyncable || |
| 147 type == kFileSystemTypeSyncableForInternalSync; |
| 148 } |
| 149 |
| 150 void SandboxFileSystemBackend::Initialize(FileSystemContext* context) { |
138 // Set quota observers. | 151 // Set quota observers. |
139 if (sandbox_context_->is_usage_tracking_enabled()) { | 152 if (sandbox_context_->is_usage_tracking_enabled()) { |
140 update_observers_ = update_observers_.AddObserver( | 153 update_observers_ = update_observers_.AddObserver( |
141 sandbox_context_->quota_observer(), | 154 sandbox_context_->quota_observer(), |
142 sandbox_context_->file_task_runner()); | 155 sandbox_context_->file_task_runner()); |
143 access_observers_ = access_observers_.AddObserver( | 156 access_observers_ = access_observers_.AddObserver( |
144 sandbox_context_->quota_observer(), NULL); | 157 sandbox_context_->quota_observer(), NULL); |
145 } | 158 } |
146 | 159 |
147 syncable_update_observers_ = update_observers_; | 160 syncable_update_observers_ = update_observers_; |
148 | 161 |
149 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { | 162 if (!sandbox_context_->file_task_runner()->RunsTasksOnCurrentThread()) { |
150 // Post prepopulate task only if it's not already running on | 163 // Post prepopulate task only if it's not already running on |
151 // file_task_runner (which implies running in tests). | 164 // file_task_runner (which implies running in tests). |
152 sandbox_context_->file_task_runner()->PostTask( | 165 sandbox_context_->file_task_runner()->PostTask( |
153 FROM_HERE, | 166 FROM_HERE, |
154 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, | 167 base::Bind(&ObfuscatedFileUtil::MaybePrepopulateDatabase, |
155 base::Unretained(sandbox_sync_file_util()))); | 168 base::Unretained(sandbox_sync_file_util()))); |
156 } | 169 } |
157 } | 170 } |
158 | 171 |
159 SandboxFileSystemBackend::~SandboxFileSystemBackend() { | 172 void SandboxFileSystemBackend::OpenFileSystem( |
160 } | |
161 | |
162 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { | |
163 return type == kFileSystemTypeTemporary || | |
164 type == kFileSystemTypePersistent || | |
165 type == kFileSystemTypeSyncable || | |
166 type == kFileSystemTypeSyncableForInternalSync; | |
167 } | |
168 | |
169 void SandboxFileSystemBackend::InitializeFileSystem( | |
170 const GURL& origin_url, | 173 const GURL& origin_url, |
171 fileapi::FileSystemType type, | 174 fileapi::FileSystemType type, |
172 OpenFileSystemMode mode, | 175 OpenFileSystemMode mode, |
173 FileSystemContext* context, | 176 const OpenFileSystemCallback& callback) { |
174 const InitializeFileSystemCallback& callback) { | |
175 if (file_system_options_.is_incognito() && | 177 if (file_system_options_.is_incognito() && |
176 !(type == kFileSystemTypeTemporary && | 178 !(type == kFileSystemTypeTemporary && |
177 enable_temporary_file_system_in_incognito_)) { | 179 enable_temporary_file_system_in_incognito_)) { |
178 // TODO(kinuko): return an isolated temporary directory. | 180 // TODO(kinuko): return an isolated temporary directory. |
179 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY); | 181 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY); |
180 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, | 182 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, |
181 kIncognito, | 183 kIncognito, |
182 kFileSystemErrorMax); | 184 kFileSystemErrorMax); |
183 return; | 185 return; |
184 } | 186 } |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 653 |
652 while (!(file_path_each = enumerator->Next()).empty()) { | 654 while (!(file_path_each = enumerator->Next()).empty()) { |
653 usage += enumerator->Size(); | 655 usage += enumerator->Size(); |
654 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); | 656 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); |
655 } | 657 } |
656 | 658 |
657 return usage; | 659 return usage; |
658 } | 660 } |
659 | 661 |
660 } // namespace fileapi | 662 } // namespace fileapi |
OLD | NEW |