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

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: Remove code duplication Created 7 years, 4 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_browser_connection.h"
20 #include "content/renderer/pepper/pepper_helper_impl.h" 21 #include "content/renderer/pepper/pepper_helper_impl.h"
21 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 22 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
22 #include "content/renderer/pepper/ppb_file_ref_impl.h" 23 #include "content/renderer/pepper/plugin_module.h"
23 #include "content/renderer/pepper/quota_file_io.h" 24 #include "content/renderer/pepper/quota_file_io.h"
25 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
24 #include "content/renderer/render_thread_impl.h" 26 #include "content/renderer/render_thread_impl.h"
25 #include "ppapi/c/pp_errors.h" 27 #include "ppapi/c/pp_errors.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 // The maximum size we'll support reading in one chunk. The renderer process 45 // The maximum size we'll support reading in one chunk. The renderer process
45 // must allocate a buffer sized according to the request of the plugin. To 46 // must allocate a buffer sized according to the request of the plugin. To
46 // keep things from getting out of control, we cap the read size to this value. 47 // keep things from getting out of control, we cap the read size to this value.
47 // This should generally be OK since the API specifies that it may perform a 48 // This should generally be OK since the API specifies that it may perform a
48 // partial read. 49 // partial read.
49 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB 50 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB
50 51
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 PP_Resource resource) 145 PP_Resource resource)
145 : ResourceHost(host->GetPpapiHost(), instance, resource), 146 : ResourceHost(host->GetPpapiHost(), instance, resource),
146 file_(base::kInvalidPlatformFileValue), 147 file_(base::kInvalidPlatformFileValue),
147 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 148 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
148 quota_policy_(quota::kQuotaLimitTypeUnknown), 149 quota_policy_(quota::kQuotaLimitTypeUnknown),
149 is_running_in_process_(host->IsRunningInProcess()), 150 is_running_in_process_(host->IsRunningInProcess()),
150 open_flags_(0), 151 open_flags_(0),
151 weak_factory_(this), 152 weak_factory_(this),
152 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) { 153 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()) {
153 ChildThread::current()->AddRoute(routing_id_, this); 154 ChildThread::current()->AddRoute(routing_id_, this);
155 plugin_instance_ = HostGlobals::Get()->GetInstance(instance);
dmichael (off chromium) 2013/08/07 22:19:13 nit: Why not do this in the initializer list?
teravest 2013/08/08 00:50:06 Done.
154 } 156 }
155 157
156 PepperFileIOHost::~PepperFileIOHost() { 158 PepperFileIOHost::~PepperFileIOHost() {
157 OnHostMsgClose(NULL); 159 OnHostMsgClose(NULL);
158 ChildThread::current()->RemoveRoute(routing_id_); 160 ChildThread::current()->RemoveRoute(routing_id_);
159 } 161 }
160 162
161 int32_t PepperFileIOHost::OnResourceMessageReceived( 163 int32_t PepperFileIOHost::OnResourceMessageReceived(
162 const IPC::Message& msg, 164 const IPC::Message& msg,
163 ppapi::host::HostMessageContext* context) { 165 ppapi::host::HostMessageContext* context) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 234
233 // TODO(tommycli): Eventually just pass the Pepper flags straight to the 235 // TODO(tommycli): Eventually just pass the Pepper flags straight to the
234 // FileSystemDispatcher so it can handle doing the security check. 236 // FileSystemDispatcher so it can handle doing the security check.
235 int platform_file_flags = 0; 237 int platform_file_flags = 0;
236 open_flags_ = open_flags; 238 open_flags_ = open_flags;
237 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, 239 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags,
238 &platform_file_flags)) { 240 &platform_file_flags)) {
239 return PP_ERROR_BADARGUMENT; 241 return PP_ERROR_BADARGUMENT;
240 } 242 }
241 243
242 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); 244 RendererPpapiHostImpl* host_impl =
243 if (enter.failed()) 245 plugin_instance_->module()->renderer_ppapi_host();
244 return PP_ERROR_BADRESOURCE; 246 RenderView* render_view = host_impl->GetRenderViewForInstance(pp_instance());
247 PepperBrowserConnection* browser_connection =
248 PepperBrowserConnection::Get(render_view);
249 int child_process_id = plugin_instance_->module()->GetPluginChildId();
245 250
246 PPB_FileRef_API* file_ref_api = enter.object(); 251 std::vector<PP_Resource> resources;
247 PP_FileSystemType type = file_ref_api->GetFileSystemType(); 252 resources.push_back(file_ref_resource);
248 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && 253 browser_connection->SendBrowserFileRefGetInfo(
249 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && 254 child_process_id,
250 type != PP_FILESYSTEMTYPE_EXTERNAL && 255 resources,
251 type != PP_FILESYSTEMTYPE_ISOLATED) 256 base::Bind(&PepperFileIOHost::DidGetFileRefInfo,
252 return PP_ERROR_FAILED; 257 weak_factory_.GetWeakPtr(),
258 context->MakeReplyMessageContext(),
259 platform_file_flags));
260 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
261 return PP_OK_COMPLETIONPENDING;
262 }
263
264 void PepperFileIOHost::DidGetFileRefInfo(
265 ppapi::host::ReplyMessageContext reply_context,
266 int platform_file_flags,
267 const std::vector<ppapi::FileRef_DetailedInfo>& infos) {
268 if (infos.size() == 0)
269 return;
270 // TODO: Confirm resources match.
271
272 PP_FileSystemType type = infos[0].file_system_type;
253 file_system_type_ = type; 273 file_system_type_ = type;
254 274 if (type != PP_FILESYSTEMTYPE_EXTERNAL) {
255 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); 275 const std::string& file_system_url_spec = infos[0].file_system_url_spec;
256 if (file_ref->HasValidFileSystem()) { 276 file_system_url_ = GURL(file_system_url_spec);
257 file_system_url_ = file_ref->GetFileSystemURL();
258 277
259 FileSystemDispatcher* file_system_dispatcher = 278 FileSystemDispatcher* file_system_dispatcher =
260 ChildThread::current()->file_system_dispatcher(); 279 ChildThread::current()->file_system_dispatcher();
280
261 AsyncOpenFileSystemURLCallback callback = base::Bind( 281 AsyncOpenFileSystemURLCallback callback = base::Bind(
262 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, 282 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback,
263 weak_factory_.GetWeakPtr(), 283 weak_factory_.GetWeakPtr(),
264 context->MakeReplyMessageContext()); 284 reply_context);
265 file_system_dispatcher->OpenFile( 285 file_system_dispatcher->OpenFile(
266 file_system_url_, platform_file_flags, 286 file_system_url_, platform_file_flags,
267 base::Bind(&DidOpenFileSystemURL, callback), 287 base::Bind(&DidOpenFileSystemURL, callback),
268 base::Bind(&DidFailOpenFileSystemURL, callback)); 288 base::Bind(&DidFailOpenFileSystemURL, callback));
269 } else { 289 } else {
270 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL)
271 return PP_ERROR_FAILED;
272 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( 290 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback(
273 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, 291 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback,
274 weak_factory_.GetWeakPtr(), 292 weak_factory_.GetWeakPtr(),
275 context->MakeReplyMessageContext()))); 293 reply_context)));
276 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( 294 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile(
277 routing_id_, file_ref->GetSystemPath(), open_flags, message_id)); 295 routing_id_, infos[0].external_path, open_flags_, message_id));
278 } 296 }
279
280 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
281 return PP_OK_COMPLETIONPENDING;
282 } 297 }
283 298
284 int32_t PepperFileIOHost::OnHostMsgQuery( 299 int32_t PepperFileIOHost::OnHostMsgQuery(
285 ppapi::host::HostMessageContext* context) { 300 ppapi::host::HostMessageContext* context) {
286 int32_t rv = state_manager_.CheckOperationState( 301 int32_t rv = state_manager_.CheckOperationState(
287 FileIOStateManager::OPERATION_EXCLUSIVE, true); 302 FileIOStateManager::OPERATION_EXCLUSIVE, true);
288 if (rv != PP_OK) 303 if (rv != PP_OK)
289 return rv; 304 return rv;
290 305
291 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( 306 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // On the plugin side, the callback expects a parameter with different meaning 659 // On the plugin side, the callback expects a parameter with different meaning
645 // depends on whether is negative or not. It is the result here. We translate 660 // depends on whether is negative or not. It is the result here. We translate
646 // for the callback. 661 // for the callback.
647 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); 662 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
648 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); 663 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
649 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 664 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
650 state_manager_.SetOperationFinished(); 665 state_manager_.SetOperationFinished();
651 } 666 }
652 667
653 } // namespace content 668 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698