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

Side by Side Diff: net/dns/dns_transaction.cc

Issue 2910473005: Deprecate NonThreadSafe in net/ in favor of SequenceChecker/ThreadChecker. (Closed)
Patch Set: another compile nit Created 3 years, 6 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 "net/dns/dns_transaction.h" 5 #include "net/dns/dns_transaction.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/big_endian.h" 13 #include "base/big_endian.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/profiler/scoped_tracker.h" 21 #include "base/profiler/scoped_tracker.h"
22 #include "base/rand_util.h" 22 #include "base/rand_util.h"
23 #include "base/sequence_checker.h"
23 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
24 #include "base/stl_util.h" 25 #include "base/stl_util.h"
25 #include "base/strings/string_piece.h" 26 #include "base/strings/string_piece.h"
26 #include "base/threading/non_thread_safe.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/timer/timer.h" 28 #include "base/timer/timer.h"
29 #include "base/values.h" 29 #include "base/values.h"
30 #include "net/base/completion_callback.h" 30 #include "net/base/completion_callback.h"
31 #include "net/base/io_buffer.h" 31 #include "net/base/io_buffer.h"
32 #include "net/base/ip_address.h" 32 #include "net/base/ip_address.h"
33 #include "net/base/ip_endpoint.h" 33 #include "net/base/ip_endpoint.h"
34 #include "net/base/net_errors.h" 34 #include "net/base/net_errors.h"
35 #include "net/dns/dns_protocol.h" 35 #include "net/dns/dns_protocol.h"
36 #include "net/dns/dns_query.h" 36 #include "net/dns/dns_query.h"
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 552
553 // ---------------------------------------------------------------------------- 553 // ----------------------------------------------------------------------------
554 554
555 // Implements DnsTransaction. Configuration is supplied by DnsSession. 555 // Implements DnsTransaction. Configuration is supplied by DnsSession.
556 // The suffix list is built according to the DnsConfig from the session. 556 // The suffix list is built according to the DnsConfig from the session.
557 // The timeout for each DnsUDPAttempt is given by DnsSession::NextTimeout. 557 // The timeout for each DnsUDPAttempt is given by DnsSession::NextTimeout.
558 // The first server to attempt on each query is given by 558 // The first server to attempt on each query is given by
559 // DnsSession::NextFirstServerIndex, and the order is round-robin afterwards. 559 // DnsSession::NextFirstServerIndex, and the order is round-robin afterwards.
560 // Each server is attempted DnsConfig::attempts times. 560 // Each server is attempted DnsConfig::attempts times.
561 class DnsTransactionImpl : public DnsTransaction, 561 class DnsTransactionImpl : public DnsTransaction,
562 public base::NonThreadSafe,
563 public base::SupportsWeakPtr<DnsTransactionImpl> { 562 public base::SupportsWeakPtr<DnsTransactionImpl> {
564 public: 563 public:
565 DnsTransactionImpl(DnsSession* session, 564 DnsTransactionImpl(DnsSession* session,
566 const std::string& hostname, 565 const std::string& hostname,
567 uint16_t qtype, 566 uint16_t qtype,
568 const DnsTransactionFactory::CallbackType& callback, 567 const DnsTransactionFactory::CallbackType& callback,
569 const NetLogWithSource& net_log) 568 const NetLogWithSource& net_log)
570 : session_(session), 569 : session_(session),
571 hostname_(hostname), 570 hostname_(hostname),
572 qtype_(qtype), 571 qtype_(qtype),
573 callback_(callback), 572 callback_(callback),
574 net_log_(net_log), 573 net_log_(net_log),
575 qnames_initial_size_(0), 574 qnames_initial_size_(0),
576 attempts_count_(0), 575 attempts_count_(0),
577 had_tcp_attempt_(false), 576 had_tcp_attempt_(false),
578 first_server_index_(0) { 577 first_server_index_(0) {
579 DCHECK(session_.get()); 578 DCHECK(session_.get());
580 DCHECK(!hostname_.empty()); 579 DCHECK(!hostname_.empty());
581 DCHECK(!callback_.is_null()); 580 DCHECK(!callback_.is_null());
582 DCHECK(!IsIPLiteral(hostname_)); 581 DCHECK(!IsIPLiteral(hostname_));
583 } 582 }
584 583
585 ~DnsTransactionImpl() override { 584 ~DnsTransactionImpl() override {
585 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
586 if (!callback_.is_null()) { 586 if (!callback_.is_null()) {
587 net_log_.EndEventWithNetErrorCode(NetLogEventType::DNS_TRANSACTION, 587 net_log_.EndEventWithNetErrorCode(NetLogEventType::DNS_TRANSACTION,
588 ERR_ABORTED); 588 ERR_ABORTED);
589 } // otherwise logged in DoCallback or Start 589 } // otherwise logged in DoCallback or Start
590 } 590 }
591 591
592 const std::string& GetHostname() const override { 592 const std::string& GetHostname() const override {
593 DCHECK(CalledOnValidThread()); 593 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
594 return hostname_; 594 return hostname_;
595 } 595 }
596 596
597 uint16_t GetType() const override { 597 uint16_t GetType() const override {
598 DCHECK(CalledOnValidThread()); 598 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
599 return qtype_; 599 return qtype_;
600 } 600 }
601 601
602 void Start() override { 602 void Start() override {
603 DCHECK(!callback_.is_null()); 603 DCHECK(!callback_.is_null());
604 DCHECK(attempts_.empty()); 604 DCHECK(attempts_.empty());
605 net_log_.BeginEvent(NetLogEventType::DNS_TRANSACTION, 605 net_log_.BeginEvent(NetLogEventType::DNS_TRANSACTION,
606 base::Bind(&NetLogStartCallback, &hostname_, qtype_)); 606 base::Bind(&NetLogStartCallback, &hostname_, qtype_));
607 AttemptResult result(PrepareSearch(), NULL); 607 AttemptResult result(PrepareSearch(), NULL);
608 if (result.rv == OK) { 608 if (result.rv == OK) {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 std::vector<std::unique_ptr<DnsAttempt>> attempts_; 963 std::vector<std::unique_ptr<DnsAttempt>> attempts_;
964 // Count of attempts, not reset when |attempts_| vector is cleared. 964 // Count of attempts, not reset when |attempts_| vector is cleared.
965 int attempts_count_; 965 int attempts_count_;
966 bool had_tcp_attempt_; 966 bool had_tcp_attempt_;
967 967
968 // Index of the first server to try on each search query. 968 // Index of the first server to try on each search query.
969 int first_server_index_; 969 int first_server_index_;
970 970
971 base::OneShotTimer timer_; 971 base::OneShotTimer timer_;
972 972
973 SEQUENCE_CHECKER(sequence_checker_);
974
973 DISALLOW_COPY_AND_ASSIGN(DnsTransactionImpl); 975 DISALLOW_COPY_AND_ASSIGN(DnsTransactionImpl);
974 }; 976 };
975 977
976 // ---------------------------------------------------------------------------- 978 // ----------------------------------------------------------------------------
977 979
978 // Implementation of DnsTransactionFactory that returns instances of 980 // Implementation of DnsTransactionFactory that returns instances of
979 // DnsTransactionImpl. 981 // DnsTransactionImpl.
980 class DnsTransactionFactoryImpl : public DnsTransactionFactory { 982 class DnsTransactionFactoryImpl : public DnsTransactionFactory {
981 public: 983 public:
982 explicit DnsTransactionFactoryImpl(DnsSession* session) { 984 explicit DnsTransactionFactoryImpl(DnsSession* session) {
(...skipping 16 matching lines...) Expand all
999 } // namespace 1001 } // namespace
1000 1002
1001 // static 1003 // static
1002 std::unique_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( 1004 std::unique_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory(
1003 DnsSession* session) { 1005 DnsSession* session) {
1004 return std::unique_ptr<DnsTransactionFactory>( 1006 return std::unique_ptr<DnsTransactionFactory>(
1005 new DnsTransactionFactoryImpl(session)); 1007 new DnsTransactionFactoryImpl(session));
1006 } 1008 }
1007 1009
1008 } // namespace net 1010 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698