OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 using ppapi::thunk::ResourceCreationAPI; | 26 using ppapi::thunk::ResourceCreationAPI; |
27 | 27 |
28 namespace ppapi { | 28 namespace ppapi { |
29 namespace proxy { | 29 namespace proxy { |
30 | 30 |
31 class FileRef : public PPB_FileRef_Shared { | 31 class FileRef : public PPB_FileRef_Shared { |
32 public: | 32 public: |
33 explicit FileRef(const PPB_FileRef_CreateInfo& info); | 33 explicit FileRef(const PPB_FileRef_CreateInfo& info); |
34 virtual ~FileRef(); | 34 virtual ~FileRef(); |
35 | 35 |
| 36 // Resource overrides. |
| 37 virtual void LastPluginRefWasDeleted() OVERRIDE; |
| 38 |
36 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). | 39 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). |
37 virtual PP_Resource GetParent() OVERRIDE; | 40 virtual PP_Resource GetParent() OVERRIDE; |
38 virtual int32_t MakeDirectory(PP_Bool make_ancestors, | 41 virtual int32_t MakeDirectory(PP_Bool make_ancestors, |
39 PP_CompletionCallback callback) OVERRIDE; | 42 PP_CompletionCallback callback) OVERRIDE; |
40 virtual int32_t Touch(PP_Time last_access_time, | 43 virtual int32_t Touch(PP_Time last_access_time, |
41 PP_Time last_modified_time, | 44 PP_Time last_modified_time, |
42 PP_CompletionCallback callback) OVERRIDE; | 45 PP_CompletionCallback callback) OVERRIDE; |
43 virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE; | 46 virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE; |
44 virtual int32_t Rename(PP_Resource new_file_ref, | 47 virtual int32_t Rename(PP_Resource new_file_ref, |
45 PP_CompletionCallback callback) OVERRIDE; | 48 PP_CompletionCallback callback) OVERRIDE; |
(...skipping 24 matching lines...) Expand all Loading... |
70 | 73 |
71 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); | 74 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); |
72 }; | 75 }; |
73 | 76 |
74 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) | 77 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) |
75 : PPB_FileRef_Shared(PPB_FileRef_Shared::InitAsProxy(), info), | 78 : PPB_FileRef_Shared(PPB_FileRef_Shared::InitAsProxy(), info), |
76 next_callback_id_(1) { | 79 next_callback_id_(1) { |
77 } | 80 } |
78 | 81 |
79 FileRef::~FileRef() { | 82 FileRef::~FileRef() { |
| 83 // The callbacks map should have been cleared by LastPluginRefWasDeleted. |
| 84 DCHECK(pending_callbacks_.empty()); |
| 85 } |
| 86 |
| 87 void FileRef::LastPluginRefWasDeleted() { |
80 // Abort all pending callbacks. Do this by posting a task to avoid reentering | 88 // Abort all pending callbacks. Do this by posting a task to avoid reentering |
81 // the plugin's Release() call that probably deleted this object. | 89 // the plugin's Release() call that probably deleted this object. |
82 for (PendingCallbackMap::iterator i = pending_callbacks_.begin(); | 90 for (PendingCallbackMap::iterator i = pending_callbacks_.begin(); |
83 i != pending_callbacks_.end(); ++i) { | 91 i != pending_callbacks_.end(); ++i) { |
84 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 92 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
85 i->second.func, i->second.user_data, | 93 i->second.func, i->second.user_data, |
86 static_cast<int32_t>(PP_ERROR_ABORTED))); | 94 static_cast<int32_t>(PP_ERROR_ABORTED))); |
87 } | 95 } |
| 96 pending_callbacks_.clear(); |
88 } | 97 } |
89 | 98 |
90 PP_Resource FileRef::GetParent() { | 99 PP_Resource FileRef::GetParent() { |
91 PPB_FileRef_CreateInfo create_info; | 100 PPB_FileRef_CreateInfo create_info; |
92 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( | 101 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( |
93 API_ID_PPB_FILE_REF, host_resource(), &create_info)); | 102 API_ID_PPB_FILE_REF, host_resource(), &create_info)); |
94 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); | 103 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); |
95 } | 104 } |
96 | 105 |
97 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, | 106 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 int32_t result, | 343 int32_t result, |
335 const HostResource& host_resource, | 344 const HostResource& host_resource, |
336 int callback_id) { | 345 int callback_id) { |
337 // Execute OnMsgCallbackComplete in the plugin process. | 346 // Execute OnMsgCallbackComplete in the plugin process. |
338 Send(new PpapiMsg_PPBFileRef_CallbackComplete( | 347 Send(new PpapiMsg_PPBFileRef_CallbackComplete( |
339 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); | 348 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); |
340 } | 349 } |
341 | 350 |
342 } // namespace proxy | 351 } // namespace proxy |
343 } // namespace ppapi | 352 } // namespace ppapi |
OLD | NEW |