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

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: more cleanup around ValidateFileSystemRoot 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..f9c404bb16f4f2a000912116a403ec88611c14f6 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"
@@ -29,6 +30,8 @@
using quota::QuotaManagerProxy;
+namespace fileapi {
+
namespace {
const char kChromeScheme[] = "chrome";
@@ -257,9 +260,37 @@ void MigrateIfNeeded(
MigrateAllOldFileSystems(file_util, old_base_path);
}
-} // anonymous namespace
+template <typename A>
+void PassPointerByValue(const base::Callback<void(A)>& callback, A* a) {
satorux1 2011/12/27 18:56:37 This looks a bit tricky (or I'm just not good at r
kinuko 2011/12/28 10:59:35 Done.
+ callback.Run(*a);
+}
-namespace fileapi {
+void ValidateRootOnFileThread(ObfuscatedFileUtil* file_util,
+ const GURL& origin_url,
+ FileSystemType type,
+ const FilePath& old_base_path,
+ bool create,
+ base::PlatformFileError* error) {
+ DCHECK(error);
+ 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;
+ }
+ // 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");
@@ -271,85 +302,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_;
-};
satorux1 2011/12/27 18:56:37 Wow, a lot of code is removed. Cool!
-
SandboxMountPointProvider::SandboxMountPointProvider(
scoped_refptr<base::MessageLoopProxy> file_message_loop,
const FilePath& profile_path,
@@ -370,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);
@@ -395,22 +335,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);
+ base::PlatformFileError* error = 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)),
+ base::Bind(base::Bind(&PassPointerByValue<base::PlatformFileError>,
+ callback),
+ base::Owned(error)));
};
FilePath
-SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread(
+SandboxMountPointProvider::GetFileSystemRootPathOnFileThread(
const GURL& origin_url, FileSystemType type, const FilePath& unused,
bool create) {
if (file_system_options_->is_incognito())
@@ -426,6 +371,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())

Powered by Google App Engine
This is Rietveld 408576698