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

Side by Side Diff: webrtc/p2p/stunprober/stunprober.cc

Issue 1967193002: ThreadScope concept to check variable accessed on correct thread (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: generalized ThreadScope Created 4 years, 7 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 | « webrtc/base/thread_scope.h ('k') | webrtc/pc/channel.h » ('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 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 15
16 #include "webrtc/base/asyncpacketsocket.h" 16 #include "webrtc/base/asyncpacketsocket.h"
17 #include "webrtc/base/asyncresolverinterface.h" 17 #include "webrtc/base/asyncresolverinterface.h"
18 #include "webrtc/base/bind.h" 18 #include "webrtc/base/bind.h"
19 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
20 #include "webrtc/base/constructormagic.h" 20 #include "webrtc/base/constructormagic.h"
21 #include "webrtc/base/helpers.h" 21 #include "webrtc/base/helpers.h"
22 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
23 #include "webrtc/base/timeutils.h" 23 #include "webrtc/base/timeutils.h"
24 #include "webrtc/base/thread.h" 24 #include "webrtc/base/thread.h"
25 #include "webrtc/base/thread_scope.h"
25 #include "webrtc/p2p/base/packetsocketfactory.h" 26 #include "webrtc/p2p/base/packetsocketfactory.h"
26 #include "webrtc/p2p/base/stun.h" 27 #include "webrtc/p2p/base/stun.h"
27 #include "webrtc/p2p/stunprober/stunprober.h" 28 #include "webrtc/p2p/stunprober/stunprober.h"
28 29
29 namespace stunprober { 30 namespace stunprober {
30 31
31 namespace { 32 namespace {
32 33
33 const int THREAD_WAKE_UP_INTERVAL_MS = 5; 34 const int THREAD_WAKE_UP_INTERVAL_MS = 5;
34 35
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 91
91 StunProber* prober_; 92 StunProber* prober_;
92 93
93 // The socket for this session. 94 // The socket for this session.
94 std::unique_ptr<rtc::AsyncPacketSocket> socket_; 95 std::unique_ptr<rtc::AsyncPacketSocket> socket_;
95 96
96 // Temporary SocketAddress and buffer for RecvFrom. 97 // Temporary SocketAddress and buffer for RecvFrom.
97 rtc::SocketAddress addr_; 98 rtc::SocketAddress addr_;
98 std::unique_ptr<rtc::ByteBufferWriter> response_packet_; 99 std::unique_ptr<rtc::ByteBufferWriter> response_packet_;
99 100
100 std::vector<Request*> requests_; 101 std::vector<Request*> requests_ GUARDED_BY(thread_checker_);
101 std::vector<rtc::SocketAddress> server_ips_; 102 std::vector<rtc::SocketAddress> server_ips_;
102 int16_t num_request_sent_ = 0; 103 int16_t num_request_sent_ = 0;
103 int16_t num_response_received_ = 0; 104 int16_t num_response_received_ = 0;
104 105
105 rtc::ThreadChecker& thread_checker_; 106 rtc::ThreadChecker& thread_checker_;
106 107
107 RTC_DISALLOW_COPY_AND_ASSIGN(Requester); 108 RTC_DISALLOW_COPY_AND_ASSIGN(Requester);
108 }; 109 };
109 110
110 StunProber::Requester::Requester( 111 StunProber::Requester::Requester(
(...skipping 14 matching lines...) Expand all
125 socket_->Close(); 126 socket_->Close();
126 } 127 }
127 for (auto req : requests_) { 128 for (auto req : requests_) {
128 if (req) { 129 if (req) {
129 delete req; 130 delete req;
130 } 131 }
131 } 132 }
132 } 133 }
133 134
134 void StunProber::Requester::SendStunRequest() { 135 void StunProber::Requester::SendStunRequest() {
135 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 136 RTC_DCHECK_RUN_ON(&thread_checker_);
136 requests_.push_back(new Request()); 137 requests_.push_back(new Request());
137 Request& request = *(requests_.back()); 138 Request& request = *(requests_.back());
138 cricket::StunMessage message; 139 cricket::StunMessage message;
139 140
140 // Random transaction ID, STUN_BINDING_REQUEST 141 // Random transaction ID, STUN_BINDING_REQUEST
141 message.SetTransactionID( 142 message.SetTransactionID(
142 rtc::CreateRandomString(cricket::kStunTransactionIdLength)); 143 rtc::CreateRandomString(cricket::kStunTransactionIdLength));
143 message.SetType(cricket::STUN_BINDING_REQUEST); 144 message.SetType(cricket::STUN_BINDING_REQUEST);
144 145
145 std::unique_ptr<rtc::ByteBufferWriter> request_packet( 146 std::unique_ptr<rtc::ByteBufferWriter> request_packet(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 prober_->ReportOnFinished(GENERIC_FAILURE); 213 prober_->ReportOnFinished(GENERIC_FAILURE);
213 return; 214 return;
214 } 215 }
215 216
216 num_response_received_++; 217 num_response_received_++;
217 request->ProcessResponse(buf, size); 218 request->ProcessResponse(buf, size);
218 } 219 }
219 220
220 StunProber::Requester::Request* StunProber::Requester::GetRequestByAddress( 221 StunProber::Requester::Request* StunProber::Requester::GetRequestByAddress(
221 const rtc::IPAddress& ipaddr) { 222 const rtc::IPAddress& ipaddr) {
222 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 223 RTC_DCHECK_RUN_ON(&thread_checker_);
223 for (auto request : requests_) { 224 for (auto request : requests_) {
224 if (request->server_addr == ipaddr) { 225 if (request->server_addr == ipaddr) {
225 return request; 226 return request;
226 } 227 }
227 } 228 }
228 229
229 return nullptr; 230 return nullptr;
230 } 231 }
231 232
232 StunProber::StunProber(rtc::PacketSocketFactory* socket_factory, 233 StunProber::StunProber(rtc::PacketSocketFactory* socket_factory,
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 564 }
564 } 565 }
565 566
566 void StunProber::ReportOnFinished(StunProber::Status status) { 567 void StunProber::ReportOnFinished(StunProber::Status status) {
567 if (observer_) { 568 if (observer_) {
568 observer_->OnFinished(this, status); 569 observer_->OnFinished(this, status);
569 } 570 }
570 } 571 }
571 572
572 } // namespace stunprober 573 } // namespace stunprober
OLDNEW
« no previous file with comments | « webrtc/base/thread_scope.h ('k') | webrtc/pc/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698