summaryrefslogtreecommitdiffstats
path: root/webkit/browser
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-20 22:43:55 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-20 22:43:55 +0000
commitc79859b8aaf03c6ca791ee98c6e2a9558e070a26 (patch)
tree82fd2f41155e05d176aea7211a6c277031a1375d /webkit/browser
parent5062a57b9dc728cfff5c922709c37f8dfb984b8e (diff)
downloadchromium_src-c79859b8aaf03c6ca791ee98c6e2a9558e070a26.zip
chromium_src-c79859b8aaf03c6ca791ee98c6e2a9558e070a26.tar.gz
chromium_src-c79859b8aaf03c6ca791ee98c6e2a9558e070a26.tar.bz2
Revert of Revert of Add mechanism to auto mount file systems in response to a URL request. (https://codereview.chromium.org/206253002/)
Reason for revert: This revert did not fix the breakage it was suspected of. Original issue's description: > Revert of Add mechanism to auto mount file systems in response to a URL request. (https://codereview.chromium.org/195923002/) > > Reason for revert: > Best guess that this broke > SyncFileSystemApiTest.WriteFileThenGetUsage > SyncFileSystemApiTest.GetFileStatuses > MediaGalleriesPlatformAppBrowserTest.MediaGalleriesCopyTo > on XP Tests(1). > > Original issue's description: > > Add mechanism to auto mount file systems in response to a URL request. > > > > This code adds a hook for when a file system URL request can not be cracked. > > It will allow external media galleries file systems to be lazily created. > > > > BUG=160900 > > > > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=258064 > > TBR=kinuko@chromium.org,tzik@chromium.org,joi@chromium.org,sky@chromium.org,vandebo@chromium.org > NOTREECHECKS=true > NOTRY=true > BUG=160900 > > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=258261 TBR=kinuko@chromium.org,tzik@chromium.org,joi@chromium.org,sky@chromium.org,pneubeck@chromium.org BUG=160900 Review URL: https://codereview.chromium.org/199903003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258440 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser')
-rw-r--r--webkit/browser/fileapi/external_mount_points.h4
-rw-r--r--webkit/browser/fileapi/file_system_context.cc19
-rw-r--r--webkit/browser/fileapi/file_system_context.h30
-rw-r--r--webkit/browser/fileapi/file_system_dir_url_request_job.cc20
-rw-r--r--webkit/browser/fileapi/file_system_dir_url_request_job.h3
-rw-r--r--webkit/browser/fileapi/file_system_url_request_job.cc19
-rw-r--r--webkit/browser/fileapi/file_system_url_request_job.h8
-rw-r--r--webkit/browser/fileapi/file_system_url_request_job_factory.cc19
-rw-r--r--webkit/browser/fileapi/file_system_url_request_job_factory.h5
9 files changed, 113 insertions, 14 deletions
diff --git a/webkit/browser/fileapi/external_mount_points.h b/webkit/browser/fileapi/external_mount_points.h
index 9fb3cc3..1748a09 100644
--- a/webkit/browser/fileapi/external_mount_points.h
+++ b/webkit/browser/fileapi/external_mount_points.h
@@ -21,10 +21,8 @@ class FilePath;
}
namespace fileapi {
-class FileSystemURL;
-}
-namespace fileapi {
+class FileSystemURL;
// Manages external filesystem namespaces that are identified by 'mount name'
// and are persisted until RevokeFileSystem is called.
diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc
index c42eadb..067b25b 100644
--- a/webkit/browser/fileapi/file_system_context.cc
+++ b/webkit/browser/fileapi/file_system_context.cc
@@ -8,6 +8,7 @@
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/task_runner_util.h"
+#include "net/url_request/url_request.h"
#include "url/gurl.h"
#include "webkit/browser/blob/file_stream_reader.h"
#include "webkit/browser/fileapi/copy_or_move_file_validator.h"
@@ -113,6 +114,7 @@ FileSystemContext::FileSystemContext(
quota::SpecialStoragePolicy* special_storage_policy,
quota::QuotaManagerProxy* quota_manager_proxy,
ScopedVector<FileSystemBackend> additional_backends,
+ const std::vector<URLRequestAutoMountHandler>& auto_mount_handlers,
const base::FilePath& partition_path,
const FileSystemOptions& options)
: io_task_runner_(io_task_runner),
@@ -133,6 +135,7 @@ FileSystemContext::FileSystemContext(
special_storage_policy,
options)),
additional_backends_(additional_backends.Pass()),
+ auto_mount_handlers_(auto_mount_handlers),
external_mount_points_(external_mount_points),
partition_path_(partition_path),
is_incognito_(options.is_incognito()),
@@ -337,6 +340,22 @@ void FileSystemContext::ResolveURL(
callback));
}
+void FileSystemContext::AttemptAutoMountForURLRequest(
+ const net::URLRequest* url_request,
+ const std::string& storage_domain,
+ const StatusCallback& callback) {
+ FileSystemURL filesystem_url(url_request->url());
+ if (filesystem_url.type() == kFileSystemTypeExternal) {
+ for (size_t i = 0; i < auto_mount_handlers_.size(); i++) {
+ if (auto_mount_handlers_[i].Run(url_request, filesystem_url,
+ storage_domain, callback)) {
+ return;
+ }
+ }
+ }
+ callback.Run(base::File::FILE_ERROR_NOT_FOUND);
+}
+
void FileSystemContext::DeleteFileSystem(
const GURL& origin_url,
FileSystemType type,
diff --git a/webkit/browser/fileapi/file_system_context.h b/webkit/browser/fileapi/file_system_context.h
index 62841d1..ba91af7 100644
--- a/webkit/browser/fileapi/file_system_context.h
+++ b/webkit/browser/fileapi/file_system_context.h
@@ -38,6 +38,10 @@ class QuotaManagerProxy;
class SpecialStoragePolicy;
}
+namespace net {
+class URLRequest;
+}
+
namespace webkit_blob {
class BlobURLRequestJobTest;
class FileStreamReader;
@@ -65,6 +69,18 @@ class SandboxFileSystemBackend;
struct DefaultContextDeleter;
struct FileSystemInfo;
+// An auto mount handler will attempt to mount the file system requested in
+// |url_request|. If the URL is for this auto mount handler, it returns true
+// and calls |callback| when the attempt is complete. If the auto mounter
+// does not recognize the URL, it returns false and does not call |callback|.
+// Called on the IO thread.
+typedef base::Callback<bool(
+ const net::URLRequest* url_request,
+ const FileSystemURL& filesystem_url,
+ const std::string& storage_domain,
+ const base::Callback<void(base::File::Error result)>& callback)>
+ URLRequestAutoMountHandler;
+
// This class keeps and provides a file system context for FileSystem API.
// An instance of this class is created and owned by profile.
class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
@@ -95,6 +111,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
// to serve filesystem requests for non-regular types.
// If none is given, this context only handles HTML5 Sandbox FileSystem
// and Drag-and-drop Isolated FileSystem requests.
+ //
+ // |auto_mount_handlers| are used to resolve calls to
+ // AttemptAutoMountForURLRequest. Only external filesystems are auto mounted
+ // when a filesystem: URL request is made.
FileSystemContext(
base::SingleThreadTaskRunner* io_task_runner,
base::SequencedTaskRunner* file_task_runner,
@@ -102,6 +122,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
quota::SpecialStoragePolicy* special_storage_policy,
quota::QuotaManagerProxy* quota_manager_proxy,
ScopedVector<FileSystemBackend> additional_backends,
+ const std::vector<URLRequestAutoMountHandler>& auto_mount_handlers,
const base::FilePath& partition_path,
const FileSystemOptions& options);
@@ -193,6 +214,13 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
const FileSystemURL& url,
const ResolveURLCallback& callback);
+ // Attempts to mount the filesystem needed to satisfy |url_request| made
+ // from |storage_domain|. If an appropriate file system is not found,
+ // callback will return an error.
+ void AttemptAutoMountForURLRequest(const net::URLRequest* url_request,
+ const std::string& storage_domain,
+ const StatusCallback& callback);
+
// Deletes the filesystem for the given |origin_url| and |type|. This should
// be called on the IO thread.
void DeleteFileSystem(
@@ -343,6 +371,8 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext
scoped_ptr<PluginPrivateFileSystemBackend> plugin_private_backend_;
ScopedVector<FileSystemBackend> additional_backends_;
+ std::vector<URLRequestAutoMountHandler> auto_mount_handlers_;
+
// Registered file system backends.
// The map must be constructed in the constructor since it can be accessed
// on multiple threads.
diff --git a/webkit/browser/fileapi/file_system_dir_url_request_job.cc b/webkit/browser/fileapi/file_system_dir_url_request_job.cc
index b0f1966..fffe739 100644
--- a/webkit/browser/fileapi/file_system_dir_url_request_job.cc
+++ b/webkit/browser/fileapi/file_system_dir_url_request_job.cc
@@ -35,8 +35,10 @@ namespace fileapi {
FileSystemDirURLRequestJob::FileSystemDirURLRequestJob(
URLRequest* request,
NetworkDelegate* network_delegate,
+ const std::string& storage_domain,
FileSystemContext* file_system_context)
: URLRequestJob(request, network_delegate),
+ storage_domain_(storage_domain),
file_system_context_(file_system_context),
weak_factory_(this) {
}
@@ -81,6 +83,14 @@ void FileSystemDirURLRequestJob::StartAsync() {
if (!request_)
return;
url_ = file_system_context_->CrackURL(request_->url());
+ if (!url_.is_valid()) {
+ file_system_context_->AttemptAutoMountForURLRequest(
+ request_,
+ storage_domain_,
+ base::Bind(&FileSystemDirURLRequestJob::DidAttemptAutoMount,
+ weak_factory_.GetWeakPtr()));
+ return;
+ }
if (!file_system_context_->CanServeURLRequest(url_)) {
// In incognito mode the API is not usable and there should be no data.
if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) {
@@ -99,6 +109,16 @@ void FileSystemDirURLRequestJob::StartAsync() {
base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this));
}
+void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) {
+ if (result >= 0 &&
+ file_system_context_->CrackURL(request_->url()).is_valid()) {
+ StartAsync();
+ } else {
+ NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
+ net::ERR_FILE_NOT_FOUND));
+ }
+}
+
void FileSystemDirURLRequestJob::DidReadDirectory(
base::File::Error result,
const std::vector<DirectoryEntry>& entries,
diff --git a/webkit/browser/fileapi/file_system_dir_url_request_job.h b/webkit/browser/fileapi/file_system_dir_url_request_job.h
index 7346225..67e9df3 100644
--- a/webkit/browser/fileapi/file_system_dir_url_request_job.h
+++ b/webkit/browser/fileapi/file_system_dir_url_request_job.h
@@ -28,6 +28,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileSystemDirURLRequestJob
FileSystemDirURLRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
+ const std::string& storage_domain,
FileSystemContext* file_system_context);
// URLRequestJob methods:
@@ -49,12 +50,14 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileSystemDirURLRequestJob
virtual ~FileSystemDirURLRequestJob();
void StartAsync();
+ void DidAttemptAutoMount(base::File::Error result);
void DidReadDirectory(base::File::Error result,
const std::vector<DirectoryEntry>& entries,
bool has_more);
std::string data_;
FileSystemURL url_;
+ const std::string storage_domain_;
FileSystemContext* file_system_context_;
base::WeakPtrFactory<FileSystemDirURLRequestJob> weak_factory_;
diff --git a/webkit/browser/fileapi/file_system_url_request_job.cc b/webkit/browser/fileapi/file_system_url_request_job.cc
index fe445649..8ccc5bb 100644
--- a/webkit/browser/fileapi/file_system_url_request_job.cc
+++ b/webkit/browser/fileapi/file_system_url_request_job.cc
@@ -57,8 +57,10 @@ static net::HttpResponseHeaders* CreateHttpResponseHeaders() {
FileSystemURLRequestJob::FileSystemURLRequestJob(
URLRequest* request,
NetworkDelegate* network_delegate,
+ const std::string& storage_domain,
FileSystemContext* file_system_context)
: URLRequestJob(request, network_delegate),
+ storage_domain_(storage_domain),
file_system_context_(file_system_context),
is_directory_(false),
remaining_bytes_(0),
@@ -157,6 +159,14 @@ void FileSystemURLRequestJob::StartAsync() {
return;
DCHECK(!reader_.get());
url_ = file_system_context_->CrackURL(request_->url());
+ if (!url_.is_valid()) {
+ file_system_context_->AttemptAutoMountForURLRequest(
+ request_,
+ storage_domain_,
+ base::Bind(&FileSystemURLRequestJob::DidAttemptAutoMount,
+ weak_factory_.GetWeakPtr()));
+ return;
+ }
if (!file_system_context_->CanServeURLRequest(url_)) {
// In incognito mode the API is not usable and there should be no data.
NotifyFailed(net::ERR_FILE_NOT_FOUND);
@@ -168,6 +178,15 @@ void FileSystemURLRequestJob::StartAsync() {
weak_factory_.GetWeakPtr()));
}
+void FileSystemURLRequestJob::DidAttemptAutoMount(base::File::Error result) {
+ if (result >= 0 &&
+ file_system_context_->CrackURL(request_->url()).is_valid()) {
+ StartAsync();
+ } else {
+ NotifyFailed(net::ERR_FILE_NOT_FOUND);
+ }
+}
+
void FileSystemURLRequestJob::DidGetMetadata(
base::File::Error error_code,
const base::File::Info& file_info) {
diff --git a/webkit/browser/fileapi/file_system_url_request_job.h b/webkit/browser/fileapi/file_system_url_request_job.h
index 8fa766c..29b42a5 100644
--- a/webkit/browser/fileapi/file_system_url_request_job.h
+++ b/webkit/browser/fileapi/file_system_url_request_job.h
@@ -36,6 +36,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileSystemURLRequestJob
FileSystemURLRequestJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
+ const std::string& storage_domain,
FileSystemContext* file_system_context);
// URLRequestJob methods:
@@ -60,12 +61,13 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileSystemURLRequestJob
virtual ~FileSystemURLRequestJob();
void StartAsync();
- void DidGetMetadata(
- base::File::Error error_code,
- const base::File::Info& file_info);
+ void DidAttemptAutoMount(base::File::Error result);
+ void DidGetMetadata(base::File::Error error_code,
+ const base::File::Info& file_info);
void DidRead(int result);
void NotifyFailed(int rv);
+ const std::string storage_domain_;
FileSystemContext* file_system_context_;
scoped_ptr<webkit_blob::FileStreamReader> reader_;
FileSystemURL url_;
diff --git a/webkit/browser/fileapi/file_system_url_request_job_factory.cc b/webkit/browser/fileapi/file_system_url_request_job_factory.cc
index 76ae7c9..3add372 100644
--- a/webkit/browser/fileapi/file_system_url_request_job_factory.cc
+++ b/webkit/browser/fileapi/file_system_url_request_job_factory.cc
@@ -19,7 +19,8 @@ namespace {
class FileSystemProtocolHandler
: public net::URLRequestJobFactory::ProtocolHandler {
public:
- explicit FileSystemProtocolHandler(FileSystemContext* context);
+ FileSystemProtocolHandler(const std::string& storage_domain,
+ FileSystemContext* context);
virtual ~FileSystemProtocolHandler();
virtual net::URLRequestJob* MaybeCreateJob(
@@ -27,6 +28,8 @@ class FileSystemProtocolHandler
net::NetworkDelegate* network_delegate) const OVERRIDE;
private:
+ const std::string storage_domain_;
+
// No scoped_refptr because |file_system_context_| is owned by the
// ProfileIOData, which also owns this ProtocolHandler.
FileSystemContext* const file_system_context_;
@@ -35,8 +38,10 @@ class FileSystemProtocolHandler
};
FileSystemProtocolHandler::FileSystemProtocolHandler(
+ const std::string& storage_domain,
FileSystemContext* context)
- : file_system_context_(context) {
+ : storage_domain_(storage_domain),
+ file_system_context_(context) {
DCHECK(file_system_context_);
}
@@ -51,18 +56,18 @@ net::URLRequestJob* FileSystemProtocolHandler::MaybeCreateJob(
// redirects back here, by adding a / to the URL.
if (!path.empty() && path[path.size() - 1] == '/') {
return new FileSystemDirURLRequestJob(
- request, network_delegate, file_system_context_);
+ request, network_delegate, storage_domain_, file_system_context_);
}
return new FileSystemURLRequestJob(
- request, network_delegate, file_system_context_);
+ request, network_delegate, storage_domain_, file_system_context_);
}
} // anonymous namespace
-net::URLRequestJobFactory::ProtocolHandler*
-CreateFileSystemProtocolHandler(FileSystemContext* context) {
+net::URLRequestJobFactory::ProtocolHandler* CreateFileSystemProtocolHandler(
+ const std::string& storage_domain, FileSystemContext* context) {
DCHECK(context);
- return new FileSystemProtocolHandler(context);
+ return new FileSystemProtocolHandler(storage_domain, context);
}
} // namespace fileapi
diff --git a/webkit/browser/fileapi/file_system_url_request_job_factory.h b/webkit/browser/fileapi/file_system_url_request_job_factory.h
index 5bd3c0f..bcc55dc 100644
--- a/webkit/browser/fileapi/file_system_url_request_job_factory.h
+++ b/webkit/browser/fileapi/file_system_url_request_job_factory.h
@@ -5,6 +5,8 @@
#ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_URL_REQUEST_JOB_FACTORY_H_
#define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_URL_REQUEST_JOB_FACTORY_H_
+#include <string>
+
#include "net/url_request/url_request_job_factory.h"
#include "webkit/browser/webkit_storage_browser_export.h"
@@ -21,7 +23,8 @@ class FileSystemContext;
// Currently, this is only used by ProfileIOData which owns |context| and the
// ProtocolHandler.
WEBKIT_STORAGE_BROWSER_EXPORT net::URLRequestJobFactory::ProtocolHandler*
- CreateFileSystemProtocolHandler(FileSystemContext* context);
+ CreateFileSystemProtocolHandler(const std::string& storage_domain,
+ FileSystemContext* context);
} // namespace fileapi