Index: webkit/fileapi/sandbox_mount_point_provider.cc |
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc |
index 95edc813ca631c4977433dbfefb8fce17f5af6a3..6225cdf2fd27bf6f6e7064ac60fc557f137defb4 100644 |
--- a/webkit/fileapi/sandbox_mount_point_provider.cc |
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc |
@@ -16,6 +16,7 @@ |
#include "base/metrics/histogram.h" |
#include "googleurl/src/gurl.h" |
#include "net/base/net_util.h" |
+#include "webkit/fileapi/file_system_operation.h" |
#include "webkit/fileapi/file_system_operation_context.h" |
#include "webkit/fileapi/file_system_options.h" |
#include "webkit/fileapi/file_system_types.h" |
@@ -28,6 +29,8 @@ |
using quota::QuotaManagerProxy; |
+namespace fileapi { |
ericu
2012/01/09 18:44:44
Please remove all the "fileapi::" that are now unn
kinuko
2012/01/10 09:48:53
Done.
|
+ |
namespace { |
const char kChromeScheme[] = "chrome"; |
@@ -256,9 +259,39 @@ void MigrateIfNeeded( |
MigrateAllOldFileSystems(file_util, old_base_path); |
} |
-} // anonymous namespace |
+void PassPointerErrorByValue( |
+ const base::Callback<void(PlatformFileError)>& callback, |
+ PlatformFileError* error_ptr) { |
+ DCHECK(error_ptr); |
+ callback.Run(*error_ptr); |
+} |
-namespace fileapi { |
+void ValidateRootOnFileThread(ObfuscatedFileUtil* file_util, |
+ const GURL& origin_url, |
+ FileSystemType type, |
+ const FilePath& old_base_path, |
+ bool create, |
+ base::PlatformFileError* error_ptr) { |
+ DCHECK(error_ptr); |
+ MigrateIfNeeded(file_util, old_base_path); |
+ FilePath root_path = |
+ file_util->GetDirectoryForOriginAndType(origin_url, type, create); |
+ if (root_path.empty()) { |
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
+ kCreateDirectoryError, |
+ kFileSystemErrorMax); |
+ // TODO(kinuko): We should return appropriate error code. |
+ *error_ptr = base::PLATFORM_FILE_ERROR_FAILED; |
+ } else { |
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, kOK, kFileSystemErrorMax); |
+ *error_ptr = base::PLATFORM_FILE_OK; |
+ } |
+ // The reference of file_util will be derefed on the FILE thread |
+ // when the storage of this callback gets deleted regardless of whether |
+ // this method is called or not. |
+} |
+ |
+} // anonymous namespace |
const FilePath::CharType SandboxMountPointProvider::kOldFileSystemDirectory[] = |
FILE_PATH_LITERAL("FileSystem"); |
@@ -270,85 +303,6 @@ const FilePath::CharType |
SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] = |
FILE_PATH_LITERAL("FS.old"); |
-class SandboxMountPointProvider::GetFileSystemRootPathTask |
- : public base::RefCountedThreadSafe< |
- SandboxMountPointProvider::GetFileSystemRootPathTask> { |
- public: |
- GetFileSystemRootPathTask( |
- scoped_refptr<base::MessageLoopProxy> file_message_loop, |
- const GURL& origin_url, |
- FileSystemType type, |
- ObfuscatedFileUtil* file_util, |
- const FilePath& old_base_path, |
- const FileSystemMountPointProvider::GetRootPathCallback& callback) |
- : file_message_loop_(file_message_loop), |
- origin_message_loop_proxy_( |
- base::MessageLoopProxy::current()), |
- origin_url_(origin_url), |
- type_(type), |
- file_util_(file_util), |
- old_base_path_(old_base_path), |
- callback_(callback) { |
- } |
- |
- virtual ~GetFileSystemRootPathTask() { |
- // Just in case we get deleted without running, make sure to clean up the |
- // file_util_ on the right thread. |
- if (file_util_.get() && !file_message_loop_->BelongsToCurrentThread()) |
- file_message_loop_->ReleaseSoon(FROM_HERE, file_util_.release()); |
- } |
- |
- void Start(bool create) { |
- file_message_loop_->PostTask( |
- FROM_HERE, |
- base::Bind( |
- &GetFileSystemRootPathTask::GetFileSystemRootPathOnFileThread, this, |
- create)); |
- } |
- |
- private: |
- void GetFileSystemRootPathOnFileThread(bool create) { |
- MigrateIfNeeded(file_util_, old_base_path_); |
- DispatchCallbackOnCallerThread( |
- file_util_->GetDirectoryForOriginAndType(origin_url_, type_, create)); |
- // We must clear the reference on the file thread. |
- file_util_ = NULL; |
- } |
- |
- void DispatchCallbackOnCallerThread(const FilePath& root_path) { |
- if (root_path.empty()) { |
- UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
- kCreateDirectoryError, |
- kFileSystemErrorMax); |
- } |
- origin_message_loop_proxy_->PostTask( |
- FROM_HERE, |
- base::Bind(&GetFileSystemRootPathTask::DispatchCallback, this, |
- root_path)); |
- } |
- |
- void DispatchCallback(const FilePath& root_path) { |
- std::string origin_identifier = GetOriginIdentifierFromURL(origin_url_); |
- std::string type_string = GetFileSystemTypeString(type_); |
- DCHECK(!type_string.empty()); |
- std::string name = origin_identifier + ":" + type_string; |
- |
- if (!root_path.empty()) |
- UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, kOK, kFileSystemErrorMax); |
- |
- callback_.Run(!root_path.empty(), root_path, name); |
- callback_.Reset(); |
- } |
- |
- scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
- scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
- GURL origin_url_; |
- FileSystemType type_; |
- scoped_refptr<ObfuscatedFileUtil> file_util_; |
- FilePath old_base_path_; |
- FileSystemMountPointProvider::GetRootPathCallback callback_; |
-}; |
- |
SandboxMountPointProvider::SandboxMountPointProvider( |
scoped_refptr<base::MessageLoopProxy> file_message_loop, |
const FilePath& profile_path, |
@@ -368,24 +322,12 @@ SandboxMountPointProvider::~SandboxMountPointProvider() { |
file_message_loop_->ReleaseSoon(FROM_HERE, sandbox_file_util_.release()); |
} |
-bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
- FileSystemType type, |
- const FilePath& unused) { |
- if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) |
- return false; |
- // We essentially depend on quota to do our access controls, so here |
- // we only check if the requested scheme is allowed or not. |
- return IsAllowedScheme(origin_url); |
-} |
- |
-void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
+void SandboxMountPointProvider::ValidateFileSystemRoot( |
const GURL& origin_url, fileapi::FileSystemType type, bool create, |
- const FileSystemMountPointProvider::GetRootPathCallback& callback) { |
- FilePath origin_base_path; |
- |
+ const ValidateFileSystemCallback& callback) { |
if (file_system_options_.is_incognito()) { |
// TODO(kinuko): return an isolated temporary directory. |
- callback.Run(false, FilePath(), std::string()); |
+ callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
kIncognito, |
kFileSystemErrorMax); |
@@ -393,22 +335,26 @@ void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
} |
if (!IsAllowedScheme(origin_url)) { |
- callback.Run(false, FilePath(), std::string()); |
+ callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, |
kInvalidScheme, |
kFileSystemErrorMax); |
return; |
} |
- scoped_refptr<GetFileSystemRootPathTask> task( |
- new GetFileSystemRootPathTask( |
- file_message_loop_, origin_url, type, sandbox_file_util_.get(), |
- old_base_path(), callback)); |
- task->Start(create); |
+ base::PlatformFileError* error_ptr = new base::PlatformFileError; |
+ file_message_loop_->PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(&ValidateRootOnFileThread, |
+ sandbox_file_util_, |
+ origin_url, type, old_base_path(), create, |
+ base::Unretained(error_ptr)), |
+ base::Bind(base::Bind(&PassPointerErrorByValue, callback), |
+ base::Owned(error_ptr))); |
}; |
FilePath |
-SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( |
+SandboxMountPointProvider::GetFileSystemRootPathOnFileThread( |
const GURL& origin_url, FileSystemType type, const FilePath& unused, |
bool create) { |
if (file_system_options_.is_incognito()) |
@@ -424,6 +370,16 @@ SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( |
origin_url, type, create); |
} |
+bool SandboxMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
+ FileSystemType type, |
+ const FilePath& unused) { |
+ if (type != kFileSystemTypeTemporary && type != kFileSystemTypePersistent) |
+ return false; |
+ // We essentially depend on quota to do our access controls, so here |
+ // we only check if the requested scheme is allowed or not. |
+ return IsAllowedScheme(origin_url); |
+} |
+ |
bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) |
const { |
if (filename.value().empty()) |