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/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 class PepperDeviceEnumerationHostHelper::ScopedEnumerationRequest | 28 class PepperDeviceEnumerationHostHelper::ScopedEnumerationRequest |
29 : public base::SupportsWeakPtr<ScopedEnumerationRequest> { | 29 : public base::SupportsWeakPtr<ScopedEnumerationRequest> { |
30 public: | 30 public: |
31 // |owner| must outlive this object. | 31 // |owner| must outlive this object. |
32 ScopedEnumerationRequest(PepperDeviceEnumerationHostHelper* owner, | 32 ScopedEnumerationRequest(PepperDeviceEnumerationHostHelper* owner, |
33 const Delegate::DevicesCallback& callback) | 33 const Delegate::DevicesCallback& callback) |
34 : callback_(callback), requested_(false), sync_call_(false) { | 34 : callback_(callback), requested_(false), sync_call_(false) { |
35 if (!owner->document_url_.is_valid()) | 35 if (!owner->document_url_.is_valid()) |
36 return; | 36 return; |
37 | 37 |
38 if (!owner->delegate_) | |
yzshen1
2017/05/05 17:08:11
Sorry this has been too long ago. I don't remember
Guido Urdaneta
2017/05/05 17:18:12
It is also expected if the document_url is not val
yzshen1
2017/05/05 17:22:31
That makes sense. :)
| |
39 return; | |
40 | |
38 requested_ = true; | 41 requested_ = true; |
39 | 42 |
40 // Note that the callback passed into | 43 // Note that the callback passed into |
41 // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be | 44 // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be |
42 // called synchronously. In that case, |callback| may destroy this | 45 // called synchronously. In that case, |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 DCHECK(owner->delegate_); | |
48 owner->delegate_->EnumerateDevices( | 50 owner->delegate_->EnumerateDevices( |
49 owner->device_type_, owner->document_url_, | 51 owner->device_type_, owner->document_url_, |
50 base::Bind(&ScopedEnumerationRequest::EnumerateDevicesCallbackBody, | 52 base::Bind(&ScopedEnumerationRequest::EnumerateDevicesCallbackBody, |
51 AsWeakPtr())); | 53 AsWeakPtr())); |
52 sync_call_ = false; | 54 sync_call_ = false; |
53 } | 55 } |
54 | 56 |
55 bool requested() const { return requested_; } | 57 bool requested() const { return requested_; } |
56 | 58 |
57 private: | 59 private: |
(...skipping 26 matching lines...) Expand all Loading... | |
84 ScopedMonitoringRequest(PepperDeviceEnumerationHostHelper* owner, | 86 ScopedMonitoringRequest(PepperDeviceEnumerationHostHelper* owner, |
85 const Delegate::DevicesCallback& callback) | 87 const Delegate::DevicesCallback& callback) |
86 : owner_(owner), | 88 : owner_(owner), |
87 callback_(callback), | 89 callback_(callback), |
88 requested_(false), | 90 requested_(false), |
89 subscription_id_(0) { | 91 subscription_id_(0) { |
90 DCHECK(owner_); | 92 DCHECK(owner_); |
91 if (!owner_->document_url_.is_valid()) | 93 if (!owner_->document_url_.is_valid()) |
92 return; | 94 return; |
93 | 95 |
96 if (!owner->delegate_) | |
97 return; | |
98 | |
94 requested_ = true; | 99 requested_ = true; |
95 | 100 |
96 DCHECK(owner_->delegate_); | |
97 // |callback| is never called synchronously by StartMonitoringDevices(), | 101 // |callback| is never called synchronously by StartMonitoringDevices(), |
98 // so it is OK to pass it directly, even if |callback| destroys |this|. | 102 // so it is OK to pass it directly, even if |callback| destroys |this|. |
99 subscription_id_ = owner_->delegate_->StartMonitoringDevices( | 103 subscription_id_ = owner_->delegate_->StartMonitoringDevices( |
100 owner_->device_type_, owner_->document_url_, callback); | 104 owner_->device_type_, owner_->document_url_, callback); |
101 } | 105 } |
102 | 106 |
103 ~ScopedMonitoringRequest() { | 107 ~ScopedMonitoringRequest() { |
104 if (requested_ && owner_->delegate_) { | 108 if (requested_ && owner_->delegate_) { |
105 owner_->delegate_->StopMonitoringDevices(owner_->device_type_, | 109 owner_->delegate_->StopMonitoringDevices(owner_->device_type_, |
106 subscription_id_); | 110 subscription_id_); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( | 211 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( |
208 uint32_t callback_id, | 212 uint32_t callback_id, |
209 const std::vector<ppapi::DeviceRefData>& devices) { | 213 const std::vector<ppapi::DeviceRefData>& devices) { |
210 resource_host_->host()->SendUnsolicitedReply( | 214 resource_host_->host()->SendUnsolicitedReply( |
211 resource_host_->pp_resource(), | 215 resource_host_->pp_resource(), |
212 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id, | 216 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id, |
213 devices)); | 217 devices)); |
214 } | 218 } |
215 | 219 |
216 } // namespace content | 220 } // namespace content |
OLD | NEW |