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 "content/renderer/pepper/pepper_device_enumeration_host_helper.h" | 5 #include "content/renderer/pepper/pepper_device_enumeration_host_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/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, | 128 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, |
129 OnStopMonitoringDeviceChange) | 129 OnStopMonitoringDeviceChange) |
130 IPC_END_MESSAGE_MAP() | 130 IPC_END_MESSAGE_MAP() |
131 | 131 |
132 *handled = false; | 132 *handled = false; |
133 return PP_ERROR_FAILED; | 133 return PP_ERROR_FAILED; |
134 } | 134 } |
135 | 135 |
136 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( | 136 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( |
137 HostMessageContext* context) { | 137 HostMessageContext* context) { |
138 if (enumerate_devices_context_) | 138 if (enumerate_devices_context_.is_valid()) |
139 return PP_ERROR_INPROGRESS; | 139 return PP_ERROR_INPROGRESS; |
140 | 140 |
141 enumerate_.reset(new ScopedRequest( | 141 enumerate_.reset(new ScopedRequest( |
142 this, | 142 this, |
143 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, | 143 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, |
144 base::Unretained(this)))); | 144 base::Unretained(this)))); |
145 if (!enumerate_->requested()) | 145 if (!enumerate_->requested()) |
146 return PP_ERROR_FAILED; | 146 return PP_ERROR_FAILED; |
147 | 147 |
148 enumerate_devices_context_.reset( | 148 enumerate_devices_context_ = context->MakeReplyMessageContext(); |
149 new ppapi::host::ReplyMessageContext(context->MakeReplyMessageContext())); | |
150 return PP_OK_COMPLETIONPENDING; | 149 return PP_OK_COMPLETIONPENDING; |
151 } | 150 } |
152 | 151 |
153 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( | 152 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( |
154 HostMessageContext* /* context */, | 153 HostMessageContext* /* context */, |
155 uint32_t callback_id) { | 154 uint32_t callback_id) { |
156 monitor_.reset(new ScopedRequest( | 155 monitor_.reset(new ScopedRequest( |
157 this, | 156 this, |
158 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, | 157 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, |
159 base::Unretained(this), callback_id))); | 158 base::Unretained(this), callback_id))); |
160 | 159 |
161 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; | 160 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; |
162 } | 161 } |
163 | 162 |
164 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( | 163 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( |
165 HostMessageContext* /* context */) { | 164 HostMessageContext* /* context */) { |
166 monitor_.reset(NULL); | 165 monitor_.reset(NULL); |
167 return PP_OK; | 166 return PP_OK; |
168 } | 167 } |
169 | 168 |
170 void PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete( | 169 void PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete( |
171 int /* request_id */, | 170 int /* request_id */, |
172 const std::vector<ppapi::DeviceRefData>& devices) { | 171 const std::vector<ppapi::DeviceRefData>& devices) { |
173 DCHECK(enumerate_devices_context_.get()); | 172 DCHECK(enumerate_devices_context_.is_valid()); |
174 | 173 |
175 enumerate_.reset(NULL); | 174 enumerate_.reset(NULL); |
176 | 175 |
177 enumerate_devices_context_->params.set_result(PP_OK); | 176 enumerate_devices_context_.params.set_result(PP_OK); |
178 resource_host_->host()->SendReply( | 177 resource_host_->host()->SendReply( |
179 *enumerate_devices_context_, | 178 enumerate_devices_context_, |
180 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); | 179 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); |
181 enumerate_devices_context_.reset(); | 180 enumerate_devices_context_ = ppapi::host::ReplyMessageContext(); |
dmichael (off chromium)
2014/04/11 20:56:14
optional: you could alternatively have a "clear()"
bbudge
2014/04/11 22:46:05
Going through RMC usage and copying sounds like a
| |
182 } | 181 } |
183 | 182 |
184 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( | 183 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( |
185 uint32_t callback_id, | 184 uint32_t callback_id, |
186 int /* request_id */, | 185 int /* request_id */, |
187 const std::vector<ppapi::DeviceRefData>& devices) { | 186 const std::vector<ppapi::DeviceRefData>& devices) { |
188 resource_host_->host()->SendUnsolicitedReply( | 187 resource_host_->host()->SendUnsolicitedReply( |
189 resource_host_->pp_resource(), | 188 resource_host_->pp_resource(), |
190 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 189 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
191 callback_id, | 190 callback_id, |
192 devices)); | 191 devices)); |
193 } | 192 } |
194 | 193 |
195 } // namespace content | 194 } // namespace content |
OLD | NEW |