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/fileapi/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/message_loop_proxy.h" | |
13 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/single_thread_task_runner.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/metrics/histogram.h" | |
17 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
18 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
19 #include "webkit/fileapi/file_system_file_reader.h" | 18 #include "webkit/fileapi/file_system_file_reader.h" |
20 #include "webkit/fileapi/file_system_operation.h" | 19 #include "webkit/fileapi/file_system_operation.h" |
21 #include "webkit/fileapi/file_system_operation_context.h" | 20 #include "webkit/fileapi/file_system_operation_context.h" |
22 #include "webkit/fileapi/file_system_options.h" | 21 #include "webkit/fileapi/file_system_options.h" |
23 #include "webkit/fileapi/file_system_types.h" | 22 #include "webkit/fileapi/file_system_types.h" |
24 #include "webkit/fileapi/file_system_usage_cache.h" | 23 #include "webkit/fileapi/file_system_usage_cache.h" |
25 #include "webkit/fileapi/file_system_util.h" | 24 #include "webkit/fileapi/file_system_util.h" |
26 #include "webkit/fileapi/obfuscated_file_util.h" | 25 #include "webkit/fileapi/obfuscated_file_util.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 FILE_PATH_LITERAL("FileSystem"); | 298 FILE_PATH_LITERAL("FileSystem"); |
300 | 299 |
301 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = | 300 const FilePath::CharType SandboxMountPointProvider::kNewFileSystemDirectory[] = |
302 FILE_PATH_LITERAL("File System"); | 301 FILE_PATH_LITERAL("File System"); |
303 | 302 |
304 const FilePath::CharType | 303 const FilePath::CharType |
305 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = | 304 SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
306 FILE_PATH_LITERAL("FS.old"); | 305 FILE_PATH_LITERAL("FS.old"); |
307 | 306 |
308 SandboxMountPointProvider::SandboxMountPointProvider( | 307 SandboxMountPointProvider::SandboxMountPointProvider( |
309 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 308 base::SingleThreadTaskRunner* file_task_runner, |
310 const FilePath& profile_path, | 309 const FilePath& profile_path, |
311 const FileSystemOptions& file_system_options) | 310 const FileSystemOptions& file_system_options) |
312 : FileSystemQuotaUtil(file_message_loop), | 311 : FileSystemQuotaUtil(file_task_runner), |
313 file_message_loop_(file_message_loop), | 312 file_task_runner_(file_task_runner), |
314 profile_path_(profile_path), | 313 profile_path_(profile_path), |
315 file_system_options_(file_system_options), | 314 file_system_options_(file_system_options), |
316 sandbox_file_util_( | 315 sandbox_file_util_( |
317 new ObfuscatedFileUtil( | 316 new ObfuscatedFileUtil( |
318 profile_path.Append(kNewFileSystemDirectory), | 317 profile_path.Append(kNewFileSystemDirectory), |
319 QuotaFileUtil::CreateDefault())) { | 318 QuotaFileUtil::CreateDefault())) { |
320 } | 319 } |
321 | 320 |
322 SandboxMountPointProvider::~SandboxMountPointProvider() { | 321 SandboxMountPointProvider::~SandboxMountPointProvider() { |
323 if (!file_message_loop_->BelongsToCurrentThread()) { | 322 ObfuscatedFileUtil* sandbox_file_util = sandbox_file_util_.release(); |
324 ObfuscatedFileUtil* sandbox_file_util = sandbox_file_util_.release(); | 323 if (!file_task_runner_->ReleaseSoon(FROM_HERE, sandbox_file_util)) |
325 if (!file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util)) | 324 sandbox_file_util->Release(); |
326 sandbox_file_util->Release(); | |
327 } | |
328 } | 325 } |
329 | 326 |
330 void SandboxMountPointProvider::ValidateFileSystemRoot( | 327 void SandboxMountPointProvider::ValidateFileSystemRoot( |
331 const GURL& origin_url, fileapi::FileSystemType type, bool create, | 328 const GURL& origin_url, fileapi::FileSystemType type, bool create, |
332 const ValidateFileSystemCallback& callback) { | 329 const ValidateFileSystemCallback& callback) { |
333 if (file_system_options_.is_incognito()) { | 330 if (file_system_options_.is_incognito()) { |
334 // TODO(kinuko): return an isolated temporary directory. | 331 // TODO(kinuko): return an isolated temporary directory. |
335 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 332 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
336 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, | 333 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, |
337 kIncognito, | 334 kIncognito, |
338 kFileSystemErrorMax); | 335 kFileSystemErrorMax); |
339 return; | 336 return; |
340 } | 337 } |
341 | 338 |
342 if (!IsAllowedScheme(origin_url)) { | 339 if (!IsAllowedScheme(origin_url)) { |
343 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 340 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
344 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, | 341 UMA_HISTOGRAM_ENUMERATION(kOpenFileSystemLabel, |
345 kInvalidScheme, | 342 kInvalidScheme, |
346 kFileSystemErrorMax); | 343 kFileSystemErrorMax); |
347 return; | 344 return; |
348 } | 345 } |
349 | 346 |
350 base::PlatformFileError* error_ptr = new base::PlatformFileError; | 347 base::PlatformFileError* error_ptr = new base::PlatformFileError; |
351 file_message_loop_->PostTaskAndReply( | 348 file_task_runner_->PostTaskAndReply( |
352 FROM_HERE, | 349 FROM_HERE, |
353 base::Bind(&ValidateRootOnFileThread, | 350 base::Bind(&ValidateRootOnFileThread, |
354 sandbox_file_util_, | 351 sandbox_file_util_, |
355 origin_url, type, old_base_path(), create, | 352 origin_url, type, old_base_path(), create, |
356 base::Unretained(error_ptr)), | 353 base::Unretained(error_ptr)), |
357 base::Bind(base::Bind(&PassPointerErrorByValue, callback), | 354 base::Bind(base::Bind(&PassPointerErrorByValue, callback), |
358 base::Owned(error_ptr))); | 355 base::Owned(error_ptr))); |
359 }; | 356 }; |
360 | 357 |
361 FilePath | 358 FilePath |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // We simply return the very top directory of the sandbox | 419 // We simply return the very top directory of the sandbox |
423 // filesystem regardless of the input path. | 420 // filesystem regardless of the input path. |
424 return new_base_path(); | 421 return new_base_path(); |
425 } | 422 } |
426 | 423 |
427 FileSystemOperationInterface* | 424 FileSystemOperationInterface* |
428 SandboxMountPointProvider::CreateFileSystemOperation( | 425 SandboxMountPointProvider::CreateFileSystemOperation( |
429 const GURL& origin_url, | 426 const GURL& origin_url, |
430 FileSystemType file_system_type, | 427 FileSystemType file_system_type, |
431 const FilePath& virtual_path, | 428 const FilePath& virtual_path, |
432 base::MessageLoopProxy* file_proxy, | 429 base::TaskRunner* file_task_runner, |
433 FileSystemContext* context) const { | 430 FileSystemContext* context) const { |
434 return new FileSystemOperation(file_proxy, context); | 431 return new FileSystemOperation(file_task_runner, context); |
435 } | 432 } |
436 | 433 |
437 webkit_blob::FileReader* SandboxMountPointProvider::CreateFileReader( | 434 webkit_blob::FileReader* SandboxMountPointProvider::CreateFileReader( |
438 const GURL& url, | 435 const GURL& url, |
439 int64 offset, | 436 int64 offset, |
440 base::MessageLoopProxy* file_proxy, | 437 base::TaskRunner* file_task_runner, |
441 FileSystemContext* context) const { | 438 FileSystemContext* context) const { |
442 return new FileSystemFileReader(file_proxy, context, url, offset); | 439 return new FileSystemFileReader(file_task_runner, context, url, offset); |
443 } | 440 } |
444 | 441 |
445 FilePath SandboxMountPointProvider::old_base_path() const { | 442 FilePath SandboxMountPointProvider::old_base_path() const { |
446 return profile_path_.Append(kOldFileSystemDirectory); | 443 return profile_path_.Append(kOldFileSystemDirectory); |
447 } | 444 } |
448 | 445 |
449 FilePath SandboxMountPointProvider::new_base_path() const { | 446 FilePath SandboxMountPointProvider::new_base_path() const { |
450 return profile_path_.Append(kNewFileSystemDirectory); | 447 return profile_path_.Append(kNewFileSystemDirectory); |
451 } | 448 } |
452 | 449 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 i < file_system_options_.additional_allowed_schemes().size(); | 667 i < file_system_options_.additional_allowed_schemes().size(); |
671 ++i) { | 668 ++i) { |
672 if (url.SchemeIs( | 669 if (url.SchemeIs( |
673 file_system_options_.additional_allowed_schemes()[i].c_str())) | 670 file_system_options_.additional_allowed_schemes()[i].c_str())) |
674 return true; | 671 return true; |
675 } | 672 } |
676 return false; | 673 return false; |
677 } | 674 } |
678 | 675 |
679 } // namespace fileapi | 676 } // namespace fileapi |
OLD | NEW |