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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, | 124 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, |
125 OnStopMonitoringDeviceChange) | 125 OnStopMonitoringDeviceChange) |
126 IPC_END_MESSAGE_MAP() | 126 IPC_END_MESSAGE_MAP() |
127 | 127 |
128 *handled = false; | 128 *handled = false; |
129 return PP_ERROR_FAILED; | 129 return PP_ERROR_FAILED; |
130 } | 130 } |
131 | 131 |
132 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( | 132 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( |
133 HostMessageContext* context) { | 133 HostMessageContext* context) { |
134 if (enumerate_devices_context_) | 134 if (enumerate_devices_context_.is_valid()) |
135 return PP_ERROR_INPROGRESS; | 135 return PP_ERROR_INPROGRESS; |
136 | 136 |
137 enumerate_.reset(new ScopedRequest( | 137 enumerate_.reset(new ScopedRequest( |
138 this, | 138 this, |
139 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, | 139 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, |
140 base::Unretained(this)))); | 140 base::Unretained(this)))); |
141 if (!enumerate_->requested()) | 141 if (!enumerate_->requested()) |
142 return PP_ERROR_FAILED; | 142 return PP_ERROR_FAILED; |
143 | 143 |
144 enumerate_devices_context_.reset( | 144 enumerate_devices_context_ = context->MakeReplyMessageContext(); |
145 new ppapi::host::ReplyMessageContext(context->MakeReplyMessageContext())); | |
146 return PP_OK_COMPLETIONPENDING; | 145 return PP_OK_COMPLETIONPENDING; |
147 } | 146 } |
148 | 147 |
149 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( | 148 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( |
150 HostMessageContext* /* context */, | 149 HostMessageContext* /* context */, |
151 uint32_t callback_id) { | 150 uint32_t callback_id) { |
152 monitor_.reset(new ScopedRequest( | 151 monitor_.reset(new ScopedRequest( |
153 this, | 152 this, |
154 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, | 153 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, |
155 base::Unretained(this), | 154 base::Unretained(this), |
156 callback_id))); | 155 callback_id))); |
157 | 156 |
158 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; | 157 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; |
159 } | 158 } |
160 | 159 |
161 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( | 160 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( |
162 HostMessageContext* /* context */) { | 161 HostMessageContext* /* context */) { |
163 monitor_.reset(NULL); | 162 monitor_.reset(NULL); |
164 return PP_OK; | 163 return PP_OK; |
165 } | 164 } |
166 | 165 |
167 void PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete( | 166 void PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete( |
168 int /* request_id */, | 167 int /* request_id */, |
169 const std::vector<ppapi::DeviceRefData>& devices) { | 168 const std::vector<ppapi::DeviceRefData>& devices) { |
170 DCHECK(enumerate_devices_context_.get()); | 169 DCHECK(enumerate_devices_context_.is_valid()); |
171 | 170 |
172 enumerate_.reset(NULL); | 171 enumerate_.reset(NULL); |
173 | 172 |
174 enumerate_devices_context_->params.set_result(PP_OK); | 173 enumerate_devices_context_.params.set_result(PP_OK); |
175 resource_host_->host()->SendReply( | 174 resource_host_->host()->SendReply( |
176 *enumerate_devices_context_, | 175 enumerate_devices_context_, |
177 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); | 176 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); |
178 enumerate_devices_context_.reset(); | 177 enumerate_devices_context_ = ppapi::host::ReplyMessageContext(); |
179 } | 178 } |
180 | 179 |
181 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( | 180 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( |
182 uint32_t callback_id, | 181 uint32_t callback_id, |
183 int /* request_id */, | 182 int /* request_id */, |
184 const std::vector<ppapi::DeviceRefData>& devices) { | 183 const std::vector<ppapi::DeviceRefData>& devices) { |
185 resource_host_->host()->SendUnsolicitedReply( | 184 resource_host_->host()->SendUnsolicitedReply( |
186 resource_host_->pp_resource(), | 185 resource_host_->pp_resource(), |
187 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id, | 186 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id, |
188 devices)); | 187 devices)); |
189 } | 188 } |
190 | 189 |
191 } // namespace content | 190 } // namespace content |
OLD | NEW |