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

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

Issue 2164503002: Do not delete blink::WebRTCCertificateCallback on non-main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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
« no previous file with comments | « base/sequenced_task_runner_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 25 matching lines...) Expand all
36 return rtc::KeyParams(); 36 return rtc::KeyParams();
37 } 37 }
38 } 38 }
39 39
40 // A certificate generation request spawned by 40 // A certificate generation request spawned by
41 // |RTCCertificateGenerator::generateCertificateWithOptionalExpiration|. This 41 // |RTCCertificateGenerator::generateCertificateWithOptionalExpiration|. This
42 // is handled by a separate class so that reference counting can keep the 42 // is handled by a separate class so that reference counting can keep the
43 // request alive independently of the |RTCCertificateGenerator| that spawned it. 43 // request alive independently of the |RTCCertificateGenerator| that spawned it.
44 class RTCCertificateGeneratorRequest 44 class RTCCertificateGeneratorRequest
45 : public base::RefCountedThreadSafe<RTCCertificateGeneratorRequest> { 45 : public base::RefCountedThreadSafe<RTCCertificateGeneratorRequest> {
46 private:
47 using CertificateCallbackPtr = std::unique_ptr<
48 blink::WebRTCCertificateCallback,
49 base::OnTaskRunnerDeleter>;
46 public: 50 public:
47 RTCCertificateGeneratorRequest( 51 RTCCertificateGeneratorRequest(
48 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, 52 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
49 const scoped_refptr<base::SingleThreadTaskRunner>& worker_thread) 53 const scoped_refptr<base::SingleThreadTaskRunner>& worker_thread)
50 : main_thread_(main_thread), 54 : main_thread_(main_thread),
51 worker_thread_(worker_thread) { 55 worker_thread_(worker_thread) {
52 DCHECK(main_thread_); 56 DCHECK(main_thread_);
53 DCHECK(worker_thread_); 57 DCHECK(worker_thread_);
54 } 58 }
55 59
56 void GenerateCertificateAsync( 60 void GenerateCertificateAsync(
57 const blink::WebRTCKeyParams& key_params, 61 const blink::WebRTCKeyParams& key_params,
58 const rtc::Optional<uint64_t>& expires_ms, 62 const rtc::Optional<uint64_t>& expires_ms,
59 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { 63 std::unique_ptr<blink::WebRTCCertificateCallback> observer) {
60 DCHECK(main_thread_->BelongsToCurrentThread()); 64 DCHECK(main_thread_->BelongsToCurrentThread());
61 DCHECK(observer); 65 DCHECK(observer);
66
67 CertificateCallbackPtr transition(
68 observer.release(),
69 base::OnTaskRunnerDeleter(base::ThreadTaskRunnerHandle::Get()));
62 worker_thread_->PostTask(FROM_HERE, base::Bind( 70 worker_thread_->PostTask(FROM_HERE, base::Bind(
63 &RTCCertificateGeneratorRequest::GenerateCertificateOnWorkerThread, 71 &RTCCertificateGeneratorRequest::GenerateCertificateOnWorkerThread,
64 this, 72 this,
65 key_params, 73 key_params,
66 expires_ms, 74 expires_ms,
67 base::Passed(std::move(observer)))); 75 base::Passed(&transition)));
68 } 76 }
69 77
70 private: 78 private:
71 friend class base::RefCountedThreadSafe<RTCCertificateGeneratorRequest>; 79 friend class base::RefCountedThreadSafe<RTCCertificateGeneratorRequest>;
72 ~RTCCertificateGeneratorRequest() {} 80 ~RTCCertificateGeneratorRequest() {}
73 81
74 void GenerateCertificateOnWorkerThread( 82 void GenerateCertificateOnWorkerThread(
75 const blink::WebRTCKeyParams key_params, 83 const blink::WebRTCKeyParams key_params,
76 const rtc::Optional<uint64_t> expires_ms, 84 const rtc::Optional<uint64_t> expires_ms,
77 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { 85 CertificateCallbackPtr observer) {
78 DCHECK(worker_thread_->BelongsToCurrentThread()); 86 DCHECK(worker_thread_->BelongsToCurrentThread());
79 87
80 rtc::scoped_refptr<rtc::RTCCertificate> certificate = 88 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
81 rtc::RTCCertificateGenerator::GenerateCertificate( 89 rtc::RTCCertificateGenerator::GenerateCertificate(
82 WebRTCKeyParamsToKeyParams(key_params), expires_ms); 90 WebRTCKeyParamsToKeyParams(key_params), expires_ms);
83 91
84 main_thread_->PostTask(FROM_HERE, base::Bind( 92 main_thread_->PostTask(FROM_HERE, base::Bind(
85 &RTCCertificateGeneratorRequest::DoCallbackOnMainThread, 93 &RTCCertificateGeneratorRequest::DoCallbackOnMainThread,
86 this, 94 this,
87 base::Passed(std::move(observer)), 95 base::Passed(std::move(observer)),
88 base::Passed(base::WrapUnique(new RTCCertificate(certificate))))); 96 base::Passed(base::WrapUnique(new RTCCertificate(certificate)))));
89 } 97 }
90 98
91 void DoCallbackOnMainThread( 99 void DoCallbackOnMainThread(
92 std::unique_ptr<blink::WebRTCCertificateCallback> observer, 100 CertificateCallbackPtr observer,
93 std::unique_ptr<blink::WebRTCCertificate> certificate) { 101 std::unique_ptr<blink::WebRTCCertificate> certificate) {
94 DCHECK(main_thread_->BelongsToCurrentThread()); 102 DCHECK(main_thread_->BelongsToCurrentThread());
95 DCHECK(observer); 103 DCHECK(observer);
96 if (certificate) 104 if (certificate)
97 observer->onSuccess(std::move(certificate)); 105 observer->onSuccess(std::move(certificate));
98 else 106 else
99 observer->onError(); 107 observer->onError();
100 } 108 }
101 109
102 // The main thread is the renderer thread. 110 // The main thread is the renderer thread.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 blink::WebString pem_certificate) { 163 blink::WebString pem_certificate) {
156 rtc::scoped_refptr<rtc::RTCCertificate> certificate = 164 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
157 rtc::RTCCertificate::FromPEM( 165 rtc::RTCCertificate::FromPEM(
158 rtc::RTCCertificatePEM(pem_private_key.utf8(), 166 rtc::RTCCertificatePEM(pem_private_key.utf8(),
159 pem_certificate.utf8())); 167 pem_certificate.utf8()));
160 return std::unique_ptr<blink::WebRTCCertificate>( 168 return std::unique_ptr<blink::WebRTCCertificate>(
161 new RTCCertificate(certificate)); 169 new RTCCertificate(certificate));
162 } 170 }
163 171
164 } // namespace content 172 } // namespace content
OLDNEW
« no previous file with comments | « base/sequenced_task_runner_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698