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

Unified Diff: chrome/browser/extensions/api/extfs/extfs_api.cc

Issue 16439016: extfs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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: chrome/browser/extensions/api/extfs/extfs_api.cc
diff --git a/chrome/browser/extensions/api/extfs/extfs_api.cc b/chrome/browser/extensions/api/extfs/extfs_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d4dbb01c953f4367735c05b65bacc767220a9586
--- /dev/null
+++ b/chrome/browser/extensions/api/extfs/extfs_api.cc
@@ -0,0 +1,207 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/extfs/extfs_api.h"
+
+#include "chrome/browser/extensions/event_names.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/extfs.h"
+#include "content/public/browser/browser_context.h"
+#include "webkit/browser/blob/file_stream_reader.h"
+#include "webkit/browser/fileapi/external_mount_points.h"
+#include "webkit/browser/fileapi/file_system_url.h"
+#include "webkit/browser/fileapi/remote_file_system_proxy.h"
+
+namespace extensions {
+
+class ExtfsProxy : public fileapi::RemoteFileSystemProxyInterface {
+ public:
+ ExtfsProxy(EventRouter* event_router,
+ const std::string& extension_id,
+ const std::string& mount_name)
+ : request_id_(0),
+ event_router_(event_router),
+ extension_id_(extension_id) {
+ }
+
+ // fileapi::RemoteFileSystemProxyInterface overrides.
+ virtual void GetFileInfo(
+ const fileapi::FileSystemURL& url,
+ const fileapi::FileSystemOperation::GetMetadataCallback& callback)
+ OVERRIDE {
+ base::FilePath extfs_path(FILE_PATH_LITERAL("/"));
+ base::FilePath::FromUTF8Unsafe("/extfs").AppendRelativePath(url.path(),
+ &extfs_path);
+ LOG(ERROR) << "@@ ExtfsProxy::GetFileInfo: " << extfs_path.value();
+
+ get_metadata_callback_map_[request_id_] = callback;
+ scoped_ptr<base::ListValue> values(new ListValue());
+ values->AppendInteger(request_id_);
+ values->AppendString(extfs_path.value());
+ scoped_ptr<Event> event(new Event(event_names::kOnGetFileInfo,
+ values.Pass()));
+
+ event_router_->DispatchEventToExtension(extension_id_, event.Pass());
+ ++request_id_;
+ }
+ void DidGetFileInfo(int request_id,
+ const base::PlatformFileError file_error,
+ const base::PlatformFileInfo& file_info,
+ const base::FilePath& file_path) {
+ LOG(ERROR) << "@@ " << __PRETTY_FUNCTION__;
+ GetMetadataCallbackMap::iterator iter =
+ get_metadata_callback_map_.find(request_id);
+ DCHECK(iter != get_metadata_callback_map_.end());
+ iter->second.Run(file_error, file_info, file_path);
+ get_metadata_callback_map_.erase(iter);
+ }
+
+ virtual void Copy(
+ const fileapi::FileSystemURL& src_url,
+ const fileapi::FileSystemURL& dest_url,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void Move(
+ const fileapi::FileSystemURL& src_url,
+ const fileapi::FileSystemURL& dest_url,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void ReadDirectory(
+ const fileapi::FileSystemURL& url,
+ const fileapi::FileSystemOperation::ReadDirectoryCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void Remove(
+ const fileapi::FileSystemURL& url, bool recursive,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void CreateDirectory(
+ const fileapi::FileSystemURL& file_url,
+ bool exclusive,
+ bool recursive,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void CreateFile(
+ const fileapi::FileSystemURL& file_url,
+ bool exclusive,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void Truncate(
+ const fileapi::FileSystemURL& file_url, int64 length,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void CreateSnapshotFile(
+ const fileapi::FileSystemURL& url,
+ const fileapi::FileSystemOperation::SnapshotFileCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void CreateWritableSnapshotFile(
+ const fileapi::FileSystemURL& url,
+ const fileapi::WritableSnapshotFile& callback) OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void OpenFile(
+ const fileapi::FileSystemURL& url,
+ int file_flags,
+ base::ProcessHandle peer_handle,
+ const OpenFileCallback& callback) OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void NotifyCloseFile(const fileapi::FileSystemURL& url) OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual void TouchFile(
+ const fileapi::FileSystemURL& url,
+ const base::Time& last_access_time,
+ const base::Time& last_modified_time,
+ const fileapi::FileSystemOperation::StatusCallback& callback)
+ OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ }
+ virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
+ base::SequencedTaskRunner* file_task_runner,
+ const fileapi::FileSystemURL& url,
+ int64 offset,
+ const base::Time& expected_modification_time) OVERRIDE {
+ NOTREACHED() << "@@ not implemented";
+ return scoped_ptr<webkit_blob::FileStreamReader>();
+ }
+
+ protected:
+ virtual ~ExtfsProxy() {
+ }
+
+ private:
+ int request_id_;
+ EventRouter* event_router_;
+ const std::string extension_id_;
+ typedef std::map<int,
+ fileapi::FileSystemOperation::GetMetadataCallback> GetMetadataCallbackMap;
+ GetMetadataCallbackMap get_metadata_callback_map_;
+};
+
+ExtfsProxy* g_extfs_router_;
+
+bool ExtfsAddMountPointFunction::RunImpl() {
+ scoped_ptr<api::extfs::AddMountPoint::Params> params(
+ api::extfs::AddMountPoint::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+ LOG(ERROR) << "@@ " << __PRETTY_FUNCTION__;
+ LOG(ERROR) << "@@ mount_name: " << params->mount_name;
+ LOG(ERROR) << "@@ extension_id: " << extension_id();
+
+ EventRouter* event_router = ExtensionSystem::Get(profile())->event_router();
+ // TODO...
+ DCHECK(!g_extfs_router_);
+ g_extfs_router_ = new ExtfsProxy(event_router,
+ extension_id(),
+ params->mount_name);
+
+ fileapi::ExternalMountPoints* mount_points =
+ content::BrowserContext::GetMountPoints(profile_);
+ DCHECK(mount_points);
+
+ bool success = mount_points->RegisterRemoteFileSystem(
+ "extfs",
+ fileapi::kFileSystemTypeDrive,
+ g_extfs_router_,
+ base::FilePath::FromUTF8Unsafe("/extfs"));
+ DCHECK(success);
+
+ SetResult(base::Value::CreateBooleanValue(true));
+ SendResponse(true);
+ return true;
+}
+
+bool ExtfsDidGetFileInfoFunction::RunImpl() {
+ scoped_ptr<api::extfs::DidGetFileInfo::Params> params(
+ api::extfs::DidGetFileInfo::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+ LOG(ERROR) << "@@ " << __PRETTY_FUNCTION__;
+ base::PlatformFileInfo file_info;
+ file_info.is_directory = params->entry.is_directory;
+ g_extfs_router_->DidGetFileInfo(params->request_id,
+ base::PLATFORM_FILE_OK,
+ file_info,
+ base::FilePath::FromUTF8Unsafe("/"));
+ return true;
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/extfs/extfs_api.h ('k') | chrome/browser/extensions/api/extfs/extfs_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698