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

Side by Side Diff: talk/app/webrtc/dtlsidentitystore.cc

Issue 1460043002: Don't call the Pass methods of rtc::Buffer, rtc::scoped_ptr, and rtc::ScopedVector (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Restore the Pass methods Created 5 years 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 | « talk/app/webrtc/dtlsidentitystore.h ('k') | talk/app/webrtc/java/jni/peerconnection_jni.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation 11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution. 12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products 13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/dtlsidentitystore.h" 28 #include "talk/app/webrtc/dtlsidentitystore.h"
29 29
30 #include <utility>
31
30 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" 32 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
31 #include "webrtc/base/logging.h" 33 #include "webrtc/base/logging.h"
32 34
33 using webrtc::DtlsIdentityRequestObserver; 35 using webrtc::DtlsIdentityRequestObserver;
34 36
35 namespace webrtc { 37 namespace webrtc {
36 38
37 // Passed to SSLIdentity::Generate, "WebRTC". Used for the certificates' 39 // Passed to SSLIdentity::Generate, "WebRTC". Used for the certificates'
38 // subject and issuer name. 40 // subject and issuer name.
39 const char kIdentityName[] = "WebRTC"; 41 const char kIdentityName[] = "WebRTC";
(...skipping 25 matching lines...) Expand all
65 67
66 private: 68 private:
67 void GenerateIdentity_w() { 69 void GenerateIdentity_w() {
68 LOG(LS_INFO) << "Generating identity, using keytype " << key_type_; 70 LOG(LS_INFO) << "Generating identity, using keytype " << key_type_;
69 rtc::scoped_ptr<rtc::SSLIdentity> identity( 71 rtc::scoped_ptr<rtc::SSLIdentity> identity(
70 rtc::SSLIdentity::Generate(kIdentityName, key_type_)); 72 rtc::SSLIdentity::Generate(kIdentityName, key_type_));
71 73
72 // Posting to |this| avoids touching |store_| on threads other than 74 // Posting to |this| avoids touching |store_| on threads other than
73 // |signaling_thread_| and thus avoids having to use locks. 75 // |signaling_thread_| and thus avoids having to use locks.
74 IdentityResultMessageData* msg = new IdentityResultMessageData( 76 IdentityResultMessageData* msg = new IdentityResultMessageData(
75 new IdentityResult(key_type_, identity.Pass())); 77 new IdentityResult(key_type_, std::move(identity)));
76 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY_RESULT, msg); 78 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY_RESULT, msg);
77 } 79 }
78 80
79 void OnMessage(rtc::Message* msg) override { 81 void OnMessage(rtc::Message* msg) override {
80 switch (msg->message_id) { 82 switch (msg->message_id) {
81 case MSG_GENERATE_IDENTITY: 83 case MSG_GENERATE_IDENTITY:
82 // This message always runs on the worker thread. 84 // This message always runs on the worker thread.
83 GenerateIdentity_w(); 85 GenerateIdentity_w();
84 86
85 // Must delete |this|, owned by msg->pdata, on the signaling thread to 87 // Must delete |this|, owned by msg->pdata, on the signaling thread to
86 // avoid races on disconnecting the signal. 88 // avoid races on disconnecting the signal.
87 signaling_thread_->Post(this, MSG_DESTROY, msg->pdata); 89 signaling_thread_->Post(this, MSG_DESTROY, msg->pdata);
88 break; 90 break;
89 case MSG_GENERATE_IDENTITY_RESULT: 91 case MSG_GENERATE_IDENTITY_RESULT:
90 RTC_DCHECK(signaling_thread_->IsCurrent()); 92 RTC_DCHECK(signaling_thread_->IsCurrent());
91 { 93 {
92 rtc::scoped_ptr<IdentityResultMessageData> pdata( 94 rtc::scoped_ptr<IdentityResultMessageData> pdata(
93 static_cast<IdentityResultMessageData*>(msg->pdata)); 95 static_cast<IdentityResultMessageData*>(msg->pdata));
94 if (store_) { 96 if (store_) {
95 store_->OnIdentityGenerated(pdata->data()->key_type_, 97 store_->OnIdentityGenerated(pdata->data()->key_type_,
96 pdata->data()->identity_.Pass()); 98 std::move(pdata->data()->identity_));
97 } 99 }
98 } 100 }
99 break; 101 break;
100 case MSG_DESTROY: 102 case MSG_DESTROY:
101 RTC_DCHECK(signaling_thread_->IsCurrent()); 103 RTC_DCHECK(signaling_thread_->IsCurrent());
102 delete msg->pdata; 104 delete msg->pdata;
103 // |this| has now been deleted. Don't touch member variables. 105 // |this| has now been deleted. Don't touch member variables.
104 break; 106 break;
105 default: 107 default:
106 RTC_CHECK(false) << "Unexpected message type"; 108 RTC_CHECK(false) << "Unexpected message type";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 GenerateIdentity(key_type, observer); 147 GenerateIdentity(key_type, observer);
146 } 148 }
147 149
148 void DtlsIdentityStoreImpl::OnMessage(rtc::Message* msg) { 150 void DtlsIdentityStoreImpl::OnMessage(rtc::Message* msg) {
149 RTC_DCHECK(signaling_thread_->IsCurrent()); 151 RTC_DCHECK(signaling_thread_->IsCurrent());
150 switch (msg->message_id) { 152 switch (msg->message_id) {
151 case MSG_GENERATE_IDENTITY_RESULT: { 153 case MSG_GENERATE_IDENTITY_RESULT: {
152 rtc::scoped_ptr<IdentityResultMessageData> pdata( 154 rtc::scoped_ptr<IdentityResultMessageData> pdata(
153 static_cast<IdentityResultMessageData*>(msg->pdata)); 155 static_cast<IdentityResultMessageData*>(msg->pdata));
154 OnIdentityGenerated(pdata->data()->key_type_, 156 OnIdentityGenerated(pdata->data()->key_type_,
155 pdata->data()->identity_.Pass()); 157 std::move(pdata->data()->identity_));
156 break; 158 break;
157 } 159 }
158 } 160 }
159 } 161 }
160 162
161 bool DtlsIdentityStoreImpl::HasFreeIdentityForTesting( 163 bool DtlsIdentityStoreImpl::HasFreeIdentityForTesting(
162 rtc::KeyType key_type) const { 164 rtc::KeyType key_type) const {
163 RTC_DCHECK(signaling_thread_->IsCurrent()); 165 RTC_DCHECK(signaling_thread_->IsCurrent());
164 return request_info_[key_type].free_identity_.get() != nullptr; 166 return request_info_[key_type].free_identity_.get() != nullptr;
165 } 167 }
166 168
167 void DtlsIdentityStoreImpl::GenerateIdentity( 169 void DtlsIdentityStoreImpl::GenerateIdentity(
168 rtc::KeyType key_type, 170 rtc::KeyType key_type,
169 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& observer) { 171 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& observer) {
170 RTC_DCHECK(signaling_thread_->IsCurrent()); 172 RTC_DCHECK(signaling_thread_->IsCurrent());
171 173
172 // Enqueue observer to be informed when generation of |key_type| is completed. 174 // Enqueue observer to be informed when generation of |key_type| is completed.
173 if (observer.get()) { 175 if (observer.get()) {
174 request_info_[key_type].request_observers_.push(observer); 176 request_info_[key_type].request_observers_.push(observer);
175 177
176 // Already have a free identity generated? 178 // Already have a free identity generated?
177 if (request_info_[key_type].free_identity_.get()) { 179 if (request_info_[key_type].free_identity_.get()) {
178 // Return identity async - post even though we are on |signaling_thread_|. 180 // Return identity async - post even though we are on |signaling_thread_|.
179 LOG(LS_VERBOSE) << "Using a free DTLS identity."; 181 LOG(LS_VERBOSE) << "Using a free DTLS identity.";
180 ++request_info_[key_type].gen_in_progress_counts_; 182 ++request_info_[key_type].gen_in_progress_counts_;
181 IdentityResultMessageData* msg = new IdentityResultMessageData( 183 IdentityResultMessageData* msg =
182 new IdentityResult(key_type, 184 new IdentityResultMessageData(new IdentityResult(
183 request_info_[key_type].free_identity_.Pass())); 185 key_type, std::move(request_info_[key_type].free_identity_)));
184 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY_RESULT, msg); 186 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY_RESULT, msg);
185 return; 187 return;
186 } 188 }
187 189
188 // Free identity in the process of being generated? 190 // Free identity in the process of being generated?
189 if (request_info_[key_type].gen_in_progress_counts_ == 191 if (request_info_[key_type].gen_in_progress_counts_ ==
190 request_info_[key_type].request_observers_.size()) { 192 request_info_[key_type].request_observers_.size()) {
191 // No need to do anything, the free identity will be returned to the 193 // No need to do anything, the free identity will be returned to the
192 // observer in a MSG_GENERATE_IDENTITY_RESULT. 194 // observer in a MSG_GENERATE_IDENTITY_RESULT.
193 return; 195 return;
(...skipping 27 matching lines...) Expand all
221 RTC_DCHECK(!request_info_[key_type].free_identity_.get()); 223 RTC_DCHECK(!request_info_[key_type].free_identity_.get());
222 request_info_[key_type].free_identity_.swap(identity); 224 request_info_[key_type].free_identity_.swap(identity);
223 if (request_info_[key_type].free_identity_.get()) 225 if (request_info_[key_type].free_identity_.get())
224 LOG(LS_VERBOSE) << "A free DTLS identity was saved."; 226 LOG(LS_VERBOSE) << "A free DTLS identity was saved.";
225 else 227 else
226 LOG(LS_WARNING) << "Failed to generate DTLS identity (preemptively)."; 228 LOG(LS_WARNING) << "Failed to generate DTLS identity (preemptively).";
227 } else { 229 } else {
228 // Return the result to the observer. 230 // Return the result to the observer.
229 if (identity.get()) { 231 if (identity.get()) {
230 LOG(LS_VERBOSE) << "A DTLS identity is returned to an observer."; 232 LOG(LS_VERBOSE) << "A DTLS identity is returned to an observer.";
231 observer->OnSuccess(identity.Pass()); 233 observer->OnSuccess(std::move(identity));
232 } else { 234 } else {
233 LOG(LS_WARNING) << "Failed to generate DTLS identity."; 235 LOG(LS_WARNING) << "Failed to generate DTLS identity.";
234 observer->OnFailure(0); 236 observer->OnFailure(0);
235 } 237 }
236 238
237 // Preemptively generate another identity of the same type? 239 // Preemptively generate another identity of the same type?
238 if (worker_thread_ != signaling_thread_ && // Only do in background thread. 240 if (worker_thread_ != signaling_thread_ && // Only do in background thread.
239 key_type == rtc::KT_RSA && // Only necessary for RSA. 241 key_type == rtc::KT_RSA && // Only necessary for RSA.
240 !request_info_[key_type].free_identity_.get() && 242 !request_info_[key_type].free_identity_.get() &&
241 request_info_[key_type].request_observers_.size() <= 243 request_info_[key_type].request_observers_.size() <=
242 request_info_[key_type].gen_in_progress_counts_) { 244 request_info_[key_type].gen_in_progress_counts_) {
243 GenerateIdentity(key_type, nullptr); 245 GenerateIdentity(key_type, nullptr);
244 } 246 }
245 } 247 }
246 } 248 }
247 249
248 } // namespace webrtc 250 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/dtlsidentitystore.h ('k') | talk/app/webrtc/java/jni/peerconnection_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698