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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_ref_impl.cc

Issue 14796018: Cleanup: Deprecate FileSystemCallbackDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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/plugins/ppapi/ppb_file_ref_impl.h ('k') | webkit/plugins/webkit_plugins.gypi » ('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) 2012 The Chromium Authors. All rights reserved. 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 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/plugins/ppapi/ppb_file_ref_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
6 6
7 #include "base/platform_file.h" 7 #include "base/platform_file.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/shared_impl/file_type_conversion.h" 13 #include "ppapi/shared_impl/file_type_conversion.h"
14 #include "ppapi/shared_impl/time_conversion.h" 14 #include "ppapi/shared_impl/time_conversion.h"
15 #include "ppapi/shared_impl/var.h" 15 #include "ppapi/shared_impl/var.h"
16 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
17 #include "ppapi/thunk/ppb_file_system_api.h" 17 #include "ppapi/thunk/ppb_file_system_api.h"
18 #include "webkit/fileapi/file_system_util.h"
18 #include "webkit/plugins/ppapi/common.h" 19 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/plugins/ppapi/file_callbacks.h"
20 #include "webkit/plugins/ppapi/plugin_delegate.h" 20 #include "webkit/plugins/ppapi/plugin_delegate.h"
21 #include "webkit/plugins/ppapi/plugin_module.h" 21 #include "webkit/plugins/ppapi/plugin_module.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
23 #include "webkit/plugins/ppapi/resource_helper.h" 23 #include "webkit/plugins/ppapi/resource_helper.h"
24 24
25 using ppapi::HostResource; 25 using ppapi::HostResource;
26 using ppapi::PPB_FileRef_CreateInfo; 26 using ppapi::PPB_FileRef_CreateInfo;
27 using ppapi::PPTimeToTime; 27 using ppapi::PPTimeToTime;
28 using ppapi::StringVar; 28 using ppapi::StringVar;
29 using ppapi::TrackedCallback; 29 using ppapi::TrackedCallback;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // There should always be a leading slash at least! 84 // There should always be a leading slash at least!
85 size_t pos = path.rfind('/'); 85 size_t pos = path.rfind('/');
86 CHECK(pos != std::string::npos); 86 CHECK(pos != std::string::npos);
87 return path.substr(pos + 1); 87 return path.substr(pos + 1);
88 } 88 }
89 89
90 void IgnoreCloseCallback(base::PlatformFileError error_code) { 90 void IgnoreCloseCallback(base::PlatformFileError error_code) {
91 } 91 }
92 92
93 void PlatformFileInfoToPPFileInfo(
94 const base::PlatformFileInfo& file_info,
95 PP_FileSystemType file_system_type,
96 PP_FileInfo* info) {
97 DCHECK(info);
98
99 info->size = file_info.size;
100 info->system_type = file_system_type;
101 info->creation_time = ::ppapi::TimeToPPTime(file_info.creation_time);
102 info->last_access_time = ::ppapi::TimeToPPTime(file_info.last_accessed);
103 info->last_modified_time = ::ppapi::TimeToPPTime(file_info.last_modified);
104
105 if (file_info.is_symbolic_link) {
106 // Only external filesystem may have symbolic link files.
107 DCHECK_EQ(PP_FILESYSTEMTYPE_EXTERNAL, file_system_type);
108 info->type = PP_FILETYPE_OTHER;
109 } else if (file_info.is_directory) {
110 info->type = PP_FILETYPE_DIRECTORY;
111 } else {
112 info->type = PP_FILETYPE_REGULAR;
113 }
114 }
115
93 void GetFileInfoCallback( 116 void GetFileInfoCallback(
94 scoped_refptr<base::TaskRunner> task_runner, 117 scoped_refptr<base::TaskRunner> task_runner,
95 base::PlatformFile file, 118 base::PlatformFile file,
96 linked_ptr<PP_FileInfo> info, 119 linked_ptr<PP_FileInfo> info,
97 scoped_refptr<TrackedCallback> callback, 120 scoped_refptr<TrackedCallback> callback,
98 base::PlatformFileError error_code, 121 base::PlatformFileError error_code,
99 const base::PlatformFileInfo& file_info) { 122 const base::PlatformFileInfo& file_info) {
100 base::FileUtilProxy::Close( 123 base::FileUtilProxy::Close(
101 task_runner, file, base::Bind(&IgnoreCloseCallback)); 124 task_runner, file, base::Bind(&IgnoreCloseCallback));
102 125
103 if (!TrackedCallback::IsPending(callback)) 126 if (!TrackedCallback::IsPending(callback))
104 return; 127 return;
105 128
106 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 129 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
107 if (pp_error != PP_OK) 130 if (pp_error != PP_OK) {
108 callback->Run(pp_error); 131 callback->Run(pp_error);
132 return;
133 }
109 134
110 info->size = file_info.size; 135 PlatformFileInfoToPPFileInfo(
111 if (file_info.is_symbolic_link) 136 file_info, PP_FILESYSTEMTYPE_EXTERNAL, info.get());
112 info->type = PP_FILETYPE_OTHER;
113 else if (file_info.is_directory)
114 info->type = PP_FILETYPE_DIRECTORY;
115 else
116 info->type = PP_FILETYPE_REGULAR;
117 137
118 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
119 info->creation_time = file_info.creation_time.ToDoubleT();
120 info->last_access_time = file_info.last_accessed.ToDoubleT();
121 info->last_modified_time = file_info.last_modified.ToDoubleT();
122 callback->Run(PP_OK); 138 callback->Run(PP_OK);
123 } 139 }
124 140
125 void QueryCallback(scoped_refptr<base::TaskRunner> task_runner, 141 void QueryCallback(scoped_refptr<base::TaskRunner> task_runner,
126 linked_ptr<PP_FileInfo> info, 142 linked_ptr<PP_FileInfo> info,
127 scoped_refptr<TrackedCallback> callback, 143 scoped_refptr<TrackedCallback> callback,
128 base::PlatformFileError error_code, 144 base::PlatformFileError error_code,
129 base::PassPlatformFile passed_file) { 145 base::PassPlatformFile passed_file) {
130 if (!TrackedCallback::IsPending(callback)) 146 if (!TrackedCallback::IsPending(callback))
131 return; 147 return;
132 148
133 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 149 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
134 if (pp_error != PP_OK) 150 if (pp_error != PP_OK) {
135 callback->Run(pp_error); 151 callback->Run(pp_error);
152 return;
153 }
136 base::PlatformFile file = passed_file.ReleaseValue(); 154 base::PlatformFile file = passed_file.ReleaseValue();
137 155
138 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( 156 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
139 task_runner, file, 157 task_runner, file,
140 base::Bind(&GetFileInfoCallback, task_runner, file, info, 158 base::Bind(&GetFileInfoCallback, task_runner, file, info,
141 callback))) { 159 callback))) {
142 base::FileUtilProxy::Close( 160 base::FileUtilProxy::Close(
143 task_runner, file, base::Bind(&IgnoreCloseCallback)); 161 task_runner, file, base::Bind(&IgnoreCloseCallback));
144 callback->Run(PP_ERROR_FAILED); 162 callback->Run(PP_ERROR_FAILED);
145 } 163 }
146 } 164 }
147 165
166 void DidReadMetadata(
167 scoped_refptr< ::ppapi::TrackedCallback> callback,
168 linked_ptr<PP_FileInfo> info,
169 PP_FileSystemType file_system_type,
170 const base::PlatformFileInfo& file_info,
171 const base::FilePath& unused) {
172 if (!TrackedCallback::IsPending(callback))
173 return;
174
175 PlatformFileInfoToPPFileInfo(file_info, file_system_type, info.get());
176 callback->Run(PP_OK);
177 }
178
179 void DidReadDirectory(
180 scoped_refptr< ::ppapi::TrackedCallback> callback,
181 PPB_FileRef_Impl* dir_ref,
182 linked_ptr<std::vector< ::ppapi::PPB_FileRef_CreateInfo> > dir_files,
183 linked_ptr<std::vector<PP_FileType> > dir_file_types,
184 const std::vector<base::FileUtilProxy::Entry>& entries,
185 bool has_more) {
186 if (!TrackedCallback::IsPending(callback))
187 return;
188
189 // The current filesystem backend always returns false.
190 DCHECK(!has_more);
191
192 DCHECK(dir_ref);
193 DCHECK(dir_files.get());
194 DCHECK(dir_file_types.get());
195
196 std::string dir_path = dir_ref->GetCreateInfo().path;
197 if (dir_path.empty() || dir_path[dir_path.size() - 1] != '/')
198 dir_path += '/';
199
200 for (size_t i = 0; i < entries.size(); ++i) {
201 const base::FileUtilProxy::Entry& entry = entries[i];
202 scoped_refptr<PPB_FileRef_Impl> file_ref(PPB_FileRef_Impl::CreateInternal(
203 dir_ref->pp_instance(),
204 dir_ref->file_system_resource(),
205 dir_path + fileapi::FilePathToString(base::FilePath(entry.name))));
206 dir_files->push_back(file_ref->GetCreateInfo());
207 dir_file_types->push_back(
208 entry.is_directory ? PP_FILETYPE_DIRECTORY : PP_FILETYPE_REGULAR);
209 // Add a ref count on behalf of the plugin side.
210 file_ref->GetReference();
211 }
212 CHECK_EQ(dir_files->size(), dir_file_types->size());
213
214 callback->Run(PP_OK);
215 }
216
217 void DidFinishFileOperation(
218 scoped_refptr< ::ppapi::TrackedCallback> callback,
219 base::PlatformFileError error_code) {
220 if (callback->completed())
221 return;
222 callback->Run(::ppapi::PlatformFileErrorToPepperError(error_code));
223 }
224
148 } // namespace 225 } // namespace
149 226
150 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, 227 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
151 PP_Resource file_system) 228 PP_Resource file_system)
152 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), 229 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info),
153 file_system_(file_system), 230 file_system_(file_system),
154 external_file_system_path_() { 231 external_file_system_path_() {
155 } 232 }
156 233
157 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, 234 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 PP_Bool make_ancestors, 320 PP_Bool make_ancestors,
244 scoped_refptr<TrackedCallback> callback) { 321 scoped_refptr<TrackedCallback> callback) {
245 if (!IsValidNonExternalFileSystem()) 322 if (!IsValidNonExternalFileSystem())
246 return PP_ERROR_NOACCESS; 323 return PP_ERROR_NOACCESS;
247 324
248 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 325 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
249 if (!plugin_instance) 326 if (!plugin_instance)
250 return PP_ERROR_FAILED; 327 return PP_ERROR_FAILED;
251 if (!plugin_instance->delegate()->MakeDirectory( 328 if (!plugin_instance->delegate()->MakeDirectory(
252 GetFileSystemURL(), PP_ToBool(make_ancestors), 329 GetFileSystemURL(), PP_ToBool(make_ancestors),
253 new FileCallbacks(this, callback))) 330 base::Bind(&DidFinishFileOperation, callback)))
254 return PP_ERROR_FAILED; 331 return PP_ERROR_FAILED;
255 return PP_OK_COMPLETIONPENDING; 332 return PP_OK_COMPLETIONPENDING;
256 } 333 }
257 334
258 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, 335 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time,
259 PP_Time last_modified_time, 336 PP_Time last_modified_time,
260 scoped_refptr<TrackedCallback> callback) { 337 scoped_refptr<TrackedCallback> callback) {
261 if (!IsValidNonExternalFileSystem()) 338 if (!IsValidNonExternalFileSystem())
262 return PP_ERROR_NOACCESS; 339 return PP_ERROR_NOACCESS;
263 340
264 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 341 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
265 if (!plugin_instance) 342 if (!plugin_instance)
266 return PP_ERROR_FAILED; 343 return PP_ERROR_FAILED;
267 if (!plugin_instance->delegate()->Touch( 344 if (!plugin_instance->delegate()->Touch(
268 GetFileSystemURL(), 345 GetFileSystemURL(),
269 PPTimeToTime(last_access_time), 346 PPTimeToTime(last_access_time),
270 PPTimeToTime(last_modified_time), 347 PPTimeToTime(last_modified_time),
271 new FileCallbacks(this, callback))) 348 base::Bind(&DidFinishFileOperation, callback)))
272 return PP_ERROR_FAILED; 349 return PP_ERROR_FAILED;
273 return PP_OK_COMPLETIONPENDING; 350 return PP_OK_COMPLETIONPENDING;
274 } 351 }
275 352
276 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) { 353 int32_t PPB_FileRef_Impl::Delete(scoped_refptr<TrackedCallback> callback) {
277 if (!IsValidNonExternalFileSystem()) 354 if (!IsValidNonExternalFileSystem())
278 return PP_ERROR_NOACCESS; 355 return PP_ERROR_NOACCESS;
279 356
280 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 357 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
281 if (!plugin_instance) 358 if (!plugin_instance)
282 return PP_ERROR_FAILED; 359 return PP_ERROR_FAILED;
283 if (!plugin_instance->delegate()->Delete( 360 if (!plugin_instance->delegate()->Delete(
284 GetFileSystemURL(), 361 GetFileSystemURL(),
285 new FileCallbacks(this, callback))) 362 base::Bind(&DidFinishFileOperation, callback)))
286 return PP_ERROR_FAILED; 363 return PP_ERROR_FAILED;
287 return PP_OK_COMPLETIONPENDING; 364 return PP_OK_COMPLETIONPENDING;
288 } 365 }
289 366
290 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, 367 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref,
291 scoped_refptr<TrackedCallback> callback) { 368 scoped_refptr<TrackedCallback> callback) {
292 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); 369 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true);
293 if (enter.failed()) 370 if (enter.failed())
294 return PP_ERROR_BADRESOURCE; 371 return PP_ERROR_BADRESOURCE;
295 PPB_FileRef_Impl* new_file_ref = 372 PPB_FileRef_Impl* new_file_ref =
296 static_cast<PPB_FileRef_Impl*>(enter.object()); 373 static_cast<PPB_FileRef_Impl*>(enter.object());
297 374
298 if (!IsValidNonExternalFileSystem() || 375 if (!IsValidNonExternalFileSystem() ||
299 file_system_ != new_file_ref->file_system_) 376 file_system_ != new_file_ref->file_system_)
300 return PP_ERROR_NOACCESS; 377 return PP_ERROR_NOACCESS;
301 378
302 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? 379 // TODO(viettrungluu): Also cancel when the new file ref is destroyed?
303 // http://crbug.com/67624 380 // http://crbug.com/67624
304 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 381 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
305 if (!plugin_instance) 382 if (!plugin_instance)
306 return PP_ERROR_FAILED; 383 return PP_ERROR_FAILED;
307 if (!plugin_instance->delegate()->Rename( 384 if (!plugin_instance->delegate()->Rename(
308 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), 385 GetFileSystemURL(), new_file_ref->GetFileSystemURL(),
309 new FileCallbacks(this, callback))) 386 base::Bind(&DidFinishFileOperation, callback)))
310 return PP_ERROR_FAILED; 387 return PP_ERROR_FAILED;
311 return PP_OK_COMPLETIONPENDING; 388 return PP_OK_COMPLETIONPENDING;
312 } 389 }
313 390
314 PP_Var PPB_FileRef_Impl::GetAbsolutePath() { 391 PP_Var PPB_FileRef_Impl::GetAbsolutePath() {
315 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) 392 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL)
316 return GetPath(); 393 return GetPath();
317 if (!external_path_var_) { 394 if (!external_path_var_) {
318 external_path_var_ = new StringVar( 395 external_path_var_ = new StringVar(
319 external_file_system_path_.AsUTF8Unsafe()); 396 external_file_system_path_.AsUTF8Unsafe());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // Non-external file system 478 // Non-external file system
402 if (!HasValidFileSystem()) 479 if (!HasValidFileSystem())
403 return PP_ERROR_NOACCESS; 480 return PP_ERROR_NOACCESS;
404 481
405 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 482 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
406 PluginDelegate* delegate = 483 PluginDelegate* delegate =
407 plugin_instance ? plugin_instance->delegate() : NULL; 484 plugin_instance ? plugin_instance->delegate() : NULL;
408 if (!delegate) 485 if (!delegate)
409 return PP_ERROR_FAILED; 486 return PP_ERROR_FAILED;
410 487
488 PP_FileSystemType file_system_type =
489 delegate->GetFileSystemType(pp_instance(), file_system_);
411 if (!plugin_instance->delegate()->Query( 490 if (!plugin_instance->delegate()->Query(
412 GetFileSystemURL(), 491 GetFileSystemURL(),
413 new FileCallbacks(this, callback, info, 492 base::Bind(&DidReadMetadata, callback, info, file_system_type),
414 delegate->GetFileSystemType(pp_instance(), 493 base::Bind(&DidFinishFileOperation, callback)))
415 file_system_))))
416 return PP_ERROR_FAILED; 494 return PP_ERROR_FAILED;
417 495
418 } 496 }
419 return PP_OK_COMPLETIONPENDING; 497 return PP_OK_COMPLETIONPENDING;
420 } 498 }
421 499
422 int32_t PPB_FileRef_Impl::ReadDirectoryEntries( 500 int32_t PPB_FileRef_Impl::ReadDirectoryEntries(
423 const PP_ArrayOutput& output, 501 const PP_ArrayOutput& output,
424 scoped_refptr<TrackedCallback> callback) { 502 scoped_refptr<TrackedCallback> callback) {
425 NOTREACHED(); 503 NOTREACHED();
426 return PP_ERROR_FAILED; 504 return PP_ERROR_FAILED;
427 } 505 }
428 506
429 int32_t PPB_FileRef_Impl::ReadDirectoryEntriesInHost( 507 int32_t PPB_FileRef_Impl::ReadDirectoryEntriesInHost(
430 linked_ptr<std::vector< ::ppapi::PPB_FileRef_CreateInfo> > files, 508 linked_ptr<std::vector< ::ppapi::PPB_FileRef_CreateInfo> > files,
431 linked_ptr<std::vector<PP_FileType> > file_types, 509 linked_ptr<std::vector<PP_FileType> > file_types,
432 scoped_refptr<TrackedCallback> callback) { 510 scoped_refptr<TrackedCallback> callback) {
433 if (!IsValidNonExternalFileSystem()) 511 if (!IsValidNonExternalFileSystem())
434 return PP_ERROR_NOACCESS; 512 return PP_ERROR_NOACCESS;
435 513
436 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 514 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
437 if (!plugin_instance) 515 if (!plugin_instance)
438 return PP_ERROR_FAILED; 516 return PP_ERROR_FAILED;
439 517
440 FileCallbacks::ReadDirectoryEntriesParams params; 518 // TODO(yzshen): Passing base::Unretained(this) to the callback could
441 params.dir_ref = this; 519 // be dangerous.
442 params.files = files;
443 params.file_types = file_types;
444
445 if (!plugin_instance->delegate()->ReadDirectoryEntries( 520 if (!plugin_instance->delegate()->ReadDirectoryEntries(
446 GetFileSystemURL(), 521 GetFileSystemURL(),
447 new FileCallbacks(this, callback, params))) 522 base::Bind(&DidReadDirectory,
523 callback, base::Unretained(this), files, file_types),
524 base::Bind(&DidFinishFileOperation, callback)))
448 return PP_ERROR_FAILED; 525 return PP_ERROR_FAILED;
449 return PP_OK_COMPLETIONPENDING; 526 return PP_OK_COMPLETIONPENDING;
450 } 527 }
451 528
452 } // namespace ppapi 529 } // namespace ppapi
453 } // namespace webkit 530 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_ref_impl.h ('k') | webkit/plugins/webkit_plugins.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698