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

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

Issue 10796112: Use a NetLog for test requests sent by about:net-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Last CL removed wrong line break. :( Created 8 years, 4 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 config_service->reset(new net::ProxyConfigServiceFixed( 76 config_service->reset(new net::ProxyConfigServiceFixed(
77 net::ProxyConfig::CreateDirect())); 77 net::ProxyConfig::CreateDirect()));
78 return net::OK; 78 return net::OK;
79 default: 79 default:
80 NOTREACHED(); 80 NOTREACHED();
81 return net::ERR_UNEXPECTED; 81 return net::ERR_UNEXPECTED;
82 } 82 }
83 } 83 }
84 84
85 int Init(const ConnectionTester::Experiment& experiment, 85 int Init(const ConnectionTester::Experiment& experiment,
86 scoped_ptr<net::ProxyConfigService>* proxy_config_service) { 86 scoped_ptr<net::ProxyConfigService>* proxy_config_service,
87 net::NetLog* net_log) {
87 int rv; 88 int rv;
88 89
89 // Create a custom HostResolver for this experiment. 90 // Create a custom HostResolver for this experiment.
90 scoped_ptr<net::HostResolver> host_resolver_tmp; 91 scoped_ptr<net::HostResolver> host_resolver_tmp;
91 rv = CreateHostResolver(experiment.host_resolver_experiment, 92 rv = CreateHostResolver(experiment.host_resolver_experiment,
92 &host_resolver_tmp); 93 &host_resolver_tmp);
93 if (rv != net::OK) 94 if (rv != net::OK)
94 return rv; // Failure. 95 return rv; // Failure.
95 storage_.set_host_resolver(host_resolver_tmp.release()); 96 storage_.set_host_resolver(host_resolver_tmp.release());
96 97
(...skipping 12 matching lines...) Expand all
109 new net::FtpNetworkLayer(host_resolver())); 110 new net::FtpNetworkLayer(host_resolver()));
110 storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults); 111 storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults);
111 storage_.set_http_auth_handler_factory( 112 storage_.set_http_auth_handler_factory(
112 net::HttpAuthHandlerFactory::CreateDefault(host_resolver())); 113 net::HttpAuthHandlerFactory::CreateDefault(host_resolver()));
113 storage_.set_http_server_properties(new net::HttpServerPropertiesImpl); 114 storage_.set_http_server_properties(new net::HttpServerPropertiesImpl);
114 115
115 net::HttpNetworkSession::Params session_params; 116 net::HttpNetworkSession::Params session_params;
116 session_params.host_resolver = host_resolver(); 117 session_params.host_resolver = host_resolver();
117 session_params.cert_verifier = cert_verifier(); 118 session_params.cert_verifier = cert_verifier();
118 session_params.proxy_service = proxy_service(); 119 session_params.proxy_service = proxy_service();
120 session_params.ssl_config_service = ssl_config_service();
119 session_params.http_auth_handler_factory = http_auth_handler_factory(); 121 session_params.http_auth_handler_factory = http_auth_handler_factory();
120 session_params.http_server_properties = http_server_properties(); 122 session_params.http_server_properties = http_server_properties();
121 session_params.ssl_config_service = ssl_config_service(); 123 session_params.net_log = net_log;
122 scoped_refptr<net::HttpNetworkSession> network_session( 124 scoped_refptr<net::HttpNetworkSession> network_session(
123 new net::HttpNetworkSession(session_params)); 125 new net::HttpNetworkSession(session_params));
124 storage_.set_http_transaction_factory(new net::HttpCache( 126 storage_.set_http_transaction_factory(new net::HttpCache(
125 network_session, 127 network_session,
126 net::HttpCache::DefaultBackend::InMemory(0))); 128 net::HttpCache::DefaultBackend::InMemory(0)));
127 // In-memory cookie store. 129 // In-memory cookie store.
128 storage_.set_cookie_store(new net::CookieMonster(NULL, NULL)); 130 storage_.set_cookie_store(new net::CookieMonster(NULL, NULL));
129 131
130 return net::OK; 132 return net::OK;
131 } 133 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } // namespace 283 } // namespace
282 284
283 // ConnectionTester::TestRunner ---------------------------------------------- 285 // ConnectionTester::TestRunner ----------------------------------------------
284 286
285 // TestRunner is a helper class for running an individual experiment. It can 287 // TestRunner is a helper class for running an individual experiment. It can
286 // be deleted any time after it is started, and this will abort the request. 288 // be deleted any time after it is started, and this will abort the request.
287 class ConnectionTester::TestRunner : public net::URLRequest::Delegate { 289 class ConnectionTester::TestRunner : public net::URLRequest::Delegate {
288 public: 290 public:
289 // |tester| must remain alive throughout the TestRunner's lifetime. 291 // |tester| must remain alive throughout the TestRunner's lifetime.
290 // |tester| will be notified of completion. 292 // |tester| will be notified of completion.
291 explicit TestRunner(ConnectionTester* tester) 293 TestRunner(ConnectionTester* tester, net::NetLog* net_log)
292 : tester_(tester), 294 : tester_(tester),
295 net_log_(net_log),
293 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {} 296 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
294 297
295 // Finish running |experiment| once a ProxyConfigService has been created. 298 // Finish running |experiment| once a ProxyConfigService has been created.
296 // In the case of a FirefoxProxyConfigService, this will be called back 299 // In the case of a FirefoxProxyConfigService, this will be called back
297 // after disk access has completed. 300 // after disk access has completed.
298 void ProxyConfigServiceCreated( 301 void ProxyConfigServiceCreated(
299 const Experiment& experiment, 302 const Experiment& experiment,
300 scoped_ptr<net::ProxyConfigService>* proxy_config_service, int status); 303 scoped_ptr<net::ProxyConfigService>* proxy_config_service, int status);
301 304
302 // Starts running |experiment|. Notifies tester->OnExperimentCompleted() when 305 // Starts running |experiment|. Notifies tester->OnExperimentCompleted() when
(...skipping 13 matching lines...) Expand all
316 // end of stream). 319 // end of stream).
317 void ReadBody(net::URLRequest* request); 320 void ReadBody(net::URLRequest* request);
318 321
319 // Called when the request has completed (for both success and failure). 322 // Called when the request has completed (for both success and failure).
320 void OnResponseCompleted(net::URLRequest* request); 323 void OnResponseCompleted(net::URLRequest* request);
321 void OnExperimentCompletedWithResult(int result); 324 void OnExperimentCompletedWithResult(int result);
322 325
323 ConnectionTester* tester_; 326 ConnectionTester* tester_;
324 scoped_ptr<ExperimentURLRequestContext> request_context_; 327 scoped_ptr<ExperimentURLRequestContext> request_context_;
325 scoped_ptr<net::URLRequest> request_; 328 scoped_ptr<net::URLRequest> request_;
329 net::NetLog* net_log_;
326 330
327 base::WeakPtrFactory<TestRunner> weak_factory_; 331 base::WeakPtrFactory<TestRunner> weak_factory_;
328 332
329 DISALLOW_COPY_AND_ASSIGN(TestRunner); 333 DISALLOW_COPY_AND_ASSIGN(TestRunner);
330 }; 334 };
331 335
332 void ConnectionTester::TestRunner::OnResponseStarted(net::URLRequest* request) { 336 void ConnectionTester::TestRunner::OnResponseStarted(net::URLRequest* request) {
333 if (!request->status().is_success()) { 337 if (!request->status().is_success()) {
334 OnResponseCompleted(request); 338 OnResponseCompleted(request);
335 return; 339 return;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 386
383 void ConnectionTester::TestRunner::OnExperimentCompletedWithResult(int result) { 387 void ConnectionTester::TestRunner::OnExperimentCompletedWithResult(int result) {
384 tester_->OnExperimentCompleted(result); 388 tester_->OnExperimentCompleted(result);
385 } 389 }
386 390
387 void ConnectionTester::TestRunner::ProxyConfigServiceCreated( 391 void ConnectionTester::TestRunner::ProxyConfigServiceCreated(
388 const Experiment& experiment, 392 const Experiment& experiment,
389 scoped_ptr<net::ProxyConfigService>* proxy_config_service, 393 scoped_ptr<net::ProxyConfigService>* proxy_config_service,
390 int status) { 394 int status) {
391 if (status == net::OK) 395 if (status == net::OK)
392 status = request_context_->Init(experiment, proxy_config_service); 396 status = request_context_->Init(experiment,
397 proxy_config_service,
398 net_log_);
393 if (status != net::OK) { 399 if (status != net::OK) {
394 tester_->OnExperimentCompleted(status); 400 tester_->OnExperimentCompleted(status);
395 return; 401 return;
396 } 402 }
397 // Fetch a request using the experimental context. 403 // Fetch a request using the experimental context.
398 request_.reset(new net::URLRequest(experiment.url, 404 request_.reset(new net::URLRequest(experiment.url,
399 this, 405 this,
400 request_context_.get())); 406 request_context_.get()));
401 request_->Start(); 407 request_->Start();
402 } 408 }
(...skipping 12 matching lines...) Expand all
415 experiment.proxy_settings_experiment, 421 experiment.proxy_settings_experiment,
416 proxy_config_service, config_service_callback); 422 proxy_config_service, config_service_callback);
417 if (rv != net::ERR_IO_PENDING) 423 if (rv != net::ERR_IO_PENDING)
418 ProxyConfigServiceCreated(experiment, proxy_config_service, rv); 424 ProxyConfigServiceCreated(experiment, proxy_config_service, rv);
419 } 425 }
420 426
421 // ConnectionTester ---------------------------------------------------------- 427 // ConnectionTester ----------------------------------------------------------
422 428
423 ConnectionTester::ConnectionTester( 429 ConnectionTester::ConnectionTester(
424 Delegate* delegate, 430 Delegate* delegate,
425 net::URLRequestContext* proxy_request_context) 431 net::URLRequestContext* proxy_request_context,
426 : delegate_(delegate), proxy_request_context_(proxy_request_context) { 432 net::NetLog* net_log)
433 : delegate_(delegate),
434 proxy_request_context_(proxy_request_context),
435 net_log_(net_log) {
427 DCHECK(delegate); 436 DCHECK(delegate);
428 DCHECK(proxy_request_context); 437 DCHECK(proxy_request_context);
429 } 438 }
430 439
431 ConnectionTester::~ConnectionTester() { 440 ConnectionTester::~ConnectionTester() {
432 // Cancellation happens automatically by deleting test_runner_. 441 // Cancellation happens automatically by deleting test_runner_.
433 } 442 }
434 443
435 void ConnectionTester::RunAllTests(const GURL& url) { 444 void ConnectionTester::RunAllTests(const GURL& url) {
436 // Select all possible experiments to run. (In no particular order). 445 // Select all possible experiments to run. (In no particular order).
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 505 }
497 } 506 }
498 } 507 }
499 508
500 void ConnectionTester::StartNextExperiment() { 509 void ConnectionTester::StartNextExperiment() {
501 DCHECK(!remaining_experiments_.empty()); 510 DCHECK(!remaining_experiments_.empty());
502 DCHECK(!current_test_runner_.get()); 511 DCHECK(!current_test_runner_.get());
503 512
504 delegate_->OnStartConnectionTestExperiment(current_experiment()); 513 delegate_->OnStartConnectionTestExperiment(current_experiment());
505 514
506 current_test_runner_.reset(new TestRunner(this)); 515 current_test_runner_.reset(new TestRunner(this, net_log_));
507 current_test_runner_->Run(current_experiment()); 516 current_test_runner_->Run(current_experiment());
508 } 517 }
509 518
510 void ConnectionTester::OnExperimentCompleted(int result) { 519 void ConnectionTester::OnExperimentCompleted(int result) {
511 Experiment current = current_experiment(); 520 Experiment current = current_experiment();
512 521
513 // Advance to the next experiment. 522 // Advance to the next experiment.
514 remaining_experiments_.erase(remaining_experiments_.begin()); 523 remaining_experiments_.erase(remaining_experiments_.begin());
515 current_test_runner_.reset(); 524 current_test_runner_.reset();
516 525
517 // Notify the delegate of completion. 526 // Notify the delegate of completion.
518 delegate_->OnCompletedConnectionTestExperiment(current, result); 527 delegate_->OnCompletedConnectionTestExperiment(current, result);
519 528
520 if (remaining_experiments_.empty()) { 529 if (remaining_experiments_.empty()) {
521 delegate_->OnCompletedConnectionTestSuite(); 530 delegate_->OnCompletedConnectionTestSuite();
522 } else { 531 } else {
523 StartNextExperiment(); 532 StartNextExperiment();
524 } 533 }
525 } 534 }
OLDNEW
« no previous file with comments | « chrome/browser/net/connection_tester.h ('k') | chrome/browser/net/connection_tester_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698