| OLD | NEW |
| 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/device_enumeration_resource_helper.h" | 5 #include "ppapi/proxy/device_enumeration_resource_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ipc/ipc_message.h" | 10 #include "ipc/ipc_message.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 PluginResource* owner) | 29 PluginResource* owner) |
| 30 : owner_(owner), | 30 : owner_(owner), |
| 31 pending_enumerate_devices_(false), | 31 pending_enumerate_devices_(false), |
| 32 monitor_callback_id_(0), | 32 monitor_callback_id_(0), |
| 33 monitor_user_data_(NULL) { | 33 monitor_user_data_(NULL) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 DeviceEnumerationResourceHelper::~DeviceEnumerationResourceHelper() { | 36 DeviceEnumerationResourceHelper::~DeviceEnumerationResourceHelper() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 int32_t DeviceEnumerationResourceHelper::EnumerateDevices0_2( | |
| 40 PP_Resource* devices, | |
| 41 scoped_refptr<TrackedCallback> callback) { | |
| 42 if (pending_enumerate_devices_) | |
| 43 return PP_ERROR_INPROGRESS; | |
| 44 if (!devices) | |
| 45 return PP_ERROR_BADARGUMENT; | |
| 46 | |
| 47 pending_enumerate_devices_ = true; | |
| 48 PpapiHostMsg_DeviceEnumeration_EnumerateDevices msg; | |
| 49 owner_->Call<PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply>( | |
| 50 PluginResource::RENDERER, msg, | |
| 51 base::Bind( | |
| 52 &DeviceEnumerationResourceHelper::OnPluginMsgEnumerateDevicesReply0_2, | |
| 53 AsWeakPtr(), devices, callback)); | |
| 54 return PP_OK_COMPLETIONPENDING; | |
| 55 } | |
| 56 | |
| 57 int32_t DeviceEnumerationResourceHelper::EnumerateDevices( | 39 int32_t DeviceEnumerationResourceHelper::EnumerateDevices( |
| 58 const PP_ArrayOutput& output, | 40 const PP_ArrayOutput& output, |
| 59 scoped_refptr<TrackedCallback> callback) { | 41 scoped_refptr<TrackedCallback> callback) { |
| 60 if (pending_enumerate_devices_) | 42 if (pending_enumerate_devices_) |
| 61 return PP_ERROR_INPROGRESS; | 43 return PP_ERROR_INPROGRESS; |
| 62 | 44 |
| 63 pending_enumerate_devices_ = true; | 45 pending_enumerate_devices_ = true; |
| 64 PpapiHostMsg_DeviceEnumeration_EnumerateDevices msg; | 46 PpapiHostMsg_DeviceEnumeration_EnumerateDevices msg; |
| 65 owner_->Call<PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply>( | 47 owner_->Call<PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply>( |
| 66 PluginResource::RENDERER, msg, | 48 PluginResource::RENDERER, msg, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Make sure that no further notifications are sent to the plugin. | 107 // Make sure that no further notifications are sent to the plugin. |
| 126 monitor_callback_id_++; | 108 monitor_callback_id_++; |
| 127 monitor_callback_.reset(NULL); | 109 monitor_callback_.reset(NULL); |
| 128 monitor_user_data_ = NULL; | 110 monitor_user_data_ = NULL; |
| 129 | 111 |
| 130 // There is no need to do anything with pending callback of | 112 // There is no need to do anything with pending callback of |
| 131 // EnumerateDevices(), because OnPluginMsgEnumerateDevicesReply*() will handle | 113 // EnumerateDevices(), because OnPluginMsgEnumerateDevicesReply*() will handle |
| 132 // that properly. | 114 // that properly. |
| 133 } | 115 } |
| 134 | 116 |
| 135 void DeviceEnumerationResourceHelper::OnPluginMsgEnumerateDevicesReply0_2( | |
| 136 PP_Resource* devices_resource, | |
| 137 scoped_refptr<TrackedCallback> callback, | |
| 138 const ResourceMessageReplyParams& params, | |
| 139 const std::vector<DeviceRefData>& devices) { | |
| 140 pending_enumerate_devices_ = false; | |
| 141 | |
| 142 // We shouldn't access |devices_resource| if the callback has been called, | |
| 143 // which is possible if the last plugin reference to the corresponding | |
| 144 // resource has gone away, and the callback has been aborted. | |
| 145 if (!TrackedCallback::IsPending(callback)) | |
| 146 return; | |
| 147 | |
| 148 if (params.result() == PP_OK) { | |
| 149 *devices_resource = PPB_DeviceRef_Shared::CreateResourceArray( | |
| 150 OBJECT_IS_PROXY, owner_->pp_instance(), devices); | |
| 151 } | |
| 152 | |
| 153 callback->Run(params.result()); | |
| 154 } | |
| 155 | |
| 156 void DeviceEnumerationResourceHelper::OnPluginMsgEnumerateDevicesReply( | 117 void DeviceEnumerationResourceHelper::OnPluginMsgEnumerateDevicesReply( |
| 157 const PP_ArrayOutput& output, | 118 const PP_ArrayOutput& output, |
| 158 scoped_refptr<TrackedCallback> callback, | 119 scoped_refptr<TrackedCallback> callback, |
| 159 const ResourceMessageReplyParams& params, | 120 const ResourceMessageReplyParams& params, |
| 160 const std::vector<DeviceRefData>& devices) { | 121 const std::vector<DeviceRefData>& devices) { |
| 161 pending_enumerate_devices_ = false; | 122 pending_enumerate_devices_ = false; |
| 162 | 123 |
| 163 // We shouldn't access |output| if the callback has been called, which is | 124 // We shouldn't access |output| if the callback has been called, which is |
| 164 // possible if the last plugin reference to the corresponding resource has | 125 // possible if the last plugin reference to the corresponding resource has |
| 165 // gone away, and the callback has been aborted. | 126 // gone away, and the callback has been aborted. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 OBJECT_IS_PROXY, owner_->pp_instance(), devices[i])); | 175 OBJECT_IS_PROXY, owner_->pp_instance(), devices[i])); |
| 215 } | 176 } |
| 216 if (!writer.StoreResourceVector(device_resources)) | 177 if (!writer.StoreResourceVector(device_resources)) |
| 217 return PP_ERROR_FAILED; | 178 return PP_ERROR_FAILED; |
| 218 | 179 |
| 219 return PP_OK; | 180 return PP_OK; |
| 220 } | 181 } |
| 221 | 182 |
| 222 } // namespace proxy | 183 } // namespace proxy |
| 223 } // namespace ppapi | 184 } // namespace ppapi |
| OLD | NEW |