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

Side by Side Diff: chrome/browser/net/connection_tester.cc

Issue 10831277: [net] Change factory methods for HostResolver and HostCache to return a scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use default scoped_ptr() instead of scoped_ptr(NULL) Created 8 years, 2 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 | Annotate | Revision Log
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 "chrome/browser/net/connection_tester.h" 5 #include "chrome/browser/net/connection_tester.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 scoped_ptr<net::ProxyConfigService>* proxy_config_service, 87 scoped_ptr<net::ProxyConfigService>* proxy_config_service,
88 net::NetLog* net_log) { 88 net::NetLog* net_log) {
89 int rv; 89 int rv;
90 90
91 // Create a custom HostResolver for this experiment. 91 // Create a custom HostResolver for this experiment.
92 scoped_ptr<net::HostResolver> host_resolver_tmp; 92 scoped_ptr<net::HostResolver> host_resolver_tmp;
93 rv = CreateHostResolver(experiment.host_resolver_experiment, 93 rv = CreateHostResolver(experiment.host_resolver_experiment,
94 &host_resolver_tmp); 94 &host_resolver_tmp);
95 if (rv != net::OK) 95 if (rv != net::OK)
96 return rv; // Failure. 96 return rv; // Failure.
97 storage_.set_host_resolver(host_resolver_tmp.release()); 97 storage_.set_host_resolver(host_resolver_tmp.Pass());
98 98
99 // Create a custom ProxyService for this this experiment. 99 // Create a custom ProxyService for this this experiment.
100 scoped_ptr<net::ProxyService> experiment_proxy_service; 100 scoped_ptr<net::ProxyService> experiment_proxy_service;
101 rv = CreateProxyService(experiment.proxy_settings_experiment, 101 rv = CreateProxyService(experiment.proxy_settings_experiment,
102 proxy_config_service, &experiment_proxy_service); 102 proxy_config_service, &experiment_proxy_service);
103 if (rv != net::OK) 103 if (rv != net::OK)
104 return rv; // Failure. 104 return rv; // Failure.
105 storage_.set_proxy_service(experiment_proxy_service.release()); 105 storage_.set_proxy_service(experiment_proxy_service.release());
106 106
107 // The rest of the dependencies are standard, and don't depend on the 107 // The rest of the dependencies are standard, and don't depend on the
(...skipping 28 matching lines...) Expand all
136 private: 136 private:
137 // Creates a host resolver for |experiment|. On success returns net::OK and 137 // Creates a host resolver for |experiment|. On success returns net::OK and
138 // fills |host_resolver| with a new pointer. Otherwise returns a network 138 // fills |host_resolver| with a new pointer. Otherwise returns a network
139 // error code. 139 // error code.
140 int CreateHostResolver( 140 int CreateHostResolver(
141 ConnectionTester::HostResolverExperiment experiment, 141 ConnectionTester::HostResolverExperiment experiment,
142 scoped_ptr<net::HostResolver>* host_resolver) { 142 scoped_ptr<net::HostResolver>* host_resolver) {
143 // Create a vanilla HostResolver that disables caching. 143 // Create a vanilla HostResolver that disables caching.
144 const size_t kMaxJobs = 50u; 144 const size_t kMaxJobs = 50u;
145 const size_t kMaxRetryAttempts = 4u; 145 const size_t kMaxRetryAttempts = 4u;
146 net::HostResolver* impl = net::CreateNonCachingSystemHostResolver( 146 net::HostResolver::Options options;
147 kMaxJobs, 147 options.max_concurrent_resolves = kMaxJobs;
148 kMaxRetryAttempts, 148 options.max_retry_attempts = kMaxRetryAttempts;
149 NULL /* NetLog */); 149 options.enable_caching = false;
150 150 options.enable_async = false;
151 host_resolver->reset(impl); 151 scoped_ptr<net::HostResolver> resolver(
152 net::HostResolver::CreateSystemResolver(options, NULL /* NetLog */));
152 153
153 // Modify it slightly based on the experiment being run. 154 // Modify it slightly based on the experiment being run.
154 switch (experiment) { 155 switch (experiment) {
155 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_PLAIN: 156 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_PLAIN:
156 return net::OK; 157 break;
157 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_DISABLE_IPV6: 158 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_DISABLE_IPV6:
158 impl->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); 159 resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
159 return net::OK; 160 break;
160 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_IPV6_PROBE: { 161 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_IPV6_PROBE: {
161 // Note that we don't use impl->ProbeIPv6Support() since that finishes 162 // Note that we don't use impl->ProbeIPv6Support() since that finishes
162 // asynchronously and may not take effect in time for the test. 163 // asynchronously and may not take effect in time for the test.
163 // So instead we will probe synchronously (might take 100-200 ms). 164 // So instead we will probe synchronously (might take 100-200 ms).
164 net::AddressFamily family = net::TestIPv6Support().ipv6_supported ? 165 net::AddressFamily family = net::TestIPv6Support().ipv6_supported ?
165 net::ADDRESS_FAMILY_UNSPECIFIED : net::ADDRESS_FAMILY_IPV4; 166 net::ADDRESS_FAMILY_UNSPECIFIED : net::ADDRESS_FAMILY_IPV4;
166 impl->SetDefaultAddressFamily(family); 167 resolver->SetDefaultAddressFamily(family);
167 return net::OK; 168 break;
168 } 169 }
169 default: 170 default:
170 NOTREACHED(); 171 NOTREACHED();
171 return net::ERR_UNEXPECTED; 172 return net::ERR_UNEXPECTED;
172 } 173 }
174 (*host_resolver).swap(resolver);
darin (slow to review) 2012/10/22 17:27:17 host_resolver->swap(resolver);
szym 2012/10/22 17:48:43 Done.
175 return net::OK;
173 } 176 }
174 177
175 // Creates a proxy service for |experiment|. On success returns net::OK 178 // Creates a proxy service for |experiment|. On success returns net::OK
176 // and fills |experiment_proxy_service| with a new pointer. Otherwise returns 179 // and fills |experiment_proxy_service| with a new pointer. Otherwise returns
177 // a network error code. 180 // a network error code.
178 int CreateProxyService( 181 int CreateProxyService(
179 ConnectionTester::ProxySettingsExperiment experiment, 182 ConnectionTester::ProxySettingsExperiment experiment,
180 scoped_ptr<net::ProxyConfigService>* proxy_config_service, 183 scoped_ptr<net::ProxyConfigService>* proxy_config_service,
181 scoped_ptr<net::ProxyService>* experiment_proxy_service) { 184 scoped_ptr<net::ProxyService>* experiment_proxy_service) {
182 if (CommandLine::ForCurrentProcess()->HasSwitch( 185 if (CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 527
525 // Notify the delegate of completion. 528 // Notify the delegate of completion.
526 delegate_->OnCompletedConnectionTestExperiment(current, result); 529 delegate_->OnCompletedConnectionTestExperiment(current, result);
527 530
528 if (remaining_experiments_.empty()) { 531 if (remaining_experiments_.empty()) {
529 delegate_->OnCompletedConnectionTestSuite(); 532 delegate_->OnCompletedConnectionTestSuite();
530 } else { 533 } else {
531 StartNextExperiment(); 534 StartNextExperiment();
532 } 535 }
533 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698