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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/extfs/extfs_api.h"
6
7 #include "chrome/browser/extensions/event_names.h"
8 #include "chrome/browser/extensions/event_router.h"
9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/api/extfs.h"
12 #include "content/public/browser/browser_context.h"
13 #include "webkit/browser/blob/file_stream_reader.h"
14 #include "webkit/browser/fileapi/external_mount_points.h"
15 #include "webkit/browser/fileapi/file_system_url.h"
16 #include "webkit/browser/fileapi/remote_file_system_proxy.h"
17
18 namespace extensions {
19
20 class ExtfsProxy : public fileapi::RemoteFileSystemProxyInterface {
21 public:
22 ExtfsProxy(EventRouter* event_router,
23 const std::string& extension_id,
24 const std::string& mount_name)
25 : request_id_(0),
26 event_router_(event_router),
27 extension_id_(extension_id) {
28 }
29
30 // fileapi::RemoteFileSystemProxyInterface overrides.
31 virtual void GetFileInfo(
32 const fileapi::FileSystemURL& url,
33 const fileapi::FileSystemOperation::GetMetadataCallback& callback)
34 OVERRIDE {
35 base::FilePath extfs_path(FILE_PATH_LITERAL("/"));
36 base::FilePath::FromUTF8Unsafe("/extfs").AppendRelativePath(url.path(),
37 &extfs_path);
38 LOG(ERROR) << "@@ ExtfsProxy::GetFileInfo: " << extfs_path.value();
39
40 get_metadata_callback_map_[request_id_] = callback;
41 scoped_ptr<base::ListValue> values(new ListValue());
42 values->AppendInteger(request_id_);
43 values->AppendString(extfs_path.value());
44 scoped_ptr<Event> event(new Event(event_names::kOnGetFileInfo,
45 values.Pass()));
46
47 event_router_->DispatchEventToExtension(extension_id_, event.Pass());
48 ++request_id_;
49 }
50 void DidGetFileInfo(int request_id,
51 const base::PlatformFileError file_error,
52 const base::PlatformFileInfo& file_info,
53 const base::FilePath& file_path) {
54 LOG(ERROR) << "@@ " << __PRETTY_FUNCTION__;
55 GetMetadataCallbackMap::iterator iter =
56 get_metadata_callback_map_.find(request_id);
57 DCHECK(iter != get_metadata_callback_map_.end());
58 iter->second.Run(file_error, file_info, file_path);
59 get_metadata_callback_map_.erase(iter);
60 }
61
62 virtual void Copy(
63 const fileapi::FileSystemURL& src_url,
64 const fileapi::FileSystemURL& dest_url,
65 const fileapi::FileSystemOperation::StatusCallback& callback)
66 OVERRIDE {
67 NOTREACHED() << "@@ not implemented";
68 }
69 virtual void Move(
70 const fileapi::FileSystemURL& src_url,
71 const fileapi::FileSystemURL& dest_url,
72 const fileapi::FileSystemOperation::StatusCallback& callback)
73 OVERRIDE {
74 NOTREACHED() << "@@ not implemented";
75 }
76 virtual void ReadDirectory(
77 const fileapi::FileSystemURL& url,
78 const fileapi::FileSystemOperation::ReadDirectoryCallback& callback)
79 OVERRIDE {
80 NOTREACHED() << "@@ not implemented";
81 }
82 virtual void Remove(
83 const fileapi::FileSystemURL& url, bool recursive,
84 const fileapi::FileSystemOperation::StatusCallback& callback)
85 OVERRIDE {
86 NOTREACHED() << "@@ not implemented";
87 }
88 virtual void CreateDirectory(
89 const fileapi::FileSystemURL& file_url,
90 bool exclusive,
91 bool recursive,
92 const fileapi::FileSystemOperation::StatusCallback& callback)
93 OVERRIDE {
94 NOTREACHED() << "@@ not implemented";
95 }
96 virtual void CreateFile(
97 const fileapi::FileSystemURL& file_url,
98 bool exclusive,
99 const fileapi::FileSystemOperation::StatusCallback& callback)
100 OVERRIDE {
101 NOTREACHED() << "@@ not implemented";
102 }
103 virtual void Truncate(
104 const fileapi::FileSystemURL& file_url, int64 length,
105 const fileapi::FileSystemOperation::StatusCallback& callback)
106 OVERRIDE {
107 NOTREACHED() << "@@ not implemented";
108 }
109 virtual void CreateSnapshotFile(
110 const fileapi::FileSystemURL& url,
111 const fileapi::FileSystemOperation::SnapshotFileCallback& callback)
112 OVERRIDE {
113 NOTREACHED() << "@@ not implemented";
114 }
115 virtual void CreateWritableSnapshotFile(
116 const fileapi::FileSystemURL& url,
117 const fileapi::WritableSnapshotFile& callback) OVERRIDE {
118 NOTREACHED() << "@@ not implemented";
119 }
120 virtual void OpenFile(
121 const fileapi::FileSystemURL& url,
122 int file_flags,
123 base::ProcessHandle peer_handle,
124 const OpenFileCallback& callback) OVERRIDE {
125 NOTREACHED() << "@@ not implemented";
126 }
127 virtual void NotifyCloseFile(const fileapi::FileSystemURL& url) OVERRIDE {
128 NOTREACHED() << "@@ not implemented";
129 }
130 virtual void TouchFile(
131 const fileapi::FileSystemURL& url,
132 const base::Time& last_access_time,
133 const base::Time& last_modified_time,
134 const fileapi::FileSystemOperation::StatusCallback& callback)
135 OVERRIDE {
136 NOTREACHED() << "@@ not implemented";
137 }
138 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader(
139 base::SequencedTaskRunner* file_task_runner,
140 const fileapi::FileSystemURL& url,
141 int64 offset,
142 const base::Time& expected_modification_time) OVERRIDE {
143 NOTREACHED() << "@@ not implemented";
144 return scoped_ptr<webkit_blob::FileStreamReader>();
145 }
146
147 protected:
148 virtual ~ExtfsProxy() {
149 }
150
151 private:
152 int request_id_;
153 EventRouter* event_router_;
154 const std::string extension_id_;
155 typedef std::map<int,
156 fileapi::FileSystemOperation::GetMetadataCallback> GetMetadat aCallbackMap;
157 GetMetadataCallbackMap get_metadata_callback_map_;
158 };
159
160 ExtfsProxy* g_extfs_router_;
161
162 bool ExtfsAddMountPointFunction::RunImpl() {
163 scoped_ptr<api::extfs::AddMountPoint::Params> params(
164 api::extfs::AddMountPoint::Params::Create(*args_));
165 EXTENSION_FUNCTION_VALIDATE(params.get());
166 LOG(ERROR) << "@@ " << __PRETTY_FUNCTION__;
167 LOG(ERROR) << "@@ mount_name: " << params->mount_name;
168 LOG(ERROR) << "@@ extension_id: " << extension_id();
169
170 EventRouter* event_router = ExtensionSystem::Get(profile())->event_router();
171 // TODO...
172 DCHECK(!g_extfs_router_);
173 g_extfs_router_ = new ExtfsProxy(event_router,
174 extension_id(),
175 params->mount_name);
176
177 fileapi::ExternalMountPoints* mount_points =
178 content::BrowserContext::GetMountPoints(profile_);
179 DCHECK(mount_points);
180
181 bool success = mount_points->RegisterRemoteFileSystem(
182 "extfs",
183 fileapi::kFileSystemTypeDrive,
184 g_extfs_router_,
185 base::FilePath::FromUTF8Unsafe("/extfs"));
186 DCHECK(success);
187
188 SetResult(base::Value::CreateBooleanValue(true));
189 SendResponse(true);
190 return true;
191 }
192
193 bool ExtfsDidGetFileInfoFunction::RunImpl() {
194 scoped_ptr<api::extfs::DidGetFileInfo::Params> params(
195 api::extfs::DidGetFileInfo::Params::Create(*args_));
196 EXTENSION_FUNCTION_VALIDATE(params.get());
197 LOG(ERROR) << "@@ " << __PRETTY_FUNCTION__;
198 base::PlatformFileInfo file_info;
199 file_info.is_directory = params->entry.is_directory;
200 g_extfs_router_->DidGetFileInfo(params->request_id,
201 base::PLATFORM_FILE_OK,
202 file_info,
203 base::FilePath::FromUTF8Unsafe("/"));
204 return true;
205 }
206
207 } // namespace extensions
OLDNEW
« 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