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

Side by Side Diff: ppapi/proxy/ppb_file_ref_proxy.cc

Issue 13726024: Refactor FileSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NON_EXPORTED_BASE 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 | « ppapi/proxy/ppb_file_ref_proxy.h ('k') | ppapi/proxy/ppb_file_system_proxy.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) 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 "ppapi/proxy/ppb_file_ref_proxy.h" 5 #include "ppapi/proxy/ppb_file_ref_proxy.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_file_ref.h" 11 #include "ppapi/c/ppb_file_ref.h"
12 #include "ppapi/c/private/ppb_file_ref_private.h" 12 #include "ppapi/c/private/ppb_file_ref_private.h"
13 #include "ppapi/c/private/ppb_proxy_private.h" 13 #include "ppapi/c/private/ppb_proxy_private.h"
14 #include "ppapi/proxy/enter_proxy.h" 14 #include "ppapi/proxy/enter_proxy.h"
15 #include "ppapi/proxy/host_dispatcher.h" 15 #include "ppapi/proxy/host_dispatcher.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/proxy/serialized_var.h" 18 #include "ppapi/proxy/serialized_var.h"
19 #include "ppapi/shared_impl/ppb_file_ref_shared.h" 19 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
20 #include "ppapi/shared_impl/scoped_pp_resource.h"
20 #include "ppapi/shared_impl/tracked_callback.h" 21 #include "ppapi/shared_impl/tracked_callback.h"
21 #include "ppapi/thunk/resource_creation_api.h" 22 #include "ppapi/thunk/resource_creation_api.h"
22 #include "ppapi/thunk/thunk.h" 23 #include "ppapi/thunk/thunk.h"
23 24
24 using ppapi::thunk::EnterResourceNoLock; 25 using ppapi::thunk::EnterResourceNoLock;
25 using ppapi::thunk::PPB_FileRef_API; 26 using ppapi::thunk::PPB_FileRef_API;
26 using ppapi::thunk::ResourceCreationAPI; 27 using ppapi::thunk::ResourceCreationAPI;
27 28
28 namespace ppapi { 29 namespace ppapi {
29 namespace proxy { 30 namespace proxy {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 typedef std::map<uint32_t, 75 typedef std::map<uint32_t,
75 scoped_refptr<TrackedCallback> > PendingCallbackMap; 76 scoped_refptr<TrackedCallback> > PendingCallbackMap;
76 PendingCallbackMap pending_callbacks_; 77 PendingCallbackMap pending_callbacks_;
77 78
78 // Used to keep pointers to PP_FileInfo instances that are written before 79 // Used to keep pointers to PP_FileInfo instances that are written before
79 // callbacks are invoked. The id of a pending file info will match that of 80 // callbacks are invoked. The id of a pending file info will match that of
80 // the corresponding callback. 81 // the corresponding callback.
81 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; 82 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap;
82 PendingFileInfoMap pending_file_infos_; 83 PendingFileInfoMap pending_file_infos_;
83 84
85 // Holds a reference on plugin side when running out of process, so that
86 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for
87 // corresponding code for in-process mode. Note that this workaround will
88 // be no longer needed after FileRef refactoring.
89 ScopedPPResource file_system_;
90
84 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); 91 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
85 }; 92 };
86 93
87 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) 94 FileRef::FileRef(const PPB_FileRef_CreateInfo& info)
88 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), 95 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info),
89 next_callback_id_(0u) { 96 next_callback_id_(0u),
97 file_system_(info.file_system_plugin_resource) {
90 } 98 }
91 99
92 FileRef::~FileRef() { 100 FileRef::~FileRef() {
93 // The callbacks map should have been cleared by LastPluginRefWasDeleted. 101 // The callbacks map should have been cleared by LastPluginRefWasDeleted.
94 DCHECK(pending_callbacks_.empty()); 102 DCHECK(pending_callbacks_.empty());
95 DCHECK(pending_file_infos_.empty()); 103 DCHECK(pending_file_infos_.empty());
96 } 104 }
97 105
98 void FileRef::LastPluginRefWasDeleted() { 106 void FileRef::LastPluginRefWasDeleted() {
99 // The callback tracker will abort our callbacks for us. 107 // The callback tracker will abort our callbacks for us.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 205
198 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) 206 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher)
199 : InterfaceProxy(dispatcher), 207 : InterfaceProxy(dispatcher),
200 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 208 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
201 } 209 }
202 210
203 PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { 211 PPB_FileRef_Proxy::~PPB_FileRef_Proxy() {
204 } 212 }
205 213
206 // static 214 // static
207 PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, 215 PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Instance instance,
216 PP_Resource file_system,
208 const char* path) { 217 const char* path) {
209 Resource* file_system_object =
210 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_system);
211 if (!file_system_object)
212 return 0;
213
214 PPB_FileRef_CreateInfo create_info; 218 PPB_FileRef_CreateInfo create_info;
215 PluginDispatcher::GetForResource(file_system_object)->Send( 219 PluginDispatcher::GetForInstance(instance)->Send(
216 new PpapiHostMsg_PPBFileRef_Create( 220 new PpapiHostMsg_PPBFileRef_Create(
217 API_ID_PPB_FILE_REF, file_system_object->host_resource(), 221 API_ID_PPB_FILE_REF, instance, file_system, path, &create_info));
218 path, &create_info));
219 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); 222 return PPB_FileRef_Proxy::DeserializeFileRef(create_info);
220 } 223 }
221 224
222 bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { 225 bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) {
223 bool handled = true; 226 bool handled = true;
224 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) 227 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg)
225 #if !defined(OS_NACL) 228 #if !defined(OS_NACL)
226 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) 229 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate)
227 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) 230 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent)
228 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, 231 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory,
(...skipping 25 matching lines...) Expand all
254 257
255 // static 258 // static
256 PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( 259 PP_Resource PPB_FileRef_Proxy::DeserializeFileRef(
257 const PPB_FileRef_CreateInfo& serialized) { 260 const PPB_FileRef_CreateInfo& serialized) {
258 if (serialized.resource.is_null()) 261 if (serialized.resource.is_null())
259 return 0; // Resource invalid. 262 return 0; // Resource invalid.
260 return (new FileRef(serialized))->GetReference(); 263 return (new FileRef(serialized))->GetReference();
261 } 264 }
262 265
263 #if !defined(OS_NACL) 266 #if !defined(OS_NACL)
264 void PPB_FileRef_Proxy::OnMsgCreate(const HostResource& file_system, 267 void PPB_FileRef_Proxy::OnMsgCreate(PP_Instance pp_instance,
268 PP_Resource file_system,
265 const std::string& path, 269 const std::string& path,
266 PPB_FileRef_CreateInfo* result) { 270 PPB_FileRef_CreateInfo* result) {
267 thunk::EnterResourceCreation enter(file_system.instance()); 271 thunk::EnterResourceCreation enter(pp_instance);
268 if (enter.failed()) 272 if (enter.failed())
269 return; 273 return;
274
270 PP_Resource resource = enter.functions()->CreateFileRef( 275 PP_Resource resource = enter.functions()->CreateFileRef(
271 file_system.host_resource(), path.c_str()); 276 pp_instance, file_system, path.c_str());
272 if (!resource) 277 if (!resource)
273 return; // CreateInfo default constructor initializes to 0. 278 return; // CreateInfo default constructor initializes to 0.
274 SerializeFileRef(resource, result); 279 SerializeFileRef(resource, result);
275 } 280 }
276 281
277 void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, 282 void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource,
278 PPB_FileRef_CreateInfo* result) { 283 PPB_FileRef_CreateInfo* result) {
279 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); 284 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource);
280 if (enter.succeeded()) 285 if (enter.succeeded())
281 SerializeFileRef(enter.object()->GetParent(), result); 286 SerializeFileRef(enter.object()->GetParent(), result);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 const HostResource& host_resource, 389 const HostResource& host_resource,
385 base::internal::OwnedWrapper<PP_FileInfo> info, 390 base::internal::OwnedWrapper<PP_FileInfo> info,
386 uint32_t callback_id) { 391 uint32_t callback_id) {
387 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( 392 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete(
388 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); 393 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result));
389 } 394 }
390 #endif // !defined(OS_NACL) 395 #endif // !defined(OS_NACL)
391 396
392 } // namespace proxy 397 } // namespace proxy
393 } // namespace ppapi 398 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_file_ref_proxy.h ('k') | ppapi/proxy/ppb_file_system_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698