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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 }; | 91 }; |
92 | 92 |
93 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( | 93 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( |
94 ppapi::host::ResourceHost* resource_host, | 94 ppapi::host::ResourceHost* resource_host, |
95 Delegate* delegate, | 95 Delegate* delegate, |
96 PP_DeviceType_Dev device_type, | 96 PP_DeviceType_Dev device_type, |
97 const GURL& document_url) | 97 const GURL& document_url) |
98 : resource_host_(resource_host), | 98 : resource_host_(resource_host), |
99 delegate_(delegate), | 99 delegate_(delegate), |
100 device_type_(device_type), | 100 device_type_(device_type), |
101 document_url_(document_url) { | 101 document_url_(document_url), |
| 102 enumerate_devices_pending_(false) { |
102 } | 103 } |
103 | 104 |
104 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() { | 105 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() { |
105 } | 106 } |
106 | 107 |
107 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( | 108 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( |
108 const IPC::Message& msg, | 109 const IPC::Message& msg, |
109 HostMessageContext* context, | 110 HostMessageContext* context, |
110 int32_t* result) { | 111 int32_t* result) { |
111 bool return_value = false; | 112 bool return_value = false; |
(...skipping 16 matching lines...) Expand all Loading... |
128 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, | 129 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, |
129 OnStopMonitoringDeviceChange) | 130 OnStopMonitoringDeviceChange) |
130 IPC_END_MESSAGE_MAP() | 131 IPC_END_MESSAGE_MAP() |
131 | 132 |
132 *handled = false; | 133 *handled = false; |
133 return PP_ERROR_FAILED; | 134 return PP_ERROR_FAILED; |
134 } | 135 } |
135 | 136 |
136 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( | 137 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( |
137 HostMessageContext* context) { | 138 HostMessageContext* context) { |
138 if (enumerate_devices_context_) | 139 if (enumerate_devices_pending_) |
139 return PP_ERROR_INPROGRESS; | 140 return PP_ERROR_INPROGRESS; |
140 | 141 |
141 enumerate_.reset(new ScopedRequest( | 142 enumerate_.reset(new ScopedRequest( |
142 this, | 143 this, |
143 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, | 144 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, |
144 base::Unretained(this)))); | 145 base::Unretained(this)))); |
145 if (!enumerate_->requested()) | 146 if (!enumerate_->requested()) |
146 return PP_ERROR_FAILED; | 147 return PP_ERROR_FAILED; |
147 | 148 |
148 enumerate_devices_context_.reset( | 149 enumerate_devices_pending_ = true; |
149 new ppapi::host::ReplyMessageContext(context->MakeReplyMessageContext())); | 150 enumerate_devices_context_ = context->MakeReplyMessageContext(); |
150 return PP_OK_COMPLETIONPENDING; | 151 return PP_OK_COMPLETIONPENDING; |
151 } | 152 } |
152 | 153 |
153 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( | 154 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( |
154 HostMessageContext* /* context */, | 155 HostMessageContext* /* context */, |
155 uint32_t callback_id) { | 156 uint32_t callback_id) { |
156 monitor_.reset(new ScopedRequest( | 157 monitor_.reset(new ScopedRequest( |
157 this, | 158 this, |
158 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, | 159 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, |
159 base::Unretained(this), callback_id))); | 160 base::Unretained(this), callback_id))); |
160 | 161 |
161 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; | 162 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; |
162 } | 163 } |
163 | 164 |
164 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( | 165 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( |
165 HostMessageContext* /* context */) { | 166 HostMessageContext* /* context */) { |
166 monitor_.reset(NULL); | 167 monitor_.reset(NULL); |
167 return PP_OK; | 168 return PP_OK; |
168 } | 169 } |
169 | 170 |
170 void PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete( | 171 void PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete( |
171 int /* request_id */, | 172 int /* request_id */, |
172 const std::vector<ppapi::DeviceRefData>& devices) { | 173 const std::vector<ppapi::DeviceRefData>& devices) { |
173 DCHECK(enumerate_devices_context_.get()); | 174 DCHECK(enumerate_devices_pending_); |
174 | 175 |
175 enumerate_.reset(NULL); | 176 enumerate_.reset(NULL); |
176 | 177 |
177 enumerate_devices_context_->params.set_result(PP_OK); | 178 enumerate_devices_context_.params.set_result(PP_OK); |
178 resource_host_->host()->SendReply( | 179 resource_host_->host()->SendReply( |
179 *enumerate_devices_context_, | 180 enumerate_devices_context_, |
180 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); | 181 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); |
181 enumerate_devices_context_.reset(); | 182 enumerate_devices_context_ = ppapi::host::ReplyMessageContext(); |
| 183 enumerate_devices_pending_ = false; |
182 } | 184 } |
183 | 185 |
184 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( | 186 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( |
185 uint32_t callback_id, | 187 uint32_t callback_id, |
186 int /* request_id */, | 188 int /* request_id */, |
187 const std::vector<ppapi::DeviceRefData>& devices) { | 189 const std::vector<ppapi::DeviceRefData>& devices) { |
188 resource_host_->host()->SendUnsolicitedReply( | 190 resource_host_->host()->SendUnsolicitedReply( |
189 resource_host_->pp_resource(), | 191 resource_host_->pp_resource(), |
190 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 192 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
191 callback_id, | 193 callback_id, |
192 devices)); | 194 devices)); |
193 } | 195 } |
194 | 196 |
195 } // namespace content | 197 } // namespace content |
OLD | NEW |