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

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

Issue 8764003: Implement a proxy for Pepper FileIO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
(...skipping 14 matching lines...) Expand all
25 using ppapi::thunk::ResourceCreationAPI; 25 using ppapi::thunk::ResourceCreationAPI;
26 26
27 namespace ppapi { 27 namespace ppapi {
28 namespace proxy { 28 namespace proxy {
29 29
30 class FileRef : public FileRefImpl { 30 class FileRef : public FileRefImpl {
31 public: 31 public:
32 explicit FileRef(const PPB_FileRef_CreateInfo& info); 32 explicit FileRef(const PPB_FileRef_CreateInfo& info);
33 virtual ~FileRef(); 33 virtual ~FileRef();
34 34
35 // Resource overrides.
36 virtual void LastPluginRefWasDeleted() OVERRIDE;
37
35 // PPB_FileRef_API implementation (not provided by FileRefImpl). 38 // PPB_FileRef_API implementation (not provided by FileRefImpl).
36 virtual PP_Resource GetParent() OVERRIDE; 39 virtual PP_Resource GetParent() OVERRIDE;
37 virtual int32_t MakeDirectory(PP_Bool make_ancestors, 40 virtual int32_t MakeDirectory(PP_Bool make_ancestors,
38 PP_CompletionCallback callback) OVERRIDE; 41 PP_CompletionCallback callback) OVERRIDE;
39 virtual int32_t Touch(PP_Time last_access_time, 42 virtual int32_t Touch(PP_Time last_access_time,
40 PP_Time last_modified_time, 43 PP_Time last_modified_time,
41 PP_CompletionCallback callback) OVERRIDE; 44 PP_CompletionCallback callback) OVERRIDE;
42 virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE; 45 virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE;
43 virtual int32_t Rename(PP_Resource new_file_ref, 46 virtual int32_t Rename(PP_Resource new_file_ref,
44 PP_CompletionCallback callback) OVERRIDE; 47 PP_CompletionCallback callback) OVERRIDE;
(...skipping 19 matching lines...) Expand all
64 // back here. 67 // back here.
65 int next_callback_id_; 68 int next_callback_id_;
66 typedef std::map<int, PP_CompletionCallback> PendingCallbackMap; 69 typedef std::map<int, PP_CompletionCallback> PendingCallbackMap;
67 PendingCallbackMap pending_callbacks_; 70 PendingCallbackMap pending_callbacks_;
68 71
69 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); 72 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
70 }; 73 };
71 74
72 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) 75 FileRef::FileRef(const PPB_FileRef_CreateInfo& info)
73 : FileRefImpl(FileRefImpl::InitAsProxy(), info), 76 : FileRefImpl(FileRefImpl::InitAsProxy(), info),
74 next_callback_id_(0) { 77 next_callback_id_(1) {
75 } 78 }
76 79
77 FileRef::~FileRef() { 80 FileRef::~FileRef() {
81 // The callbacks map should have been cleared by LastPluginRefWasDeleted.
82 DCHECK(pending_callbacks_.empty());
83 }
84
85 void FileRef::LastPluginRefWasDeleted() {
78 // Abort all pending callbacks. Do this by posting a task to avoid reentering 86 // Abort all pending callbacks. Do this by posting a task to avoid reentering
79 // the plugin's Release() call that probably deleted this object. 87 // the plugin's Release() call that probably deleted this object.
80 for (PendingCallbackMap::iterator i = pending_callbacks_.begin(); 88 for (PendingCallbackMap::iterator i = pending_callbacks_.begin();
81 i != pending_callbacks_.end(); ++i) { 89 i != pending_callbacks_.end(); ++i) {
82 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 90 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
83 i->second.func, i->second.user_data, 91 i->second.func, i->second.user_data,
84 static_cast<int32_t>(PP_ERROR_ABORTED))); 92 static_cast<int32_t>(PP_ERROR_ABORTED)));
85 } 93 }
94 pending_callbacks_.clear();
86 } 95 }
87 96
88 PP_Resource FileRef::GetParent() { 97 PP_Resource FileRef::GetParent() {
89 PPB_FileRef_CreateInfo create_info; 98 PPB_FileRef_CreateInfo create_info;
90 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( 99 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent(
91 API_ID_PPB_FILE_REF, host_resource(), &create_info)); 100 API_ID_PPB_FILE_REF, host_resource(), &create_info));
92 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); 101 return PPB_FileRef_Proxy::DeserializeFileRef(create_info);
93 } 102 }
94 103
95 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, 104 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 int32_t result, 317 int32_t result,
309 const HostResource& host_resource, 318 const HostResource& host_resource,
310 int callback_id) { 319 int callback_id) {
311 // Execute OnMsgCallbackComplete in the plugin process. 320 // Execute OnMsgCallbackComplete in the plugin process.
312 Send(new PpapiMsg_PPBFileRef_CallbackComplete( 321 Send(new PpapiMsg_PPBFileRef_CallbackComplete(
313 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); 322 API_ID_PPB_FILE_REF, host_resource, callback_id, result));
314 } 323 }
315 324
316 } // namespace proxy 325 } // namespace proxy
317 } // namespace ppapi 326 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698