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

Side by Side Diff: webkit/glue/plugins/pepper_file_system.cc

Issue 3394017: Pepper's FileSystem implementation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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
« no previous file with comments | « webkit/glue/plugins/pepper_file_system.h ('k') | webkit/glue/plugins/pepper_plugin_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/plugins/pepper_file_system.h" 5 #include "webkit/glue/plugins/pepper_file_system.h"
6 6
7 #include "base/logging.h"
8 #include "base/ref_counted.h"
9 #include "base/weak_ptr.h"
7 #include "third_party/ppapi/c/dev/ppb_file_system_dev.h" 10 #include "third_party/ppapi/c/dev/ppb_file_system_dev.h"
8 #include "third_party/ppapi/c/pp_completion_callback.h" 11 #include "third_party/ppapi/c/pp_completion_callback.h"
9 #include "third_party/ppapi/c/pp_errors.h" 12 #include "third_party/ppapi/c/pp_time.h"
13 #include "webkit/fileapi/file_system_callback_dispatcher.h"
14 #include "webkit/glue/plugins/pepper_resource.h"
15 #include "webkit/glue/plugins/pepper_error_util.h"
16 #include "webkit/glue/plugins/pepper_file_ref.h"
17 #include "webkit/glue/plugins/pepper_plugin_delegate.h"
18 #include "webkit/glue/plugins/pepper_plugin_instance.h"
19 #include "webkit/glue/plugins/pepper_plugin_module.h"
20 #include "webkit/glue/plugins/pepper_resource.h"
10 21
11 namespace pepper { 22 namespace pepper {
12 23
13 namespace { 24 namespace {
14 25
15 int32_t MakeDirectory(PP_Resource directory_ref, 26 // Instances of this class are deleted when RunCallback() is called.
27 class StatusCallback : public fileapi::FileSystemCallbackDispatcher {
28 public:
29 StatusCallback(base::WeakPtr<pepper::PluginModule> module,
30 PP_CompletionCallback callback)
31 : module_(module),
32 callback_(callback) {
33 }
34
35 // FileSystemCallbackDispatcher implementation.
36 virtual void DidSucceed() {
37 RunCallback(base::PLATFORM_FILE_OK);
38 }
39
40 virtual void DidReadMetadata(const base::PlatformFileInfo&) {
41 NOTREACHED();
42 }
43
44 virtual void DidReadDirectory(
45 const std::vector<base::file_util_proxy::Entry>&, bool) {
46 NOTREACHED();
47 }
48
49 virtual void DidOpenFileSystem(const string16&, const FilePath&) {
50 NOTREACHED();
51 }
52
53 virtual void DidFail(base::PlatformFileError error_code) {
54 RunCallback(error_code);
55 }
56
57 private:
58 void RunCallback(base::PlatformFileError error_code) {
59 PP_CompletionCallback callback = {0};
60 std::swap(callback, callback_);
brettw 2010/09/23 19:35:56 I don't think this swap is necessary in your case.
dumi 2010/09/23 22:31:40 done.
61
62 if (!module_.get() || !callback.func)
63 return;
64
65 PP_RunCompletionCallback(
66 &callback, pepper::PlatformFileErrorToPepperError(error_code));
67
68 delete this;
69 }
70
71 base::WeakPtr<pepper::PluginModule> module_;
72 PP_CompletionCallback callback_;
73 };
74
75 // Instances of this class are deleted when RunCallback() is called.
76 class QueryInfoCallback : public fileapi::FileSystemCallbackDispatcher {
77 public:
78 QueryInfoCallback(base::WeakPtr<pepper::PluginModule> module,
79 PP_CompletionCallback callback,
80 PP_FileInfo_Dev* info,
81 PP_FileSystemType_Dev file_system_type)
82 : module_(module),
83 callback_(callback),
84 info_(info),
85 file_system_type_(file_system_type) {
86 DCHECK(info_);
87 }
88
89 // FileSystemCallbackDispatcher implementation.
90 virtual void DidSucceed() {
91 NOTREACHED();
92 }
93
94 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info) {
95 RunCallback(base::PLATFORM_FILE_OK, file_info);
96 }
97
98 virtual void DidReadDirectory(
99 const std::vector<base::file_util_proxy::Entry>&, bool) {
100 NOTREACHED();
101 }
102
103 virtual void DidOpenFileSystem(const string16&, const FilePath&) {
104 NOTREACHED();
105 }
106
107 virtual void DidFail(base::PlatformFileError error_code) {
108 RunCallback(error_code, base::PlatformFileInfo());
109 }
110
111 private:
112 void RunCallback(base::PlatformFileError error_code,
113 const base::PlatformFileInfo& file_info) {
114 PP_CompletionCallback callback = {0};
115 std::swap(callback, callback_);
brettw 2010/09/23 19:35:56 Same swap comment as above.
dumi 2010/09/23 22:31:40 done.
116
117 if (!module_.get() || !callback.func)
118 return;
119
120 if (error_code == base::PLATFORM_FILE_OK) {
121 info_->size = file_info.size;
122 info_->creation_time = file_info.creation_time.ToDoubleT();
123 info_->last_access_time = file_info.last_accessed.ToDoubleT();
124 info_->last_modified_time = file_info.last_modified.ToDoubleT();
125 info_->system_type = file_system_type_;
126 if (file_info.is_directory)
127 info_->type = PP_FILETYPE_DIRECTORY;
128 else
129 info_->type = PP_FILETYPE_REGULAR;
130 }
131 PP_RunCompletionCallback(
132 &callback, pepper::PlatformFileErrorToPepperError(error_code));
133
134 delete this;
135 }
136
137 base::WeakPtr<pepper::PluginModule> module_;
138 PP_CompletionCallback callback_;
139 PP_FileInfo_Dev* info_;
140 PP_FileSystemType_Dev file_system_type_;
141 };
142
143 int32_t MakeDirectory(PP_Resource directory_ref_id,
16 bool make_ancestors, 144 bool make_ancestors,
17 PP_CompletionCallback callback) { 145 PP_CompletionCallback callback) {
18 return PP_ERROR_FAILED; // TODO(darin): Implement me! 146 scoped_refptr<FileRef> directory_ref(
19 } 147 Resource::GetAs<FileRef>(directory_ref_id));
20 148 if (!directory_ref)
21 int32_t Query(PP_Resource file_ref, 149 return PP_ERROR_BADRESOURCE;
150
151 if (directory_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
152 return PP_ERROR_FAILED;
153
154 PluginModule* module = directory_ref->module();
155 if (!module->GetSomeInstance()->delegate()->MakeDirectory(
156 directory_ref->system_path(), make_ancestors,
157 new StatusCallback(module->AsWeakPtr(), callback)))
158 return PP_ERROR_FAILED;
159
160 return PP_ERROR_WOULDBLOCK;
161 }
162
163 int32_t Query(PP_Resource file_ref_id,
22 PP_FileInfo_Dev* info, 164 PP_FileInfo_Dev* info,
23 PP_CompletionCallback callback) { 165 PP_CompletionCallback callback) {
24 return PP_ERROR_FAILED; // TODO(darin): Implement me! 166 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
25 } 167 if (!file_ref)
26 168 return PP_ERROR_BADRESOURCE;
27 int32_t Touch(PP_Resource file_ref, 169
170 PluginModule* module = file_ref->module();
171 if (!module->GetSomeInstance()->delegate()->Query(
172 file_ref->system_path(),
173 new QueryInfoCallback(module->AsWeakPtr(), callback,
174 info, file_ref->file_system_type())))
175 return PP_ERROR_FAILED;
176
177 return PP_ERROR_WOULDBLOCK;
178 }
179
180 int32_t Touch(PP_Resource file_ref_id,
28 PP_Time last_access_time, 181 PP_Time last_access_time,
29 PP_Time last_modified_time, 182 PP_Time last_modified_time,
30 PP_CompletionCallback callback) { 183 PP_CompletionCallback callback) {
31 return PP_ERROR_FAILED; // TODO(darin): Implement me! 184 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
32 } 185 if (!file_ref)
33 186 return PP_ERROR_BADRESOURCE;
34 int32_t Delete(PP_Resource file_ref, 187
188 PluginModule* module = file_ref->module();
189 if (!module->GetSomeInstance()->delegate()->Touch(
190 file_ref->system_path(), base::Time::FromDoubleT(last_access_time),
191 base::Time::FromDoubleT(last_modified_time),
192 new StatusCallback(module->AsWeakPtr(), callback)))
193 return PP_ERROR_FAILED;
194
195 return PP_ERROR_WOULDBLOCK;
196 }
197
198 int32_t Delete(PP_Resource file_ref_id,
35 PP_CompletionCallback callback) { 199 PP_CompletionCallback callback) {
36 return PP_ERROR_FAILED; // TODO(darin): Implement me! 200 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
37 } 201 if (!file_ref)
38 202 return PP_ERROR_BADRESOURCE;
39 int32_t Rename(PP_Resource file_ref, 203
40 PP_Resource new_file_ref, 204 if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
205 return PP_ERROR_FAILED;
206
207 PluginModule* module = file_ref->module();
208 if (!module->GetSomeInstance()->delegate()->Delete(
209 file_ref->system_path(),
210 new StatusCallback(module->AsWeakPtr(), callback)))
211 return PP_ERROR_FAILED;
212
213 return PP_ERROR_WOULDBLOCK;
214 }
215
216 int32_t Rename(PP_Resource file_ref_id,
217 PP_Resource new_file_ref_id,
41 PP_CompletionCallback callback) { 218 PP_CompletionCallback callback) {
42 return PP_ERROR_FAILED; // TODO(darin): Implement me! 219 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
220 if (!file_ref)
221 return PP_ERROR_BADRESOURCE;
222
223 scoped_refptr<FileRef> new_file_ref(
224 Resource::GetAs<FileRef>(new_file_ref_id));
225 if (!new_file_ref)
226 return PP_ERROR_BADRESOURCE;
227
228
229 if ((file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) ||
brettw 2010/09/23 19:35:56 Remove extra blank line above here.
dumi 2010/09/23 22:31:40 removed.
230 (file_ref->file_system_type() != new_file_ref->file_system_type()))
231 return PP_ERROR_FAILED;
232
233 PluginModule* module = file_ref->module();
234 if (!module->GetSomeInstance()->delegate()->Rename(
235 file_ref->system_path(), new_file_ref->system_path(),
236 new StatusCallback(module->AsWeakPtr(), callback)))
237 return PP_ERROR_FAILED;
238
239 return PP_ERROR_WOULDBLOCK;
43 } 240 }
44 241
45 const PPB_FileSystem_Dev ppb_filesystem = { 242 const PPB_FileSystem_Dev ppb_filesystem = {
46 &MakeDirectory, 243 &MakeDirectory,
47 &Query, 244 &Query,
48 &Touch, 245 &Touch,
49 &Delete, 246 &Delete,
50 &Rename 247 &Rename
51 }; 248 };
52 249
53 } // namespace 250 } // namespace
54 251
55 const PPB_FileSystem_Dev* FileSystem::GetInterface() { 252 const PPB_FileSystem_Dev* FileSystem::GetInterface() {
56 return &ppb_filesystem; 253 return &ppb_filesystem;
57 } 254 }
58 255
59 } // namespace pepper 256 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_file_system.h ('k') | webkit/glue/plugins/pepper_plugin_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698