Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: webkit/browser/fileapi/sandbox_file_system_backend.cc

Issue 18300006: FileAPI: Factor out getting root URI and FS name parts into each FS backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 #include "webkit/browser/fileapi/async_file_util_adapter.h" 17 #include "webkit/browser/fileapi/async_file_util_adapter.h"
18 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 18 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
19 #include "webkit/browser/fileapi/file_system_context.h" 19 #include "webkit/browser/fileapi/file_system_context.h"
20 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" 20 #include "webkit/browser/fileapi/file_system_file_stream_reader.h"
21 #include "webkit/browser/fileapi/file_system_operation_context.h" 21 #include "webkit/browser/fileapi/file_system_operation_context.h"
22 #include "webkit/browser/fileapi/file_system_options.h" 22 #include "webkit/browser/fileapi/file_system_options.h"
23 #include "webkit/browser/fileapi/file_system_task_runners.h" 23 #include "webkit/browser/fileapi/file_system_task_runners.h"
24 #include "webkit/browser/fileapi/file_system_usage_cache.h" 24 #include "webkit/browser/fileapi/file_system_usage_cache.h"
25 #include "webkit/browser/fileapi/local_file_system_operation.h" 25 #include "webkit/browser/fileapi/local_file_system_operation.h"
26 #include "webkit/browser/fileapi/obfuscated_file_util.h" 26 #include "webkit/browser/fileapi/obfuscated_file_util.h"
27 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" 27 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h"
28 #include "webkit/browser/fileapi/sandbox_quota_observer.h" 28 #include "webkit/browser/fileapi/sandbox_quota_observer.h"
29 #include "webkit/browser/fileapi/syncable/syncable_file_system_operation.h" 29 #include "webkit/browser/fileapi/syncable/syncable_file_system_operation.h"
30 #include "webkit/browser/fileapi/syncable/syncable_file_system_util.h"
30 #include "webkit/browser/quota/quota_manager.h" 31 #include "webkit/browser/quota/quota_manager.h"
31 #include "webkit/common/fileapi/file_system_types.h" 32 #include "webkit/common/fileapi/file_system_types.h"
32 #include "webkit/common/fileapi/file_system_util.h" 33 #include "webkit/common/fileapi/file_system_util.h"
33 34
34 using quota::QuotaManagerProxy; 35 using quota::QuotaManagerProxy;
35 36
36 namespace fileapi { 37 namespace fileapi {
37 38
38 namespace { 39 namespace {
39 40
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { 90 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE {
90 return enum_->HasFileSystemType(type); 91 return enum_->HasFileSystemType(type);
91 } 92 }
92 93
93 private: 94 private:
94 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_; 95 scoped_ptr<ObfuscatedFileUtil::AbstractOriginEnumerator> enum_;
95 }; 96 };
96 97
97 void DidOpenFileSystem( 98 void DidOpenFileSystem(
98 base::WeakPtr<SandboxFileSystemBackend> mount_point_provider, 99 base::WeakPtr<SandboxFileSystemBackend> mount_point_provider,
99 const FileSystemBackend::OpenFileSystemCallback& callback, 100 const base::Callback<void(base::PlatformFileError error)>& callback,
100 base::PlatformFileError* error) { 101 base::PlatformFileError* error) {
101 if (mount_point_provider.get()) 102 if (mount_point_provider.get())
102 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error); 103 mount_point_provider.get()->CollectOpenFileSystemMetrics(*error);
103 callback.Run(*error); 104 callback.Run(*error);
104 } 105 }
105 106
106 void OpenFileSystemOnFileThread( 107 void OpenFileSystemOnFileThread(
107 ObfuscatedFileUtil* file_util, 108 ObfuscatedFileUtil* file_util,
108 const GURL& origin_url, 109 const GURL& origin_url,
109 FileSystemType type, 110 FileSystemType type,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 202
202 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const { 203 bool SandboxFileSystemBackend::CanHandleType(FileSystemType type) const {
203 return type == kFileSystemTypeTemporary || 204 return type == kFileSystemTypeTemporary ||
204 type == kFileSystemTypePersistent || 205 type == kFileSystemTypePersistent ||
205 type == kFileSystemTypeSyncable || 206 type == kFileSystemTypeSyncable ||
206 type == kFileSystemTypeSyncableForInternalSync; 207 type == kFileSystemTypeSyncableForInternalSync;
207 } 208 }
208 209
209 void SandboxFileSystemBackend::OpenFileSystem( 210 void SandboxFileSystemBackend::OpenFileSystem(
210 const GURL& origin_url, fileapi::FileSystemType type, 211 const GURL& origin_url,
212 fileapi::FileSystemType type,
211 OpenFileSystemMode mode, 213 OpenFileSystemMode mode,
212 const OpenFileSystemCallback& callback) { 214 const OpenFileSystemCallback& callback) {
213 if (file_system_options_.is_incognito() && 215 if (file_system_options_.is_incognito() &&
214 !(type == kFileSystemTypeTemporary && 216 !(type == kFileSystemTypeTemporary &&
215 enable_temporary_file_system_in_incognito_)) { 217 enable_temporary_file_system_in_incognito_)) {
216 // TODO(kinuko): return an isolated temporary directory. 218 // TODO(kinuko): return an isolated temporary directory.
217 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 219 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY);
218 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, 220 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel,
219 kIncognito, 221 kIncognito,
220 kFileSystemErrorMax); 222 kFileSystemErrorMax);
221 return; 223 return;
222 } 224 }
223 225
224 if (!IsAllowedScheme(origin_url)) { 226 if (!IsAllowedScheme(origin_url)) {
225 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); 227 callback.Run(GURL(), std::string(), base::PLATFORM_FILE_ERROR_SECURITY);
226 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, 228 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel,
227 kInvalidSchemeError, 229 kInvalidSchemeError,
228 kFileSystemErrorMax); 230 kFileSystemErrorMax);
229 return; 231 return;
230 } 232 }
231 233
234 // TODO(nhiroki): Factor out SyncFS related code to SyncFileSystemBackend we
235 // plan to introduce. (http://crbug.com/242422/)
236 GURL root_url = (type == kFileSystemTypeSyncable)
237 ? sync_file_system::GetSyncableFileSystemRootURI(origin_url)
238 : GetFileSystemRootURI(origin_url, type);
239 std::string name = GetFileSystemName(origin_url, type);
240
232 base::PlatformFileError* error_ptr = new base::PlatformFileError; 241 base::PlatformFileError* error_ptr = new base::PlatformFileError;
233 file_task_runner_->PostTaskAndReply( 242 file_task_runner_->PostTaskAndReply(
234 FROM_HERE, 243 FROM_HERE,
235 base::Bind(&OpenFileSystemOnFileThread, 244 base::Bind(&OpenFileSystemOnFileThread,
236 sandbox_sync_file_util(), 245 sandbox_sync_file_util(),
237 origin_url, type, mode, 246 origin_url, type, mode,
238 base::Unretained(error_ptr)), 247 base::Unretained(error_ptr)),
239 base::Bind(&DidOpenFileSystem, 248 base::Bind(&DidOpenFileSystem,
240 weak_factory_.GetWeakPtr(), 249 weak_factory_.GetWeakPtr(),
241 callback, base::Owned(error_ptr))); 250 base::Bind(callback, root_url, name),
251 base::Owned(error_ptr)));
242 252
243 if (enable_usage_tracking_) 253 if (enable_usage_tracking_)
244 return; 254 return;
245 255
246 // Schedule full usage recalculation on the next launch without 256 // Schedule full usage recalculation on the next launch without
247 // --disable-file-system-usage-tracking. 257 // --disable-file-system-usage-tracking.
248 file_task_runner_->PostTask( 258 file_task_runner_->PostTask(
249 FROM_HERE, 259 FROM_HERE,
250 base::Bind(&SandboxFileSystemBackend::InvalidateUsageCacheOnFileThread, 260 base::Bind(&SandboxFileSystemBackend::InvalidateUsageCacheOnFileThread,
251 sandbox_sync_file_util(), origin_url, type, 261 sandbox_sync_file_util(), origin_url, type,
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 677
668 while (!(file_path_each = enumerator->Next()).empty()) { 678 while (!(file_path_each = enumerator->Next()).empty()) {
669 usage += enumerator->Size(); 679 usage += enumerator->Size();
670 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each); 680 usage += ObfuscatedFileUtil::ComputeFilePathCost(file_path_each);
671 } 681 }
672 682
673 return usage; 683 return usage;
674 } 684 }
675 685
676 } // namespace fileapi 686 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/isolated_file_system_backend.cc ('k') | webkit/browser/fileapi/sandbox_file_system_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698