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

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: sync 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 *host_resolver = net::HostResolver::CreateSystemResolver(
147 kMaxJobs, 147 kMaxJobs,
148 kMaxRetryAttempts, 148 kMaxRetryAttempts,
149 false /* use_cache */,
150 false /* use_async */,
149 NULL /* NetLog */); 151 NULL /* NetLog */);
150 152
151 host_resolver->reset(impl);
152
153 // Modify it slightly based on the experiment being run. 153 // Modify it slightly based on the experiment being run.
154 switch (experiment) { 154 switch (experiment) {
155 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_PLAIN: 155 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_PLAIN:
156 return net::OK; 156 return net::OK;
157 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_DISABLE_IPV6: 157 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_DISABLE_IPV6:
158 impl->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); 158 (*host_resolver)->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4);
159 return net::OK; 159 return net::OK;
160 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_IPV6_PROBE: { 160 case ConnectionTester::HOST_RESOLVER_EXPERIMENT_IPV6_PROBE: {
161 // Note that we don't use impl->ProbeIPv6Support() since that finishes 161 // Note that we don't use impl->ProbeIPv6Support() since that finishes
162 // asynchronously and may not take effect in time for the test. 162 // asynchronously and may not take effect in time for the test.
163 // So instead we will probe synchronously (might take 100-200 ms). 163 // So instead we will probe synchronously (might take 100-200 ms).
164 net::AddressFamily family = net::TestIPv6Support().ipv6_supported ? 164 net::AddressFamily family = net::TestIPv6Support().ipv6_supported ?
165 net::ADDRESS_FAMILY_UNSPECIFIED : net::ADDRESS_FAMILY_IPV4; 165 net::ADDRESS_FAMILY_UNSPECIFIED : net::ADDRESS_FAMILY_IPV4;
166 impl->SetDefaultAddressFamily(family); 166 (*host_resolver)->SetDefaultAddressFamily(family);
167 return net::OK; 167 return net::OK;
168 } 168 }
169 default: 169 default:
170 NOTREACHED(); 170 NOTREACHED();
171 return net::ERR_UNEXPECTED; 171 return net::ERR_UNEXPECTED;
darin (slow to review) 2012/10/09 17:38:34 It looks like it is possible for this function to
szym 2012/10/09 21:40:43 Done.
172 } 172 }
173 } 173 }
174 174
175 // Creates a proxy service for |experiment|. On success returns net::OK 175 // Creates a proxy service for |experiment|. On success returns net::OK
176 // and fills |experiment_proxy_service| with a new pointer. Otherwise returns 176 // and fills |experiment_proxy_service| with a new pointer. Otherwise returns
177 // a network error code. 177 // a network error code.
178 int CreateProxyService( 178 int CreateProxyService(
179 ConnectionTester::ProxySettingsExperiment experiment, 179 ConnectionTester::ProxySettingsExperiment experiment,
180 scoped_ptr<net::ProxyConfigService>* proxy_config_service, 180 scoped_ptr<net::ProxyConfigService>* proxy_config_service,
181 scoped_ptr<net::ProxyService>* experiment_proxy_service) { 181 scoped_ptr<net::ProxyService>* experiment_proxy_service) {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 524
525 // Notify the delegate of completion. 525 // Notify the delegate of completion.
526 delegate_->OnCompletedConnectionTestExperiment(current, result); 526 delegate_->OnCompletedConnectionTestExperiment(current, result);
527 527
528 if (remaining_experiments_.empty()) { 528 if (remaining_experiments_.empty()) {
529 delegate_->OnCompletedConnectionTestSuite(); 529 delegate_->OnCompletedConnectionTestSuite();
530 } else { 530 } else {
531 StartNextExperiment(); 531 StartNextExperiment();
532 } 532 }
533 } 533 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698