OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 // A version number for prefs that are saved. This should be incremented when | 76 // A version number for prefs that are saved. This should be incremented when |
77 // we change the format so that we discard old data. | 77 // we change the format so that we discard old data. |
78 static const int kPredictorStartupFormatVersion = 1; | 78 static const int kPredictorStartupFormatVersion = 1; |
79 | 79 |
80 class Predictor::LookupRequest { | 80 class Predictor::LookupRequest { |
81 public: | 81 public: |
82 LookupRequest(Predictor* predictor, | 82 LookupRequest(Predictor* predictor, |
83 net::HostResolver* host_resolver, | 83 net::HostResolver* host_resolver, |
84 const GURL& url) | 84 const GURL& url) |
85 : ALLOW_THIS_IN_INITIALIZER_LIST( | 85 : predictor_(predictor), |
86 net_callback_(this, &LookupRequest::OnLookupFinished)), | |
87 predictor_(predictor), | |
88 url_(url), | 86 url_(url), |
89 resolver_(host_resolver) { | 87 resolver_(host_resolver) { |
90 } | 88 } |
91 | 89 |
92 // Return underlying network resolver status. | 90 // Return underlying network resolver status. |
93 // net::OK ==> Host was found synchronously. | 91 // net::OK ==> Host was found synchronously. |
94 // net:ERR_IO_PENDING ==> Network will callback later with result. | 92 // net:ERR_IO_PENDING ==> Network will callback later with result. |
95 // anything else ==> Host was not found synchronously. | 93 // anything else ==> Host was not found synchronously. |
96 int Start() { | 94 int Start() { |
97 net::HostResolver::RequestInfo resolve_info( | 95 net::HostResolver::RequestInfo resolve_info( |
98 net::HostPortPair::FromURL(url_)); | 96 net::HostPortPair::FromURL(url_)); |
99 | 97 |
100 // Make a note that this is a speculative resolve request. This allows us | 98 // Make a note that this is a speculative resolve request. This allows us |
101 // to separate it from real navigations in the observer's callback, and | 99 // to separate it from real navigations in the observer's callback, and |
102 // lets the HostResolver know it can de-prioritize it. | 100 // lets the HostResolver know it can de-prioritize it. |
103 resolve_info.set_is_speculative(true); | 101 resolve_info.set_is_speculative(true); |
104 return resolver_.Resolve( | 102 return resolver_.Resolve( |
105 resolve_info, &addresses_, &net_callback_, net::BoundNetLog()); | 103 resolve_info, &addresses_, |
| 104 base::Bind(&LookupRequest::OnLookupFinished, base::Unretained(this)), |
| 105 net::BoundNetLog()); |
106 } | 106 } |
107 | 107 |
108 private: | 108 private: |
109 void OnLookupFinished(int result) { | 109 void OnLookupFinished(int result) { |
110 predictor_->OnLookupFinished(this, url_, result == net::OK); | 110 predictor_->OnLookupFinished(this, url_, result == net::OK); |
111 } | 111 } |
112 | 112 |
113 // HostResolver will call us using this callback when resolution is complete. | |
114 net::OldCompletionCallbackImpl<LookupRequest> net_callback_; | |
115 | |
116 Predictor* predictor_; // The predictor which started us. | 113 Predictor* predictor_; // The predictor which started us. |
117 | 114 |
118 const GURL url_; // Hostname to resolve. | 115 const GURL url_; // Hostname to resolve. |
119 net::SingleRequestHostResolver resolver_; | 116 net::SingleRequestHostResolver resolver_; |
120 net::AddressList addresses_; | 117 net::AddressList addresses_; |
121 | 118 |
122 DISALLOW_COPY_AND_ASSIGN(LookupRequest); | 119 DISALLOW_COPY_AND_ASSIGN(LookupRequest); |
123 }; | 120 }; |
124 | 121 |
125 Predictor::Predictor(bool preconnect_enabled) | 122 Predictor::Predictor(bool preconnect_enabled) |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 PrefService* local_state, | 1204 PrefService* local_state, |
1208 IOThread* io_thread) { | 1205 IOThread* io_thread) { |
1209 // Empty function for unittests. | 1206 // Empty function for unittests. |
1210 } | 1207 } |
1211 | 1208 |
1212 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { | 1209 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { |
1213 SetShutdown(true); | 1210 SetShutdown(true); |
1214 } | 1211 } |
1215 | 1212 |
1216 } // namespace chrome_browser_net | 1213 } // namespace chrome_browser_net |
OLD | NEW |