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

Side by Side Diff: content/renderer/pepper/pepper_file_io_host.cc

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor fixes for dmichael Created 7 years, 3 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
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 "content/renderer/pepper/pepper_file_io_host.h" 5 #include "content/renderer/pepper/pepper_file_io_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_util_proxy.h" 11 #include "base/files/file_util_proxy.h"
12 #include "content/child/child_thread.h" 12 #include "content/child/child_thread.h"
13 #include "content/child/fileapi/file_system_dispatcher.h" 13 #include "content/child/fileapi/file_system_dispatcher.h"
14 #include "content/child/quota_dispatcher.h" 14 #include "content/child/quota_dispatcher.h"
15 #include "content/common/fileapi/file_system_messages.h" 15 #include "content/common/fileapi/file_system_messages.h"
16 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
17 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
18 #include "content/public/renderer/content_renderer_client.h" 18 #include "content/public/renderer/content_renderer_client.h"
19 #include "content/renderer/pepper/host_globals.h" 19 #include "content/renderer/pepper/host_globals.h"
20 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h"
20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 21 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
21 #include "content/renderer/pepper/ppb_file_ref_impl.h" 22 #include "content/renderer/pepper/plugin_module.h"
22 #include "content/renderer/pepper/quota_file_io.h" 23 #include "content/renderer/pepper/quota_file_io.h"
24 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
23 #include "content/renderer/render_thread_impl.h" 25 #include "content/renderer/render_thread_impl.h"
24 #include "ppapi/c/pp_errors.h" 26 #include "ppapi/c/pp_errors.h"
25 #include "ppapi/c/ppb_file_io.h" 27 #include "ppapi/c/ppb_file_io.h"
26 #include "ppapi/host/dispatch_host_message.h" 28 #include "ppapi/host/dispatch_host_message.h"
27 #include "ppapi/host/ppapi_host.h" 29 #include "ppapi/host/ppapi_host.h"
28 #include "ppapi/proxy/ppapi_messages.h" 30 #include "ppapi/proxy/ppapi_messages.h"
29 #include "ppapi/shared_impl/file_type_conversion.h" 31 #include "ppapi/shared_impl/file_type_conversion.h"
30 #include "ppapi/shared_impl/time_conversion.h" 32 #include "ppapi/shared_impl/time_conversion.h"
31 #include "ppapi/thunk/enter.h" 33 #include "ppapi/thunk/enter.h"
32 #include "third_party/WebKit/public/web/WebPluginContainer.h" 34 #include "third_party/WebKit/public/web/WebPluginContainer.h"
33 35
34 namespace content { 36 namespace content {
35 37
36 using ppapi::FileIOStateManager; 38 using ppapi::FileIOStateManager;
37 using ppapi::PPTimeToTime; 39 using ppapi::PPTimeToTime;
38 using ppapi::host::ReplyMessageContext; 40 using ppapi::host::ReplyMessageContext;
39 using ppapi::thunk::EnterResourceNoLock; 41 using ppapi::thunk::EnterResourceNoLock;
40 using ppapi::thunk::PPB_FileRef_API;
41 42
42 namespace { 43 namespace {
43 44
44 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; 45 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback;
45 46
46 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) { 47 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) {
47 // On the plugin side, some callbacks expect a parameter that means different 48 // On the plugin side, some callbacks expect a parameter that means different
48 // things depending on whether is negative or not. We translate for those 49 // things depending on whether is negative or not. We translate for those
49 // callbacks here. 50 // callbacks here.
50 return pp_error == PP_OK ? byte_number : pp_error; 51 return pp_error == PP_OK ? byte_number : pp_error;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 PepperFileIOHost::NotifyCloseFileCallback()); 131 PepperFileIOHost::NotifyCloseFileCallback());
131 } 132 }
132 133
133 } // namespace 134 } // namespace
134 135
135 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, 136 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host,
136 PP_Instance instance, 137 PP_Instance instance,
137 PP_Resource resource) 138 PP_Resource resource)
138 : ResourceHost(host->GetPpapiHost(), instance, resource), 139 : ResourceHost(host->GetPpapiHost(), instance, resource),
139 renderer_ppapi_host_(host), 140 renderer_ppapi_host_(host),
141 plugin_instance_(HostGlobals::Get()->GetInstance(instance)),
140 file_(base::kInvalidPlatformFileValue), 142 file_(base::kInvalidPlatformFileValue),
141 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 143 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
142 quota_policy_(quota::kQuotaLimitTypeUnknown), 144 quota_policy_(quota::kQuotaLimitTypeUnknown),
143 is_running_in_process_(host->IsRunningInProcess()), 145 is_running_in_process_(host->IsRunningInProcess()),
144 open_flags_(0), 146 open_flags_(0),
145 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()), 147 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()),
146 weak_factory_(this) { 148 weak_factory_(this) {
147 ChildThread::current()->AddRoute(routing_id_, this); 149 ChildThread::current()->AddRoute(routing_id_, this);
148 } 150 }
149 151
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 224
223 // TODO(tommycli): Eventually just pass the Pepper flags straight to the 225 // TODO(tommycli): Eventually just pass the Pepper flags straight to the
224 // FileSystemDispatcher so it can handle doing the security check. 226 // FileSystemDispatcher so it can handle doing the security check.
225 int platform_file_flags = 0; 227 int platform_file_flags = 0;
226 open_flags_ = open_flags; 228 open_flags_ = open_flags;
227 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, 229 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags,
228 &platform_file_flags)) { 230 &platform_file_flags)) {
229 return PP_ERROR_BADARGUMENT; 231 return PP_ERROR_BADARGUMENT;
230 } 232 }
231 233
232 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); 234 ppapi::host::ResourceHost* resource_host =
233 if (enter.failed()) 235 renderer_ppapi_host_->GetPpapiHost()->GetResourceHost(file_ref_resource);
236 if (!resource_host->IsFileRefHost())
yzshen1 2013/09/04 18:31:49 Please also check NULL.
teravest 2013/09/04 19:28:46 Done.
234 return PP_ERROR_BADRESOURCE; 237 return PP_ERROR_BADRESOURCE;
238 PepperFileRefRendererHost* file_ref_host =
239 static_cast<PepperFileRefRendererHost*>(resource_host);
235 240
236 PPB_FileRef_API* file_ref_api = enter.object(); 241 file_system_type_ = file_ref_host->GetFileSystemType();
237 PP_FileSystemType type = file_ref_api->GetFileSystemType(); 242 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) {
238 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 243 file_system_url_ = file_ref_host->GetFileSystemURL();
239 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY &&
240 type != PP_FILESYSTEMTYPE_EXTERNAL &&
241 type != PP_FILESYSTEMTYPE_ISOLATED)
242 return PP_ERROR_FAILED;
243 file_system_type_ = type;
244
245 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api);
246 if (file_ref->HasValidFileSystem()) {
247 file_system_url_ = file_ref->GetFileSystemURL();
248
249 FileSystemDispatcher* file_system_dispatcher = 244 FileSystemDispatcher* file_system_dispatcher =
250 ChildThread::current()->file_system_dispatcher(); 245 ChildThread::current()->file_system_dispatcher();
246
251 AsyncOpenFileSystemURLCallback callback = base::Bind( 247 AsyncOpenFileSystemURLCallback callback = base::Bind(
252 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, 248 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback,
253 weak_factory_.GetWeakPtr(), 249 weak_factory_.GetWeakPtr(),
254 context->MakeReplyMessageContext()); 250 context->MakeReplyMessageContext());
255 file_system_dispatcher->OpenFile( 251 file_system_dispatcher->OpenFile(
256 file_system_url_, platform_file_flags, 252 file_system_url_, platform_file_flags,
257 base::Bind(&DidOpenFileSystemURL, callback), 253 base::Bind(&DidOpenFileSystemURL, callback),
258 base::Bind(&DidFailOpenFileSystemURL, callback)); 254 base::Bind(&DidFailOpenFileSystemURL, callback));
259 } else { 255 } else {
260 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL)
261 return PP_ERROR_FAILED;
262 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( 256 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback(
263 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, 257 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback,
264 weak_factory_.GetWeakPtr(), 258 weak_factory_.GetWeakPtr(),
265 context->MakeReplyMessageContext()))); 259 context->MakeReplyMessageContext())));
266 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( 260 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile(
267 routing_id_, file_ref->GetSystemPath(), open_flags, message_id)); 261 routing_id_,
262 file_ref_host->GetExternalFilePath(),
263 open_flags_,
264 message_id));
268 } 265 }
269
270 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 266 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
271 return PP_OK_COMPLETIONPENDING; 267 return PP_OK_COMPLETIONPENDING;
272 } 268 }
273 269
274 int32_t PepperFileIOHost::OnHostMsgTouch( 270 int32_t PepperFileIOHost::OnHostMsgTouch(
275 ppapi::host::HostMessageContext* context, 271 ppapi::host::HostMessageContext* context,
276 PP_Time last_access_time, 272 PP_Time last_access_time,
277 PP_Time last_modified_time) { 273 PP_Time last_modified_time) {
278 int32_t rv = state_manager_.CheckOperationState( 274 int32_t rv = state_manager_.CheckOperationState(
279 FileIOStateManager::OPERATION_EXCLUSIVE, true); 275 FileIOStateManager::OPERATION_EXCLUSIVE, true);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // On the plugin side, the callback expects a parameter with different meaning 560 // On the plugin side, the callback expects a parameter with different meaning
565 // depends on whether is negative or not. It is the result here. We translate 561 // depends on whether is negative or not. It is the result here. We translate
566 // for the callback. 562 // for the callback.
567 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); 563 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code);
568 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); 564 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
569 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 565 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
570 state_manager_.SetOperationFinished(); 566 state_manager_.SetOperationFinished();
571 } 567 }
572 568
573 } // namespace content 569 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698