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

Side by Side Diff: content/renderer/media/rtc_certificate_generator.cc

Issue 1804563002: Refactor WebRTC certificate generation to use WebPassOwnPtr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/media/rtc_certificate_generator.h" 5 #include "content/renderer/media/rtc_certificate_generator.h"
6 6
7 #include <string>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "content/renderer/media/peer_connection_identity_store.h" 11 #include "content/renderer/media/peer_connection_identity_store.h"
11 #include "content/renderer/media/rtc_certificate.h" 12 #include "content/renderer/media/rtc_certificate.h"
12 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" 13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
13 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
14 #include "third_party/webrtc/base/rtccertificate.h" 15 #include "third_party/webrtc/base/rtccertificate.h"
15 #include "third_party/webrtc/base/scoped_ref_ptr.h" 16 #include "third_party/webrtc/base/scoped_ref_ptr.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 49 }
49 ~RTCCertificateIdentityObserver() override {} 50 ~RTCCertificateIdentityObserver() override {}
50 51
51 // Perform |store|->RequestIdentity with this identity observer and ensure 52 // Perform |store|->RequestIdentity with this identity observer and ensure
52 // that this identity observer is not deleted until the request has completed 53 // that this identity observer is not deleted until the request has completed
53 // by holding on to a reference to itself for the duration of the request. 54 // by holding on to a reference to itself for the duration of the request.
54 void RequestIdentity( 55 void RequestIdentity(
55 const blink::WebRTCKeyParams& key_params, 56 const blink::WebRTCKeyParams& key_params,
56 const GURL& url, 57 const GURL& url,
57 const GURL& first_party_for_cookies, 58 const GURL& first_party_for_cookies,
58 blink::WebCallbacks<blink::WebRTCCertificate*, void>* observer) { 59 blink::WebPassOwnPtr<blink::WebRTCCertificateCallback> observer) {
59 DCHECK(main_thread_->BelongsToCurrentThread()); 60 DCHECK(main_thread_->BelongsToCurrentThread());
60 DCHECK(!observer_) << "Already have a RequestIdentity in progress."; 61 DCHECK(!observer_) << "Already have a RequestIdentity in progress.";
61 DCHECK(observer);
62 key_params_ = key_params; 62 key_params_ = key_params;
63 observer_ = observer; 63 observer_ = observer;
64 DCHECK(observer_);
64 // Identity request must be performed on the WebRTC signaling thread. 65 // Identity request must be performed on the WebRTC signaling thread.
65 signaling_thread_->PostTask(FROM_HERE, base::Bind( 66 signaling_thread_->PostTask(FROM_HERE, base::Bind(
66 &RTCCertificateIdentityObserver::RequestIdentityOnWebRtcSignalingThread, 67 &RTCCertificateIdentityObserver::RequestIdentityOnWebRtcSignalingThread,
67 this, url, first_party_for_cookies)); 68 this, url, first_party_for_cookies));
68 } 69 }
69 70
70 private: 71 private:
71 void RequestIdentityOnWebRtcSignalingThread( 72 void RequestIdentityOnWebRtcSignalingThread(
72 GURL url, 73 GURL url,
73 GURL first_party_for_cookies) { 74 GURL first_party_for_cookies) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 rtc::RTCCertificate::Create(std::move(identity)); 109 rtc::RTCCertificate::Create(std::move(identity));
109 main_thread_->PostTask(FROM_HERE, base::Bind( 110 main_thread_->PostTask(FROM_HERE, base::Bind(
110 &RTCCertificateIdentityObserver::DoCallbackOnMainThread, 111 &RTCCertificateIdentityObserver::DoCallbackOnMainThread,
111 this, new RTCCertificate(key_params_, certificate))); 112 this, new RTCCertificate(key_params_, certificate)));
112 } 113 }
113 114
114 void DoCallbackOnMainThread(blink::WebRTCCertificate* certificate) { 115 void DoCallbackOnMainThread(blink::WebRTCCertificate* certificate) {
115 DCHECK(main_thread_->BelongsToCurrentThread()); 116 DCHECK(main_thread_->BelongsToCurrentThread());
116 DCHECK(observer_); 117 DCHECK(observer_);
117 if (certificate) 118 if (certificate)
118 observer_->onSuccess(certificate); 119 observer_->onSuccess(blink::adoptWebPtr(certificate));
119 else 120 else
120 observer_->onError(); 121 observer_->onError();
122 observer_.reset();
121 } 123 }
122 124
123 // The main thread is the renderer thread. 125 // The main thread is the renderer thread.
124 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; 126 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
125 // The signaling thread is a WebRTC thread used to invoke 127 // The signaling thread is a WebRTC thread used to invoke
126 // PeerConnectionIdentityStore::RequestIdentity on, as is required. 128 // PeerConnectionIdentityStore::RequestIdentity on, as is required.
127 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_; 129 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_;
128 blink::WebRTCKeyParams key_params_; 130 blink::WebRTCKeyParams key_params_;
129 blink::WebCallbacks<blink::WebRTCCertificate*, void>* observer_; 131 scoped_ptr<blink::WebRTCCertificateCallback> observer_;
130 132
131 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver); 133 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver);
132 }; 134 };
133 135
134 } // namespace 136 } // namespace
135 137
136 void RTCCertificateGenerator::generateCertificate( 138 void RTCCertificateGenerator::generateCertificate(
137 const blink::WebRTCKeyParams& key_params, 139 const blink::WebRTCKeyParams& key_params,
138 const blink::WebURL& url, 140 const blink::WebURL& url,
139 const blink::WebURL& first_party_for_cookies, 141 const blink::WebURL& first_party_for_cookies,
140 blink::WebCallbacks<blink::WebRTCCertificate*, void>* observer) { 142 blink::WebPassOwnPtr<blink::WebRTCCertificateCallback> observer) {
141 DCHECK(isSupportedKeyParams(key_params)); 143 DCHECK(isSupportedKeyParams(key_params));
142 144
143 #if defined(ENABLE_WEBRTC) 145 #if defined(ENABLE_WEBRTC)
144 const scoped_refptr<base::SingleThreadTaskRunner> main_thread = 146 const scoped_refptr<base::SingleThreadTaskRunner> main_thread =
145 base::ThreadTaskRunnerHandle::Get(); 147 base::ThreadTaskRunnerHandle::Get();
146 148
147 PeerConnectionDependencyFactory* pc_dependency_factory = 149 PeerConnectionDependencyFactory* pc_dependency_factory =
148 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory(); 150 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory();
149 pc_dependency_factory->EnsureInitialized(); 151 pc_dependency_factory->EnsureInitialized();
150 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread = 152 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread =
151 pc_dependency_factory->GetWebRtcSignalingThread(); 153 pc_dependency_factory->GetWebRtcSignalingThread();
152 154
153 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer( 155 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer(
154 new rtc::RefCountedObject<RTCCertificateIdentityObserver>( 156 new rtc::RefCountedObject<RTCCertificateIdentityObserver>(
155 main_thread, signaling_thread)); 157 main_thread, signaling_thread));
156 // |identity_observer| lives until request has completed. 158 // |identity_observer| lives until request has completed.
157 identity_observer->RequestIdentity( 159 identity_observer->RequestIdentity(
158 key_params, url, first_party_for_cookies, observer); 160 key_params, url, first_party_for_cookies, observer);
159 #else 161 #else
160 observer->onError(); 162 observer->onError();
161 #endif 163 #endif
162 } 164 }
163 165
164 bool RTCCertificateGenerator::isSupportedKeyParams( 166 bool RTCCertificateGenerator::isSupportedKeyParams(
165 const blink::WebRTCKeyParams& key_params) { 167 const blink::WebRTCKeyParams& key_params) {
166 return WebRTCKeyParamsToKeyParams(key_params).IsValid(); 168 return WebRTCKeyParamsToKeyParams(key_params).IsValid();
167 } 169 }
168 170
169 } // namespace content 171 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_certificate_generator.h ('k') | third_party/WebKit/Source/modules/mediastream/RTCCertificate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698