| 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 16 matching lines...) Expand all Loading... |
| 27 public: | 27 public: |
| 28 // |owner| must outlive this object. | 28 // |owner| must outlive this object. |
| 29 ScopedRequest( | 29 ScopedRequest( |
| 30 PepperDeviceEnumerationHostHelper* owner, | 30 PepperDeviceEnumerationHostHelper* owner, |
| 31 const Delegate::EnumerateDevicesCallback& callback) | 31 const Delegate::EnumerateDevicesCallback& callback) |
| 32 : owner_(owner), | 32 : owner_(owner), |
| 33 callback_(callback), | 33 callback_(callback), |
| 34 requested_(false), | 34 requested_(false), |
| 35 request_id_(0), | 35 request_id_(0), |
| 36 sync_call_(false) { | 36 sync_call_(false) { |
| 37 if (!owner_->document_url_.is_valid()) |
| 38 return; |
| 39 |
| 37 requested_ = true; | 40 requested_ = true; |
| 38 | 41 |
| 39 // Note that the callback passed into | 42 // Note that the callback passed into |
| 40 // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be | 43 // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be |
| 41 // called synchronously. In that case, |request_id_| hasn't been updated | 44 // called synchronously. In that case, |request_id_| hasn't been updated |
| 42 // when the callback is called. Moreover, |callback| may destroy this | 45 // when the callback is called. Moreover, |callback| may destroy this |
| 43 // object. So we don't pass in |callback| directly. Instead, we use | 46 // object. So we don't pass in |callback| directly. Instead, we use |
| 44 // EnumerateDevicesCallbackBody() to ensure that we always call |callback| | 47 // EnumerateDevicesCallbackBody() to ensure that we always call |callback| |
| 45 // asynchronously. | 48 // asynchronously. |
| 46 sync_call_ = true; | 49 sync_call_ = true; |
| 47 request_id_ = owner_->delegate_->EnumerateDevices( | 50 request_id_ = owner_->delegate_->EnumerateDevices( |
| 48 owner_->device_type_, | 51 owner_->device_type_, |
| 52 owner_->document_url_, |
| 49 base::Bind(&ScopedRequest::EnumerateDevicesCallbackBody, AsWeakPtr())); | 53 base::Bind(&ScopedRequest::EnumerateDevicesCallbackBody, AsWeakPtr())); |
| 50 sync_call_ = false; | 54 sync_call_ = false; |
| 51 } | 55 } |
| 52 | 56 |
| 53 ~ScopedRequest() { | 57 ~ScopedRequest() { |
| 54 if (requested_) { | 58 if (requested_) { |
| 55 owner_->delegate_->StopEnumerateDevices(request_id_); | 59 owner_->delegate_->StopEnumerateDevices(request_id_); |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 | 62 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 84 bool requested_; | 88 bool requested_; |
| 85 int request_id_; | 89 int request_id_; |
| 86 bool sync_call_; | 90 bool sync_call_; |
| 87 | 91 |
| 88 DISALLOW_COPY_AND_ASSIGN(ScopedRequest); | 92 DISALLOW_COPY_AND_ASSIGN(ScopedRequest); |
| 89 }; | 93 }; |
| 90 | 94 |
| 91 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( | 95 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( |
| 92 ppapi::host::ResourceHost* resource_host, | 96 ppapi::host::ResourceHost* resource_host, |
| 93 Delegate* delegate, | 97 Delegate* delegate, |
| 94 PP_DeviceType_Dev device_type) | 98 PP_DeviceType_Dev device_type, |
| 99 const GURL& document_url) |
| 95 : resource_host_(resource_host), | 100 : resource_host_(resource_host), |
| 96 delegate_(delegate), | 101 delegate_(delegate), |
| 97 device_type_(device_type) { | 102 device_type_(device_type), |
| 103 document_url_(document_url) { |
| 98 } | 104 } |
| 99 | 105 |
| 100 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() { | 106 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() { |
| 101 } | 107 } |
| 102 | 108 |
| 103 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( | 109 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( |
| 104 const IPC::Message& msg, | 110 const IPC::Message& msg, |
| 105 HostMessageContext* context, | 111 HostMessageContext* context, |
| 106 int32_t* result) { | 112 int32_t* result) { |
| 107 bool return_value = false; | 113 bool return_value = false; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 bool succeeded, | 192 bool succeeded, |
| 187 const std::vector<ppapi::DeviceRefData>& devices) { | 193 const std::vector<ppapi::DeviceRefData>& devices) { |
| 188 resource_host_->host()->SendUnsolicitedReply( | 194 resource_host_->host()->SendUnsolicitedReply( |
| 189 resource_host_->pp_resource(), | 195 resource_host_->pp_resource(), |
| 190 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 196 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( |
| 191 callback_id, | 197 callback_id, |
| 192 succeeded ? devices : std::vector<ppapi::DeviceRefData>())); | 198 succeeded ? devices : std::vector<ppapi::DeviceRefData>())); |
| 193 } | 199 } |
| 194 | 200 |
| 195 } // namespace content | 201 } // namespace content |
| OLD | NEW |