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

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

Issue 1545233002: Convert Pass()→std::move() in //net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 | « net/dns/dns_socket_pool.cc ('k') | net/dns/dns_transaction_unittest.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 // 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 <string> 8 #include <string>
9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/big_endian.h" 12 #include "base/big_endian.h"
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return ParseIPLiteralToNumber(hostname, &ip); 61 return ParseIPLiteralToNumber(hostname, &ip);
61 } 62 }
62 63
63 scoped_ptr<base::Value> NetLogStartCallback( 64 scoped_ptr<base::Value> NetLogStartCallback(
64 const std::string* hostname, 65 const std::string* hostname,
65 uint16_t qtype, 66 uint16_t qtype,
66 NetLogCaptureMode /* capture_mode */) { 67 NetLogCaptureMode /* capture_mode */) {
67 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 68 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
68 dict->SetString("hostname", *hostname); 69 dict->SetString("hostname", *hostname);
69 dict->SetInteger("query_type", qtype); 70 dict->SetInteger("query_type", qtype);
70 return dict.Pass(); 71 return std::move(dict);
71 }; 72 };
72 73
73 // ---------------------------------------------------------------------------- 74 // ----------------------------------------------------------------------------
74 75
75 // A single asynchronous DNS exchange, which consists of sending out a 76 // A single asynchronous DNS exchange, which consists of sending out a
76 // DNS query, waiting for a response, and returning the response that it 77 // DNS query, waiting for a response, and returning the response that it
77 // matches. Logging is done in the socket and in the outer DnsTransaction. 78 // matches. Logging is done in the socket and in the outer DnsTransaction.
78 class DnsAttempt { 79 class DnsAttempt {
79 public: 80 public:
80 explicit DnsAttempt(unsigned server_index) 81 explicit DnsAttempt(unsigned server_index)
(...skipping 21 matching lines...) Expand all
102 // to the NetLog source source of the UDP socket used. The request must have 103 // to the NetLog source source of the UDP socket used. The request must have
103 // completed before this is called. 104 // completed before this is called.
104 scoped_ptr<base::Value> NetLogResponseCallback( 105 scoped_ptr<base::Value> NetLogResponseCallback(
105 NetLogCaptureMode capture_mode) const { 106 NetLogCaptureMode capture_mode) const {
106 DCHECK(GetResponse()->IsValid()); 107 DCHECK(GetResponse()->IsValid());
107 108
108 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 109 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
109 dict->SetInteger("rcode", GetResponse()->rcode()); 110 dict->SetInteger("rcode", GetResponse()->rcode());
110 dict->SetInteger("answer_count", GetResponse()->answer_count()); 111 dict->SetInteger("answer_count", GetResponse()->answer_count());
111 GetSocketNetLog().source().AddToEventParameters(dict.get()); 112 GetSocketNetLog().source().AddToEventParameters(dict.get());
112 return dict.Pass(); 113 return std::move(dict);
113 } 114 }
114 115
115 void set_result(int result) { 116 void set_result(int result) {
116 result_ = result; 117 result_ = result;
117 } 118 }
118 119
119 // True if current attempt is pending (waiting for server response). 120 // True if current attempt is pending (waiting for server response).
120 bool is_pending() const { 121 bool is_pending() const {
121 return result_ == ERR_IO_PENDING; 122 return result_ == ERR_IO_PENDING;
122 } 123 }
(...skipping 12 matching lines...) Expand all
135 }; 136 };
136 137
137 class DnsUDPAttempt : public DnsAttempt { 138 class DnsUDPAttempt : public DnsAttempt {
138 public: 139 public:
139 DnsUDPAttempt(unsigned server_index, 140 DnsUDPAttempt(unsigned server_index,
140 scoped_ptr<DnsSession::SocketLease> socket_lease, 141 scoped_ptr<DnsSession::SocketLease> socket_lease,
141 scoped_ptr<DnsQuery> query) 142 scoped_ptr<DnsQuery> query)
142 : DnsAttempt(server_index), 143 : DnsAttempt(server_index),
143 next_state_(STATE_NONE), 144 next_state_(STATE_NONE),
144 received_malformed_response_(false), 145 received_malformed_response_(false),
145 socket_lease_(socket_lease.Pass()), 146 socket_lease_(std::move(socket_lease)),
146 query_(query.Pass()) {} 147 query_(std::move(query)) {}
147 148
148 // DnsAttempt: 149 // DnsAttempt:
149 int Start(const CompletionCallback& callback) override { 150 int Start(const CompletionCallback& callback) override {
150 DCHECK_EQ(STATE_NONE, next_state_); 151 DCHECK_EQ(STATE_NONE, next_state_);
151 callback_ = callback; 152 callback_ = callback;
152 start_time_ = base::TimeTicks::Now(); 153 start_time_ = base::TimeTicks::Now();
153 next_state_ = STATE_SEND_QUERY; 154 next_state_ = STATE_SEND_QUERY;
154 return DoLoop(OK); 155 return DoLoop(OK);
155 } 156 }
156 157
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 DISALLOW_COPY_AND_ASSIGN(DnsUDPAttempt); 297 DISALLOW_COPY_AND_ASSIGN(DnsUDPAttempt);
297 }; 298 };
298 299
299 class DnsTCPAttempt : public DnsAttempt { 300 class DnsTCPAttempt : public DnsAttempt {
300 public: 301 public:
301 DnsTCPAttempt(unsigned server_index, 302 DnsTCPAttempt(unsigned server_index,
302 scoped_ptr<StreamSocket> socket, 303 scoped_ptr<StreamSocket> socket,
303 scoped_ptr<DnsQuery> query) 304 scoped_ptr<DnsQuery> query)
304 : DnsAttempt(server_index), 305 : DnsAttempt(server_index),
305 next_state_(STATE_NONE), 306 next_state_(STATE_NONE),
306 socket_(socket.Pass()), 307 socket_(std::move(socket)),
307 query_(query.Pass()), 308 query_(std::move(query)),
308 length_buffer_(new IOBufferWithSize(sizeof(uint16_t))), 309 length_buffer_(new IOBufferWithSize(sizeof(uint16_t))),
309 response_length_(0) {} 310 response_length_(0) {}
310 311
311 // DnsAttempt: 312 // DnsAttempt:
312 int Start(const CompletionCallback& callback) override { 313 int Start(const CompletionCallback& callback) override {
313 DCHECK_EQ(STATE_NONE, next_state_); 314 DCHECK_EQ(STATE_NONE, next_state_);
314 callback_ = callback; 315 callback_ = callback;
315 start_time_ = base::TimeTicks::Now(); 316 start_time_ = base::TimeTicks::Now();
316 next_state_ = STATE_CONNECT_COMPLETE; 317 next_state_ = STATE_CONNECT_COMPLETE;
317 int rv = socket_->Connect(base::Bind(&DnsTCPAttempt::OnIOComplete, 318 int rv = socket_->Connect(base::Bind(&DnsTCPAttempt::OnIOComplete,
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 (first_server_index_ + attempt_number) % config.nameservers.size(); 718 (first_server_index_ + attempt_number) % config.nameservers.size();
718 // Skip over known failed servers. 719 // Skip over known failed servers.
719 server_index = session_->NextGoodServerIndex(server_index); 720 server_index = session_->NextGoodServerIndex(server_index);
720 721
721 scoped_ptr<DnsSession::SocketLease> lease = 722 scoped_ptr<DnsSession::SocketLease> lease =
722 session_->AllocateSocket(server_index, net_log_.source()); 723 session_->AllocateSocket(server_index, net_log_.source());
723 724
724 bool got_socket = !!lease.get(); 725 bool got_socket = !!lease.get();
725 726
726 DnsUDPAttempt* attempt = 727 DnsUDPAttempt* attempt =
727 new DnsUDPAttempt(server_index, lease.Pass(), query.Pass()); 728 new DnsUDPAttempt(server_index, std::move(lease), std::move(query));
728 729
729 attempts_.push_back(make_scoped_ptr(attempt)); 730 attempts_.push_back(make_scoped_ptr(attempt));
730 ++attempts_count_; 731 ++attempts_count_;
731 732
732 if (!got_socket) 733 if (!got_socket)
733 return AttemptResult(ERR_CONNECTION_REFUSED, NULL); 734 return AttemptResult(ERR_CONNECTION_REFUSED, NULL);
734 735
735 net_log_.AddEvent( 736 net_log_.AddEvent(
736 NetLog::TYPE_DNS_TRANSACTION_ATTEMPT, 737 NetLog::TYPE_DNS_TRANSACTION_ATTEMPT,
737 attempt->GetSocketNetLog().source().ToEventParametersCallback()); 738 attempt->GetSocketNetLog().source().ToEventParametersCallback());
(...skipping 23 matching lines...) Expand all
761 uint16_t id = session_->NextQueryId(); 762 uint16_t id = session_->NextQueryId();
762 scoped_ptr<DnsQuery> query = 763 scoped_ptr<DnsQuery> query =
763 previous_attempt->GetQuery()->CloneWithNewId(id); 764 previous_attempt->GetQuery()->CloneWithNewId(id);
764 765
765 RecordLostPacketsIfAny(); 766 RecordLostPacketsIfAny();
766 // Cancel all other attempts, no point waiting on them. 767 // Cancel all other attempts, no point waiting on them.
767 attempts_.clear(); 768 attempts_.clear();
768 769
769 unsigned attempt_number = attempts_.size(); 770 unsigned attempt_number = attempts_.size();
770 771
771 DnsTCPAttempt* attempt = new DnsTCPAttempt(server_index, socket.Pass(), 772 DnsTCPAttempt* attempt =
772 query.Pass()); 773 new DnsTCPAttempt(server_index, std::move(socket), std::move(query));
773 774
774 attempts_.push_back(make_scoped_ptr(attempt)); 775 attempts_.push_back(make_scoped_ptr(attempt));
775 ++attempts_count_; 776 ++attempts_count_;
776 had_tcp_attempt_ = true; 777 had_tcp_attempt_ = true;
777 778
778 net_log_.AddEvent( 779 net_log_.AddEvent(
779 NetLog::TYPE_DNS_TRANSACTION_TCP_ATTEMPT, 780 NetLog::TYPE_DNS_TRANSACTION_TCP_ATTEMPT,
780 attempt->GetSocketNetLog().source().ToEventParametersCallback()); 781 attempt->GetSocketNetLog().source().ToEventParametersCallback());
781 782
782 int rv = attempt->Start(base::Bind(&DnsTransactionImpl::OnAttemptComplete, 783 int rv = attempt->Start(base::Bind(&DnsTransactionImpl::OnAttemptComplete,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 } // namespace 993 } // namespace
993 994
994 // static 995 // static
995 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( 996 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory(
996 DnsSession* session) { 997 DnsSession* session) {
997 return scoped_ptr<DnsTransactionFactory>( 998 return scoped_ptr<DnsTransactionFactory>(
998 new DnsTransactionFactoryImpl(session)); 999 new DnsTransactionFactoryImpl(session));
999 } 1000 }
1000 1001
1001 } // namespace net 1002 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_socket_pool.cc ('k') | net/dns/dns_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698