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

Unified Diff: webkit/fileapi/sandbox_mount_point_provider.cc

Issue 9016020: Cleanup FileSystemOperation for preparing for adding FSO-factory method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years 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 side-by-side diff with in-line comments
Download patch
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 6c36c84d48030073b9b727d1ab2a0bc60729d4b4..a1c12231040874f16982be8195b68dc254ea7161 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -17,6 +17,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"
@@ -271,83 +272,54 @@ const FilePath::CharType
SandboxMountPointProvider::kRenamedOldFileSystemDirectory[] =
FILE_PATH_LITERAL("FS.old");
-class SandboxMountPointProvider::GetFileSystemRootPathTask
- : public base::RefCountedThreadSafe<
- SandboxMountPointProvider::GetFileSystemRootPathTask> {
+class ValidateFileSystemRootHelper {
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)
+ typedef FileSystemMountPointProvider::ValidateFileSystemCallback Callback;
+
+ ValidateFileSystemRootHelper(
+ base::MessageLoopProxy* file_message_loop,
+ ObfuscatedFileUtil* file_util)
: 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) {
+ error_(base::PLATFORM_FILE_OK) {
}
- virtual ~GetFileSystemRootPathTask() {
+ ~ValidateFileSystemRootHelper() {
// 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) {
+ void RunOnFileThread(const GURL& origin_url,
+ FileSystemType type,
+ const FilePath& old_base_path,
+ bool create) {
+ 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_ = base::PLATFORM_FILE_ERROR_FAILED;
+ } else {
+ UMA_HISTOGRAM_ENUMERATION(kOpenFileSystem, kOK, kFileSystemErrorMax);
+ error_ = base::PLATFORM_FILE_OK;
}
- origin_message_loop_proxy_->PostTask(
- FROM_HERE,
- base::Bind(&GetFileSystemRootPathTask::DispatchCallback, this,
- root_path));
+ // We must clear the reference on the file thread.
+ file_util_ = NULL;
}
- 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();
+ void Reply(const Callback& callback) {
+ callback.Run(error_);
}
+ private:
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_;
+ base::PlatformFileError error_;
};
SandboxMountPointProvider::SandboxMountPointProvider(
@@ -370,24 +342,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);
@@ -395,22 +355,27 @@ 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);
+ ValidateFileSystemRootHelper* helper = new ValidateFileSystemRootHelper(
+ file_message_loop_, sandbox_file_util_);
+ file_message_loop_->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&ValidateFileSystemRootHelper::RunOnFileThread,
+ base::Unretained(helper),
+ origin_url, type, old_base_path(), create),
tzik 2011/12/22 06:49:20 Could we add sandbox_file_util_ as parameter and o
kinuko 2011/12/22 07:04:33 Good point. Done.
+ base::Bind(&ValidateFileSystemRootHelper::Reply,
+ base::Owned(helper),
+ callback));
};
FilePath
-SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread(
+SandboxMountPointProvider::GetFileSystemRootPathOnFileThread(
const GURL& origin_url, FileSystemType type, const FilePath& unused,
bool create) {
if (file_system_options_->is_incognito())
@@ -426,6 +391,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())
« no previous file with comments | « webkit/fileapi/sandbox_mount_point_provider.h ('k') | webkit/fileapi/sandbox_mount_point_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698