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

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

Issue 12817009: Add Query() support to FileRef (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits, more callback ref shuffling. Created 7 years, 8 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_ref_impl.h ('k') | no next file » | 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/string_util.h" 8 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
10 #include "net/base/escape.h" 11 #include "net/base/escape.h"
11 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/shared_impl/file_type_conversion.h"
14 #include "ppapi/shared_impl/time_conversion.h"
15 #include "ppapi/shared_impl/var.h"
12 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
13 #include "ppapi/thunk/ppb_file_system_api.h" 17 #include "ppapi/thunk/ppb_file_system_api.h"
14 #include "ppapi/shared_impl/time_conversion.h"
15 #include "ppapi/shared_impl/var.h"
16 #include "webkit/plugins/ppapi/common.h" 18 #include "webkit/plugins/ppapi/common.h"
17 #include "webkit/plugins/ppapi/file_callbacks.h" 19 #include "webkit/plugins/ppapi/file_callbacks.h"
18 #include "webkit/plugins/ppapi/plugin_delegate.h" 20 #include "webkit/plugins/ppapi/plugin_delegate.h"
19 #include "webkit/plugins/ppapi/plugin_module.h" 21 #include "webkit/plugins/ppapi/plugin_module.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" 23 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
22 #include "webkit/plugins/ppapi/resource_helper.h" 24 #include "webkit/plugins/ppapi/resource_helper.h"
23 25
24 using ppapi::HostResource; 26 using ppapi::HostResource;
25 using ppapi::PPB_FileRef_CreateInfo; 27 using ppapi::PPB_FileRef_CreateInfo;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 std::string GetNameForVirtualFilePath(const std::string& path) { 81 std::string GetNameForVirtualFilePath(const std::string& path) {
80 if (path.size() == 1 && path[0] == '/') 82 if (path.size() == 1 && path[0] == '/')
81 return path; 83 return path;
82 84
83 // There should always be a leading slash at least! 85 // There should always be a leading slash at least!
84 size_t pos = path.rfind('/'); 86 size_t pos = path.rfind('/');
85 CHECK(pos != std::string::npos); 87 CHECK(pos != std::string::npos);
86 return path.substr(pos + 1); 88 return path.substr(pos + 1);
87 } 89 }
88 90
91 void IgnoreCloseCallback(base::PlatformFileError error_code) {
92 }
93
94 void GetFileInfoCallback(
95 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
dmichael (off chromium) 2013/03/27 22:40:21 My bad, I think TaskRunner is the new hotness inst
96 base::PlatformFile file,
97 PP_FileInfo* info,
98 scoped_refptr<TrackedCallback> callback,
99 base::PlatformFileError error_code,
100 const base::PlatformFileInfo& file_info) {
101 base::FileUtilProxy::Close(
102 message_loop_proxy, file, base::Bind(&IgnoreCloseCallback));
103
104 if (!TrackedCallback::IsPending(callback))
105 return;
106
107 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
108 if (pp_error != PP_OK)
109 callback->Run(pp_error);
110
111 info->size = file_info.size;
112 if (file_info.is_symbolic_link)
113 info->type = PP_FILETYPE_OTHER;
114 else if (file_info.is_directory)
115 info->type = PP_FILETYPE_DIRECTORY;
116 else
117 info->type = PP_FILETYPE_REGULAR;
118
119 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
120 info->creation_time = file_info.creation_time.ToDoubleT();
121 info->last_access_time = file_info.last_accessed.ToDoubleT();
122 info->last_modified_time = file_info.last_modified.ToDoubleT();
123 callback->Run(PP_OK);
124 }
125
126 void QueryCallback(scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
127 PP_FileInfo* info,
128 scoped_refptr<TrackedCallback> callback,
129 base::PlatformFileError error_code,
130 base::PassPlatformFile passed_file) {
131 if (!TrackedCallback::IsPending(callback))
132 return;
133
134 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
135 if (pp_error != PP_OK)
136 callback->Run(pp_error);
137 base::PlatformFile file = passed_file.ReleaseValue();
138
139 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
140 message_loop_proxy, file,
141 base::Bind(&GetFileInfoCallback, message_loop_proxy, file, info,
142 callback))) {
143 base::FileUtilProxy::Close(
144 message_loop_proxy, file, base::Bind(&IgnoreCloseCallback));
145 callback->Run(PP_ERROR_FAILED);
146 }
147 }
148
89 } // namespace 149 } // namespace
90 150
91 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, 151 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
92 PPB_FileSystem_Impl* file_system) 152 PPB_FileSystem_Impl* file_system)
93 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), 153 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info),
94 file_system_(file_system), 154 file_system_(file_system),
95 external_file_system_path_() { 155 external_file_system_path_() {
96 } 156 }
97 157
98 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, 158 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 346
287 bool PPB_FileRef_Impl::HasValidFileSystem() const { 347 bool PPB_FileRef_Impl::HasValidFileSystem() const {
288 return file_system_ && file_system_->opened(); 348 return file_system_ && file_system_->opened();
289 } 349 }
290 350
291 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { 351 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const {
292 return file_system_ && file_system_->opened() && 352 return file_system_ && file_system_->opened() &&
293 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; 353 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL;
294 } 354 }
295 355
356 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info,
357 scoped_refptr<TrackedCallback> callback) {
358 scoped_refptr<PluginInstance> plugin_instance =
359 ResourceHelper::GetPluginInstance(this);
360 if (!plugin_instance.get())
361 return PP_ERROR_FAILED;
362
363 if (!file_system_) {
364 // External file system
365 // We have to do something totally different for external file systems.
366
367 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
368 plugin_instance->delegate()->GetFileThreadMessageLoopProxy();
dmichael (off chromium) 2013/03/27 22:40:21 nit: Could you add a TODO that we should be using
369 if (!plugin_instance->delegate()->AsyncOpenFile(
370 GetSystemPath(),
371 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
372 base::Bind(&QueryCallback, message_loop_proxy, info, callback)))
373 return PP_ERROR_FAILED;
374 } else {
375 // Non-external file system
376 if (!HasValidFileSystem())
377 return PP_ERROR_NOACCESS;
378
379 if (!plugin_instance->delegate()->Query(
380 GetFileSystemURL(),
381 new FileCallbacks(this, callback, info, file_system_)))
382 return PP_ERROR_FAILED;
383
384 }
385 return PP_OK_COMPLETIONPENDING;
386 }
387
296 } // namespace ppapi 388 } // namespace ppapi
297 } // namespace webkit 389 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_ref_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698