Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: content/renderer/pepper/pepper_device_enumeration_host_helper.cc

Issue 653243003: Pepper: Access PepperMediaDeviceManager through a WeakPtr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 28 matching lines...) Expand all
39 requested_ = true; 39 requested_ = true;
40 40
41 // Note that the callback passed into 41 // Note that the callback passed into
42 // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be 42 // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be
43 // called synchronously. In that case, |request_id_| hasn't been updated 43 // called synchronously. In that case, |request_id_| hasn't been updated
44 // when the callback is called. Moreover, |callback| may destroy this 44 // when the callback is called. Moreover, |callback| may destroy this
45 // object. So we don't pass in |callback| directly. Instead, we use 45 // object. So we don't pass in |callback| directly. Instead, we use
46 // EnumerateDevicesCallbackBody() to ensure that we always call |callback| 46 // EnumerateDevicesCallbackBody() to ensure that we always call |callback|
47 // asynchronously. 47 // asynchronously.
48 sync_call_ = true; 48 sync_call_ = true;
49 DCHECK(owner_->delegate_);
49 request_id_ = owner_->delegate_->EnumerateDevices( 50 request_id_ = owner_->delegate_->EnumerateDevices(
50 owner_->device_type_, 51 owner_->device_type_,
51 owner_->document_url_, 52 owner_->document_url_,
52 base::Bind(&ScopedRequest::EnumerateDevicesCallbackBody, AsWeakPtr())); 53 base::Bind(&ScopedRequest::EnumerateDevicesCallbackBody, AsWeakPtr()));
53 sync_call_ = false; 54 sync_call_ = false;
54 } 55 }
55 56
56 ~ScopedRequest() { 57 ~ScopedRequest() {
57 if (requested_) { 58 if (requested_ && owner_->delegate_) {
58 owner_->delegate_->StopEnumerateDevices(request_id_); 59 owner_->delegate_->StopEnumerateDevices(request_id_);
59 } 60 }
60 } 61 }
61 62
62 bool requested() const { return requested_; } 63 bool requested() const { return requested_; }
63 64
64 private: 65 private:
65 void EnumerateDevicesCallbackBody( 66 void EnumerateDevicesCallbackBody(
66 int request_id, 67 int request_id,
67 const std::vector<ppapi::DeviceRefData>& devices) { 68 const std::vector<ppapi::DeviceRefData>& devices) {
(...skipping 16 matching lines...) Expand all
84 callback_; 85 callback_;
85 bool requested_; 86 bool requested_;
86 int request_id_; 87 int request_id_;
87 bool sync_call_; 88 bool sync_call_;
88 89
89 DISALLOW_COPY_AND_ASSIGN(ScopedRequest); 90 DISALLOW_COPY_AND_ASSIGN(ScopedRequest);
90 }; 91 };
91 92
92 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( 93 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper(
93 ppapi::host::ResourceHost* resource_host, 94 ppapi::host::ResourceHost* resource_host,
94 Delegate* delegate, 95 base::WeakPtr<Delegate> delegate,
95 PP_DeviceType_Dev device_type, 96 PP_DeviceType_Dev device_type,
96 const GURL& document_url) 97 const GURL& document_url)
97 : resource_host_(resource_host), 98 : resource_host_(resource_host),
98 delegate_(delegate), 99 delegate_(delegate),
99 device_type_(device_type), 100 device_type_(device_type),
100 document_url_(document_url) {} 101 document_url_(document_url) {}
101 102
102 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() {} 103 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() {}
103 104
104 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( 105 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 uint32_t callback_id, 183 uint32_t callback_id,
183 int /* request_id */, 184 int /* request_id */,
184 const std::vector<ppapi::DeviceRefData>& devices) { 185 const std::vector<ppapi::DeviceRefData>& devices) {
185 resource_host_->host()->SendUnsolicitedReply( 186 resource_host_->host()->SendUnsolicitedReply(
186 resource_host_->pp_resource(), 187 resource_host_->pp_resource(),
187 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id, 188 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id,
188 devices)); 189 devices));
189 } 190 }
190 191
191 } // namespace content 192 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698