| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/dns_global.h" | 5 #include "chrome/browser/net/predictor_api.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| 11 #include "base/stats_counters.h" | 11 #include "base/stats_counters.h" |
| 12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/thread.h" | 14 #include "base/thread.h" |
| 15 #include "base/waitable_event.h" | 15 #include "base/waitable_event.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/browser.h" | 17 #include "chrome/browser/browser.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_thread.h" | 19 #include "chrome/browser/chrome_thread.h" |
| 20 #include "chrome/browser/io_thread.h" | 20 #include "chrome/browser/io_thread.h" |
| 21 #include "chrome/browser/net/dns_host_info.h" | 21 #include "chrome/browser/net/url_info.h" |
| 22 #include "chrome/browser/net/preconnect.h" | 22 #include "chrome/browser/net/preconnect.h" |
| 23 #include "chrome/browser/net/referrer.h" | 23 #include "chrome/browser/net/referrer.h" |
| 24 #include "chrome/browser/pref_service.h" | 24 #include "chrome/browser/pref_service.h" |
| 25 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
| 26 #include "chrome/browser/session_startup_pref.h" | 26 #include "chrome/browser/session_startup_pref.h" |
| 27 #include "chrome/common/notification_registrar.h" | 27 #include "chrome/common/notification_registrar.h" |
| 28 #include "chrome/common/notification_service.h" | 28 #include "chrome/common/notification_service.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "net/base/host_resolver.h" | 30 #include "net/base/host_resolver.h" |
| 31 #include "net/base/host_resolver_impl.h" | 31 #include "net/base/host_resolver_impl.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 299 |
| 300 //------------------------------------------------------------------------------ | 300 //------------------------------------------------------------------------------ |
| 301 // Member definitions for above Observer class. | 301 // Member definitions for above Observer class. |
| 302 | 302 |
| 303 void PrefetchObserver::OnStartResolution( | 303 void PrefetchObserver::OnStartResolution( |
| 304 int request_id, | 304 int request_id, |
| 305 const net::HostResolver::RequestInfo& request_info) { | 305 const net::HostResolver::RequestInfo& request_info) { |
| 306 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 306 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 307 if (request_info.is_speculative()) | 307 if (request_info.is_speculative()) |
| 308 return; // One of our own requests. | 308 return; // One of our own requests. |
| 309 DCHECK_NE(0U, request_info.hostname().length()); | 309 if (!request_info.hostname().length()) |
| 310 return; // PAC scripts may create queries without a hostname. |
| 310 | 311 |
| 311 UrlInfo navigation_info; | 312 UrlInfo navigation_info; |
| 312 // TODO(jar): Remove hack which guestimates ssl via port number, and perhaps | 313 // TODO(jar): Remove hack which guestimates ssl via port number, and perhaps |
| 313 // have actual URL passed down in request_info instead. | 314 // have actual URL passed down in request_info instead. |
| 314 bool is_ssl(443 == request_info.port()); | 315 bool is_ssl(443 == request_info.port()); |
| 315 std::string url_spec = is_ssl ? "https://" : "http://"; | 316 std::string url_spec = is_ssl ? "https://" : "http://"; |
| 316 url_spec += request_info.hostname(); | 317 url_spec += request_info.hostname(); |
| 317 url_spec += ":"; | 318 url_spec += ":"; |
| 318 url_spec += IntToString(request_info.port()); | 319 url_spec += IntToString(request_info.port()); |
| 319 navigation_info.SetUrl(GURL(url_spec)); | 320 navigation_info.SetUrl(GURL(url_spec)); |
| 320 navigation_info.SetStartedState(); | 321 navigation_info.SetStartedState(); |
| 321 | 322 |
| 322 // This entry will be deleted either by OnFinishResolutionWithStatus(), or | 323 // This entry will be deleted either by OnFinishResolutionWithStatus(), or |
| 323 // by OnCancelResolution(). | 324 // by OnCancelResolution(). |
| 324 resolutions_[request_id] = navigation_info; | 325 resolutions_[request_id] = navigation_info; |
| 325 } | 326 } |
| 326 | 327 |
| 327 void PrefetchObserver::OnFinishResolutionWithStatus( | 328 void PrefetchObserver::OnFinishResolutionWithStatus( |
| 328 int request_id, | 329 int request_id, |
| 329 bool was_resolved, | 330 bool was_resolved, |
| 330 const net::HostResolver::RequestInfo& request_info) { | 331 const net::HostResolver::RequestInfo& request_info) { |
| 331 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 332 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 332 if (request_info.is_speculative()) | 333 if (request_info.is_speculative()) |
| 333 return; // One of our own requests. | 334 return; // One of our own requests. |
| 335 if (!request_info.hostname().length()) |
| 336 return; // PAC scripts may create queries without a hostname. |
| 334 UrlInfo navigation_info; | 337 UrlInfo navigation_info; |
| 335 size_t startup_count = 0; | 338 size_t startup_count = 0; |
| 336 { | 339 { |
| 337 ObservedResolutionMap::iterator it = resolutions_.find(request_id); | 340 ObservedResolutionMap::iterator it = resolutions_.find(request_id); |
| 338 if (resolutions_.end() == it) { | 341 if (resolutions_.end() == it) { |
| 339 NOTREACHED(); | 342 NOTREACHED(); |
| 340 return; | 343 return; |
| 341 } | 344 } |
| 342 navigation_info = it->second; | 345 navigation_info = it->second; |
| 343 resolutions_.erase(it); | 346 resolutions_.erase(it); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 363 // page load (once we start to persist elements of our referrer tree). | 366 // page load (once we start to persist elements of our referrer tree). |
| 364 StartupListAppend(navigation_info); | 367 StartupListAppend(navigation_info); |
| 365 } | 368 } |
| 366 | 369 |
| 367 void PrefetchObserver::OnCancelResolution( | 370 void PrefetchObserver::OnCancelResolution( |
| 368 int request_id, | 371 int request_id, |
| 369 const net::HostResolver::RequestInfo& request_info) { | 372 const net::HostResolver::RequestInfo& request_info) { |
| 370 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 373 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 371 if (request_info.is_speculative()) | 374 if (request_info.is_speculative()) |
| 372 return; // One of our own requests. | 375 return; // One of our own requests. |
| 376 if (!request_info.hostname().length()) |
| 377 return; // PAC scripts may create queries without a hostname. |
| 373 | 378 |
| 374 // Remove the entry from |resolutions| that was added by OnStartResolution(). | 379 // Remove the entry from |resolutions| that was added by OnStartResolution(). |
| 375 ObservedResolutionMap::iterator it = resolutions_.find(request_id); | 380 ObservedResolutionMap::iterator it = resolutions_.find(request_id); |
| 376 if (resolutions_.end() == it) { | 381 if (resolutions_.end() == it) { |
| 377 NOTREACHED(); | 382 NOTREACHED(); |
| 378 return; | 383 return; |
| 379 } | 384 } |
| 380 resolutions_.erase(it); | 385 resolutions_.erase(it); |
| 381 } | 386 } |
| 382 | 387 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 TimeDelta::FromMilliseconds(max_queueing_delay_ms)); | 747 TimeDelta::FromMilliseconds(max_queueing_delay_ms)); |
| 743 | 748 |
| 744 DCHECK(!predictor); | 749 DCHECK(!predictor); |
| 745 InitNetworkPredictor(max_queueing_delay, max_concurrent, user_prefs, | 750 InitNetworkPredictor(max_queueing_delay, max_concurrent, user_prefs, |
| 746 local_state, preconnect_enabled); | 751 local_state, preconnect_enabled); |
| 747 } | 752 } |
| 748 } | 753 } |
| 749 | 754 |
| 750 | 755 |
| 751 } // namespace chrome_browser_net | 756 } // namespace chrome_browser_net |
| OLD | NEW |