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

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 2904643002: Remove some naked |new| statements in favor of MakeUnique. (Closed)
Patch Set: Revert changes in one test where it caused a crash. Created 3 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
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/http/http_stream_factory_impl_job.h" 5 #include "net/http/http_stream_factory_impl_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/sparse_histogram.h" 17 #include "base/metrics/sparse_histogram.h"
17 #include "base/profiler/scoped_tracker.h" 18 #include "base/profiler/scoped_tracker.h"
18 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
19 #include "base/stl_util.h" 20 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
24 #include "base/values.h" 25 #include "base/values.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } // namespace 121 } // namespace
121 122
122 // Returns parameters associated with the start of a HTTP stream job. 123 // Returns parameters associated with the start of a HTTP stream job.
123 std::unique_ptr<base::Value> NetLogHttpStreamJobCallback( 124 std::unique_ptr<base::Value> NetLogHttpStreamJobCallback(
124 const NetLogSource& source, 125 const NetLogSource& source,
125 const GURL* original_url, 126 const GURL* original_url,
126 const GURL* url, 127 const GURL* url,
127 const AlternativeService* alternative_service, 128 const AlternativeService* alternative_service,
128 RequestPriority priority, 129 RequestPriority priority,
129 NetLogCaptureMode /* capture_mode */) { 130 NetLogCaptureMode /* capture_mode */) {
130 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 131 auto dict = base::MakeUnique<base::DictionaryValue>();
131 if (source.IsValid()) 132 if (source.IsValid())
132 source.AddToEventParameters(dict.get()); 133 source.AddToEventParameters(dict.get());
133 dict->SetString("original_url", original_url->GetOrigin().spec()); 134 dict->SetString("original_url", original_url->GetOrigin().spec());
134 dict->SetString("url", url->GetOrigin().spec()); 135 dict->SetString("url", url->GetOrigin().spec());
135 dict->SetString("alternative_service", alternative_service->ToString()); 136 dict->SetString("alternative_service", alternative_service->ToString());
136 dict->SetString("priority", RequestPriorityToString(priority)); 137 dict->SetString("priority", RequestPriorityToString(priority));
137 return std::move(dict); 138 return std::move(dict);
138 } 139 }
139 140
140 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP 141 // Returns parameters associated with the Proto (with NPN negotiation) of a HTTP
141 // stream. 142 // stream.
142 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback( 143 std::unique_ptr<base::Value> NetLogHttpStreamProtoCallback(
143 NextProto negotiated_protocol, 144 NextProto negotiated_protocol,
144 NetLogCaptureMode /* capture_mode */) { 145 NetLogCaptureMode /* capture_mode */) {
145 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 146 auto dict = base::MakeUnique<base::DictionaryValue>();
146 147
147 dict->SetString("proto", NextProtoToString(negotiated_protocol)); 148 dict->SetString("proto", NextProtoToString(negotiated_protocol));
148 return std::move(dict); 149 return std::move(dict);
149 } 150 }
150 151
151 // Returns parameters associated with the proxy resolution. 152 // Returns parameters associated with the proxy resolution.
152 std::unique_ptr<base::Value> NetLogHttpStreamJobProxyServerResolved( 153 std::unique_ptr<base::Value> NetLogHttpStreamJobProxyServerResolved(
153 const ProxyServer& proxy_server, 154 const ProxyServer& proxy_server,
154 NetLogCaptureMode /* capture_mode */) { 155 NetLogCaptureMode /* capture_mode */) {
155 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 156 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 } 1177 }
1177 1178
1178 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl( 1179 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl(
1179 base::WeakPtr<SpdySession> session, 1180 base::WeakPtr<SpdySession> session,
1180 bool direct) { 1181 bool direct) {
1181 // TODO(ricea): Restore the code for WebSockets over SPDY once it's 1182 // TODO(ricea): Restore the code for WebSockets over SPDY once it's
1182 // implemented. 1183 // implemented.
1183 if (delegate_->for_websockets()) 1184 if (delegate_->for_websockets())
1184 return ERR_NOT_IMPLEMENTED; 1185 return ERR_NOT_IMPLEMENTED;
1185 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 1186 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
1186 bidirectional_stream_impl_.reset( 1187 bidirectional_stream_impl_ = base::MakeUnique<BidirectionalStreamSpdyImpl>(
1187 new BidirectionalStreamSpdyImpl(session, net_log_.source())); 1188 session, net_log_.source());
1188 return OK; 1189 return OK;
1189 } 1190 }
1190 1191
1191 // TODO(willchan): Delete this code, because eventually, the 1192 // TODO(willchan): Delete this code, because eventually, the
1192 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1193 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1193 // will know when SpdySessions become available. 1194 // will know when SpdySessions become available.
1194 1195
1195 bool use_relative_url = 1196 bool use_relative_url =
1196 direct || request_info_.url.SchemeIs(url::kHttpsScheme); 1197 direct || request_info_.url.SchemeIs(url::kHttpsScheme);
1197 stream_.reset( 1198 stream_ = base::MakeUnique<SpdyHttpStream>(session, use_relative_url,
1198 new SpdyHttpStream(session, use_relative_url, net_log_.source())); 1199 net_log_.source());
1199 return OK; 1200 return OK;
1200 } 1201 }
1201 1202
1202 int HttpStreamFactoryImpl::Job::DoCreateStream() { 1203 int HttpStreamFactoryImpl::Job::DoCreateStream() {
1203 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed. 1204 // TODO(pkasting): Remove ScopedTracker below once crbug.com/462811 is fixed.
1204 tracked_objects::ScopedTracker tracking_profile( 1205 tracked_objects::ScopedTracker tracking_profile(
1205 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1206 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1206 "462811 HttpStreamFactoryImpl::Job::DoCreateStream")); 1207 "462811 HttpStreamFactoryImpl::Job::DoCreateStream"));
1207 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_); 1208 DCHECK(connection_->socket() || existing_spdy_session_.get() || using_quic_);
1208 DCHECK(!IsQuicAlternative()); 1209 DCHECK(!IsQuicAlternative());
(...skipping 19 matching lines...) Expand all
1228 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 1229 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
1229 (request_info_.url.SchemeIs(url::kHttpScheme) || 1230 (request_info_.url.SchemeIs(url::kHttpScheme) ||
1230 request_info_.url.SchemeIs(url::kFtpScheme)); 1231 request_info_.url.SchemeIs(url::kFtpScheme));
1231 if (delegate_->for_websockets()) { 1232 if (delegate_->for_websockets()) {
1232 DCHECK_NE(job_type_, PRECONNECT); 1233 DCHECK_NE(job_type_, PRECONNECT);
1233 DCHECK(delegate_->websocket_handshake_stream_create_helper()); 1234 DCHECK(delegate_->websocket_handshake_stream_create_helper());
1234 websocket_stream_ = 1235 websocket_stream_ =
1235 delegate_->websocket_handshake_stream_create_helper() 1236 delegate_->websocket_handshake_stream_create_helper()
1236 ->CreateBasicStream(std::move(connection_), using_proxy); 1237 ->CreateBasicStream(std::move(connection_), using_proxy);
1237 } else { 1238 } else {
1238 stream_.reset(new HttpBasicStream( 1239 stream_ = base::MakeUnique<HttpBasicStream>(
1239 std::move(connection_), using_proxy, 1240 std::move(connection_), using_proxy,
1240 session_->params().http_09_on_non_default_ports_enabled)); 1241 session_->params().http_09_on_non_default_ports_enabled);
1241 } 1242 }
1242 return OK; 1243 return OK;
1243 } 1244 }
1244 1245
1245 CHECK(!stream_.get()); 1246 CHECK(!stream_.get());
1246 1247
1247 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1248 SpdySessionKey spdy_session_key = GetSpdySessionKey();
1248 if (!existing_spdy_session_) { 1249 if (!existing_spdy_session_) {
1249 existing_spdy_session_ = 1250 existing_spdy_session_ =
1250 session_->spdy_session_pool()->FindAvailableSession( 1251 session_->spdy_session_pool()->FindAvailableSession(
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 1558
1558 ConnectionAttempts socket_attempts = connection_->connection_attempts(); 1559 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1559 if (connection_->socket()) { 1560 if (connection_->socket()) {
1560 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1561 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1561 } 1562 }
1562 1563
1563 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); 1564 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts);
1564 } 1565 }
1565 1566
1566 } // namespace net 1567 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698