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

Unified Diff: webkit/tools/test_shell/simple_file_system.cc

Issue 4879001: Extend simple_file_system to use SandboxedFileSystemOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.h ('k') | webkit/tools/test_shell/test_shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/tools/test_shell/simple_file_system.cc
diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc
index 520f709caffbd72f61b12ef8885301b0ca24708e..29ea45e323209318487e565344ed9ac70bf17813 100644
--- a/webkit/tools/test_shell/simple_file_system.cc
+++ b/webkit/tools/test_shell/simple_file_system.cc
@@ -6,58 +6,85 @@
#include "base/file_path.h"
#include "base/message_loop_proxy.h"
+#include "base/scoped_callback_factory.h"
#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "googleurl/src/gurl.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFileInfo.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemEntry.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
+#include "webkit/fileapi/file_system_path_manager.h"
+#include "webkit/fileapi/file_system_types.h"
+#include "webkit/fileapi/sandboxed_file_system_context.h"
+#include "webkit/fileapi/sandboxed_file_system_operation.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_file_writer.h"
+using base::WeakPtr;
+
using WebKit::WebFileInfo;
+using WebKit::WebFileSystem;
using WebKit::WebFileSystemCallbacks;
using WebKit::WebFileSystemEntry;
using WebKit::WebFileWriter;
using WebKit::WebFileWriterClient;
+using WebKit::WebFrame;
+using WebKit::WebSecurityOrigin;
using WebKit::WebString;
using WebKit::WebVector;
+using fileapi::FileSystemCallbackDispatcher;
+using fileapi::SandboxedFileSystemContext;
+using fileapi::SandboxedFileSystemOperation;
+
namespace {
-class TestShellFileSystemCallbackDispatcher
- : public fileapi::FileSystemCallbackDispatcher {
+class SimpleFileSystemCallbackDispatcher
+ : public FileSystemCallbackDispatcher {
public:
- TestShellFileSystemCallbackDispatcher(
- SimpleFileSystem* file_system,
+ SimpleFileSystemCallbackDispatcher(
+ const WeakPtr<SimpleFileSystem>& file_system,
WebFileSystemCallbacks* callbacks)
: file_system_(file_system),
- callbacks_(callbacks),
- request_id_(-1) {
+ callbacks_(callbacks) {
}
- void set_request_id(int request_id) { request_id_ = request_id; }
+ ~SimpleFileSystemCallbackDispatcher() {
+ DCHECK(!operation_.get());
+ }
+
+ void set_operation(SandboxedFileSystemOperation* operation) {
+ operation_.reset(operation);
+ }
virtual void DidSucceed() {
- callbacks_->didSucceed();
- file_system_->RemoveCompletedOperation(request_id_);
+ if (file_system_)
+ callbacks_->didSucceed();
+ RemoveOperation();
}
virtual void DidReadMetadata(const base::PlatformFileInfo& info) {
+ DCHECK(file_system_);
WebFileInfo web_file_info;
web_file_info.length = info.size;
web_file_info.modificationTime = info.last_modified.ToDoubleT();
web_file_info.type = info.is_directory ?
WebFileInfo::TypeDirectory : WebFileInfo::TypeFile;
callbacks_->didReadMetadata(web_file_info);
- file_system_->RemoveCompletedOperation(request_id_);
+ RemoveOperation();
}
virtual void DidReadDirectory(
const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more) {
+ DCHECK(file_system_);
std::vector<WebFileSystemEntry> web_entries_vector;
for (std::vector<base::FileUtilProxy::Entry>::const_iterator it =
- entries.begin(); it != entries.end(); ++it) {
+ entries.begin(); it != entries.end(); ++it) {
WebFileSystemEntry entry;
entry.name = webkit_glue::FilePathStringToWebString(it->name);
entry.isDirectory = it->is_directory;
@@ -66,17 +93,25 @@ class TestShellFileSystemCallbackDispatcher
WebVector<WebKit::WebFileSystemEntry> web_entries =
web_entries_vector;
callbacks_->didReadDirectory(web_entries, has_more);
- file_system_->RemoveCompletedOperation(request_id_);
+ RemoveOperation();
}
- virtual void DidOpenFileSystem(const std::string&, const FilePath&) {
- NOTREACHED();
+ virtual void DidOpenFileSystem(
+ const std::string& name, const FilePath& path) {
+ DCHECK(file_system_);
+ if (path.empty())
+ callbacks_->didFail(WebKit::WebFileErrorSecurity);
+ else
+ callbacks_->didOpenFileSystem(
+ UTF8ToUTF16(name), webkit_glue::FilePathToWebString(path));
+ RemoveOperation();
}
virtual void DidFail(base::PlatformFileError error_code) {
+ DCHECK(file_system_);
callbacks_->didFail(
webkit_glue::PlatformFileErrorToWebFileError(error_code));
- file_system_->RemoveCompletedOperation(request_id_);
+ RemoveOperation();
}
virtual void DidWrite(int64, bool) {
@@ -84,18 +119,61 @@ class TestShellFileSystemCallbackDispatcher
}
private:
- SimpleFileSystem* file_system_;
+ void RemoveOperation() {
+ // We need to make sure operation_ is null when we delete the operation
+ // (which in turn deletes this dispatcher instance).
+ scoped_ptr<SandboxedFileSystemOperation> operation;
+ operation.swap(operation_);
+ operation.reset();
+ }
+
+ WeakPtr<SimpleFileSystem> file_system_;
WebFileSystemCallbacks* callbacks_;
- int request_id_;
+ scoped_ptr<SandboxedFileSystemOperation> operation_;
};
-} // namespace
+} // namespace
+
+SimpleFileSystem::SimpleFileSystem() {
+ if (file_system_dir_.CreateUniqueTempDir()) {
+ sandboxed_context_.reset(new SandboxedFileSystemContext(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ file_system_dir_.path(),
+ false /* incognito */,
+ true /* allow_file_access */,
+ false /* unlimited_quota */));
+ } else {
+ LOG(WARNING) << "Failed to create a temp dir for the filesystem."
+ "FileSystem feature will be disabled.";
+ }
+}
SimpleFileSystem::~SimpleFileSystem() {
- // Drop all the operations.
- for (OperationsMap::const_iterator iter(&operations_);
- !iter.IsAtEnd(); iter.Advance())
- operations_.Remove(iter.GetCurrentKey());
+}
+
+void SimpleFileSystem::OpenFileSystem(
+ WebFrame* frame, WebFileSystem::Type web_filesystem_type,
+ long long, bool create,
+ WebFileSystemCallbacks* callbacks) {
+ if (!frame || !sandboxed_context_.get()) {
+ // The FileSystem temp directory was not initialized successfully.
+ callbacks->didFail(WebKit::WebFileErrorSecurity);
+ return;
+ }
+
+ fileapi::FileSystemType type;
+ if (web_filesystem_type == WebFileSystem::TypeTemporary)
+ type = fileapi::kFileSystemTypeTemporary;
+ else if (web_filesystem_type == WebFileSystem::TypePersistent)
+ type = fileapi::kFileSystemTypePersistent;
+ else {
+ // Unknown type filesystem is requested.
+ callbacks->didFail(WebKit::WebFileErrorSecurity);
+ return;
+ }
+
+ GURL origin_url(frame->securityOrigin().toString());
+ GetNewOperation(callbacks)->OpenFileSystem(origin_url, type, create);
}
void SimpleFileSystem::move(
@@ -177,18 +255,13 @@ WebFileWriter* SimpleFileSystem::createFileWriter(
return new SimpleFileWriter(path, client);
}
-fileapi::FileSystemOperation* SimpleFileSystem::GetNewOperation(
+SandboxedFileSystemOperation* SimpleFileSystem::GetNewOperation(
WebFileSystemCallbacks* callbacks) {
- // This pointer will be owned by |operation|.
- TestShellFileSystemCallbackDispatcher* dispatcher =
- new TestShellFileSystemCallbackDispatcher(this, callbacks);
- fileapi::FileSystemOperation* operation = new fileapi::FileSystemOperation(
- dispatcher, base::MessageLoopProxy::CreateForCurrentThread());
- int32 request_id = operations_.Add(operation);
- dispatcher->set_request_id(request_id);
+ SimpleFileSystemCallbackDispatcher* dispatcher =
+ new SimpleFileSystemCallbackDispatcher(AsWeakPtr(), callbacks);
+ SandboxedFileSystemOperation* operation = new SandboxedFileSystemOperation(
+ dispatcher, base::MessageLoopProxy::CreateForCurrentThread(),
+ sandboxed_context_.get());
+ dispatcher->set_operation(operation);
return operation;
}
-
-void SimpleFileSystem::RemoveCompletedOperation(int request_id) {
- operations_.Remove(request_id);
-}
« no previous file with comments | « webkit/tools/test_shell/simple_file_system.h ('k') | webkit/tools/test_shell/test_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698