OLD | NEW |
---|---|
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/prerender/prerender_local_predictor.h" | 5 #include "chrome/browser/prerender/prerender_local_predictor.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "chrome/browser/history/history_database.h" | 18 #include "chrome/browser/history/history_database.h" |
19 #include "chrome/browser/history/history_db_task.h" | 19 #include "chrome/browser/history/history_db_task.h" |
20 #include "chrome/browser/history/history_service.h" | 20 #include "chrome/browser/history/history_service.h" |
21 #include "chrome/browser/history/history_service_factory.h" | 21 #include "chrome/browser/history/history_service_factory.h" |
22 #include "chrome/browser/prerender/prerender_handle.h" | |
22 #include "chrome/browser/prerender/prerender_histograms.h" | 23 #include "chrome/browser/prerender/prerender_histograms.h" |
23 #include "chrome/browser/prerender/prerender_manager.h" | 24 #include "chrome/browser/prerender/prerender_manager.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | |
25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/navigation_controller.h" | |
29 #include "content/public/browser/session_storage_namespace.h" | |
30 #include "content/public/browser/web_contents.h" | |
31 #include "content/public/browser/web_contents_view.h" | |
26 #include "content/public/common/page_transition_types.h" | 32 #include "content/public/common/page_transition_types.h" |
27 #include "crypto/secure_hash.h" | 33 #include "crypto/secure_hash.h" |
34 #include "googleurl/src/url_canon.h" | |
28 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
29 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
30 | 37 |
31 using content::BrowserThread; | 38 using content::BrowserThread; |
32 using content::PageTransition; | 39 using content::PageTransition; |
40 using content::SessionStorageNamespace; | |
41 using content::WebContents; | |
33 using history::URLID; | 42 using history::URLID; |
43 using predictors::LoggedInPredictorTable; | |
44 using std::string; | |
45 using std::vector; | |
34 | 46 |
35 namespace prerender { | 47 namespace prerender { |
36 | 48 |
37 namespace { | 49 namespace { |
38 | 50 |
39 static const size_t kURLHashSize = 5; | 51 static const size_t kURLHashSize = 5; |
52 static const int kNumPrerenderCandidates = 5; | |
53 | |
54 } // namespace | |
55 | |
56 // When considering a candidate URL to be prerendered, we need to collect the | |
57 // data in this struct to make the determination whether we should issue the | |
58 // prerender or not. | |
59 struct PrerenderLocalPredictor::LocalPredictorURLInfo { | |
60 URLID id; | |
61 GURL url; | |
62 bool url_lookup_success; | |
63 bool logged_in; | |
64 bool logged_in_lookup_ok; | |
65 double priority; | |
66 }; | |
67 | |
68 // A struct consisting of everything needed for launching a potential prerender | |
69 // on a navigation: The navigation URL (source) triggering potential prerenders, | |
70 // and a set of candidate URLs. | |
71 struct PrerenderLocalPredictor::LocalPredictorURLLookupInfo { | |
72 LocalPredictorURLInfo source_url_; | |
73 vector<LocalPredictorURLInfo> candidate_urls_; | |
74 explicit LocalPredictorURLLookupInfo(URLID source_id) { | |
75 source_url_.id = source_id; | |
76 } | |
77 void MaybeAddCandidateURL(URLID id, double priority) { | |
78 LocalPredictorURLInfo info; | |
79 info.id = id; | |
80 info.priority = priority; | |
81 int insert_pos = candidate_urls_.size(); | |
82 if (insert_pos < kNumPrerenderCandidates) | |
83 candidate_urls_.push_back(info); | |
84 while (insert_pos > 0 && | |
85 candidate_urls_[insert_pos - 1].priority < info.priority) { | |
86 if (insert_pos < kNumPrerenderCandidates) | |
87 candidate_urls_[insert_pos] = candidate_urls_[insert_pos - 1]; | |
88 insert_pos--; | |
89 } | |
90 if (insert_pos < kNumPrerenderCandidates) | |
91 candidate_urls_[insert_pos] = info; | |
92 } | |
93 }; | |
94 | |
95 namespace { | |
40 | 96 |
41 // Task to lookup the URL for a given URLID. | 97 // Task to lookup the URL for a given URLID. |
42 class GetURLForURLIDTask : public history::HistoryDBTask { | 98 class GetURLForURLIDTask : public history::HistoryDBTask { |
43 public: | 99 public: |
44 GetURLForURLIDTask(URLID url_id, base::Callback<void(const GURL&)> callback) | 100 GetURLForURLIDTask( |
45 : url_id_(url_id), | 101 PrerenderLocalPredictor::LocalPredictorURLLookupInfo* request, |
46 success_(false), | 102 const base::Closure& callback) |
103 : request_(request), | |
47 callback_(callback), | 104 callback_(callback), |
48 start_time_(base::Time::Now()) { | 105 start_time_(base::Time::Now()) { |
49 } | 106 } |
50 | 107 |
51 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 108 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
52 history::HistoryDatabase* db) OVERRIDE { | 109 history::HistoryDatabase* db) OVERRIDE { |
53 history::URLRow url_row; | 110 DoURLLookup(db, &request_->source_url_); |
54 success_ = db->GetURLRow(url_id_, &url_row); | 111 for (int i = 0; i < static_cast<int>(request_->candidate_urls_.size()); i++) |
55 if (success_) | 112 DoURLLookup(db, &request_->candidate_urls_[i]); |
56 url_ = url_row.url(); | |
57 return true; | 113 return true; |
58 } | 114 } |
59 | 115 |
60 virtual void DoneRunOnMainThread() OVERRIDE { | 116 virtual void DoneRunOnMainThread() OVERRIDE { |
61 if (success_) { | 117 callback_.Run(); |
62 callback_.Run(url_); | 118 UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.LocalPredictorURLLookupTime", |
63 UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.LocalPredictorURLLookupTime", | 119 base::Time::Now() - start_time_, |
64 base::Time::Now() - start_time_, | 120 base::TimeDelta::FromMilliseconds(10), |
65 base::TimeDelta::FromMilliseconds(10), | 121 base::TimeDelta::FromSeconds(10), |
66 base::TimeDelta::FromSeconds(10), | 122 50); |
67 50); | |
68 } | |
69 } | 123 } |
70 | 124 |
71 private: | 125 private: |
72 virtual ~GetURLForURLIDTask() {} | 126 virtual ~GetURLForURLIDTask() {} |
73 | 127 |
74 URLID url_id_; | 128 void DoURLLookup(history::HistoryDatabase* db, |
75 bool success_; | 129 PrerenderLocalPredictor::LocalPredictorURLInfo* request) { |
76 base::Callback<void(const GURL&)> callback_; | 130 history::URLRow url_row; |
131 request->url_lookup_success = db->GetURLRow(request->id, &url_row); | |
132 if (request->url_lookup_success) | |
133 request->url = url_row.url(); | |
134 } | |
135 | |
136 PrerenderLocalPredictor::LocalPredictorURLLookupInfo* request_; | |
137 base::Closure callback_; | |
77 base::Time start_time_; | 138 base::Time start_time_; |
78 GURL url_; | |
79 DISALLOW_COPY_AND_ASSIGN(GetURLForURLIDTask); | 139 DISALLOW_COPY_AND_ASSIGN(GetURLForURLIDTask); |
80 }; | 140 }; |
81 | 141 |
82 // Task to load history from the visit database on startup. | 142 // Task to load history from the visit database on startup. |
83 class GetVisitHistoryTask : public history::HistoryDBTask { | 143 class GetVisitHistoryTask : public history::HistoryDBTask { |
84 public: | 144 public: |
85 GetVisitHistoryTask(PrerenderLocalPredictor* local_predictor, | 145 GetVisitHistoryTask(PrerenderLocalPredictor* local_predictor, |
86 int max_visits) | 146 int max_visits) |
87 : local_predictor_(local_predictor), | 147 : local_predictor_(local_predictor), |
88 max_visits_(max_visits), | 148 max_visits_(max_visits), |
89 visit_history_(new std::vector<history::BriefVisitInfo>) { | 149 visit_history_(new vector<history::BriefVisitInfo>) { |
90 } | 150 } |
91 | 151 |
92 virtual bool RunOnDBThread(history::HistoryBackend* backend, | 152 virtual bool RunOnDBThread(history::HistoryBackend* backend, |
93 history::HistoryDatabase* db) OVERRIDE { | 153 history::HistoryDatabase* db) OVERRIDE { |
94 db->GetBriefVisitInfoOfMostRecentVisits(max_visits_, visit_history_.get()); | 154 db->GetBriefVisitInfoOfMostRecentVisits(max_visits_, visit_history_.get()); |
95 return true; | 155 return true; |
96 } | 156 } |
97 | 157 |
98 virtual void DoneRunOnMainThread() OVERRIDE { | 158 virtual void DoneRunOnMainThread() OVERRIDE { |
99 local_predictor_->OnGetInitialVisitHistory(visit_history_.Pass()); | 159 local_predictor_->OnGetInitialVisitHistory(visit_history_.Pass()); |
100 } | 160 } |
101 | 161 |
102 private: | 162 private: |
103 virtual ~GetVisitHistoryTask() {} | 163 virtual ~GetVisitHistoryTask() {} |
104 | 164 |
105 PrerenderLocalPredictor* local_predictor_; | 165 PrerenderLocalPredictor* local_predictor_; |
106 int max_visits_; | 166 int max_visits_; |
107 scoped_ptr<std::vector<history::BriefVisitInfo> > visit_history_; | 167 scoped_ptr<vector<history::BriefVisitInfo> > visit_history_; |
108 DISALLOW_COPY_AND_ASSIGN(GetVisitHistoryTask); | 168 DISALLOW_COPY_AND_ASSIGN(GetVisitHistoryTask); |
109 }; | 169 }; |
110 | 170 |
111 // Maximum visit history to retrieve from the visit database. | 171 // Maximum visit history to retrieve from the visit database. |
112 const int kMaxVisitHistory = 100 * 1000; | 172 const int kMaxVisitHistory = 100 * 1000; |
113 | 173 |
114 // Visit history size at which to trigger pruning, and number of items to prune. | 174 // Visit history size at which to trigger pruning, and number of items to prune. |
115 const int kVisitHistoryPruneThreshold = 120 * 1000; | 175 const int kVisitHistoryPruneThreshold = 120 * 1000; |
116 const int kVisitHistoryPruneAmount = 20 * 1000; | 176 const int kVisitHistoryPruneAmount = 20 * 1000; |
117 | 177 |
118 const int kMaxLocalPredictionTimeMs = 300 * 1000; | 178 const int kMaxLocalPredictionTimeMs = 180 * 1000; |
119 const int kMinLocalPredictionTimeMs = 500; | 179 const int kMinLocalPredictionTimeMs = 500; |
120 | 180 |
121 bool IsBackForward(PageTransition transition) { | 181 bool IsBackForward(PageTransition transition) { |
122 return (transition & content::PAGE_TRANSITION_FORWARD_BACK) != 0; | 182 return (transition & content::PAGE_TRANSITION_FORWARD_BACK) != 0; |
123 } | 183 } |
124 | 184 |
125 bool IsHomePage(PageTransition transition) { | 185 bool IsHomePage(PageTransition transition) { |
126 return (transition & content::PAGE_TRANSITION_HOME_PAGE) != 0; | 186 return (transition & content::PAGE_TRANSITION_HOME_PAGE) != 0; |
127 } | 187 } |
128 | 188 |
129 bool IsIntermediateRedirect(PageTransition transition) { | 189 bool IsIntermediateRedirect(PageTransition transition) { |
130 return (transition & content::PAGE_TRANSITION_CHAIN_END) == 0; | 190 return (transition & content::PAGE_TRANSITION_CHAIN_END) == 0; |
131 } | 191 } |
132 | 192 |
133 bool ShouldExcludeTransitionForPrediction(PageTransition transition) { | 193 bool ShouldExcludeTransitionForPrediction(PageTransition transition) { |
134 return IsBackForward(transition) || IsHomePage(transition) || | 194 return IsBackForward(transition) || IsHomePage(transition) || |
135 IsIntermediateRedirect(transition); | 195 IsIntermediateRedirect(transition); |
136 } | 196 } |
137 | 197 |
138 base::Time GetCurrentTime() { | 198 base::Time GetCurrentTime() { |
139 return base::Time::Now(); | 199 return base::Time::Now(); |
140 } | 200 } |
141 | 201 |
142 bool StrCaseStr(std::string haystack, std::string needle) { | 202 bool StringContainsIgnoringCase(string haystack, string needle) { |
143 std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower); | 203 std::transform(haystack.begin(), haystack.end(), haystack.begin(), ::tolower); |
144 std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower); | 204 std::transform(needle.begin(), needle.end(), needle.begin(), ::tolower); |
145 return haystack.find(needle) != std::string::npos; | 205 return haystack.find(needle) != string::npos; |
146 } | 206 } |
147 | 207 |
148 bool IsExtendedRootURL(const GURL& url) { | 208 bool IsExtendedRootURL(const GURL& url) { |
149 const std::string& path = url.path(); | 209 const string& path = url.path(); |
150 return path == "/index.html" || path == "/home.html" || | 210 return path == "/index.html" || path == "/home.html" || |
151 path == "/main.html" || | 211 path == "/main.html" || |
152 path == "/index.htm" || path == "/home.htm" || path == "/main.htm" || | 212 path == "/index.htm" || path == "/home.htm" || path == "/main.htm" || |
153 path == "/index.php" || path == "/home.php" || path == "/main.php" || | 213 path == "/index.php" || path == "/home.php" || path == "/main.php" || |
154 path == "/index.asp" || path == "/home.asp" || path == "/main.asp" || | 214 path == "/index.asp" || path == "/home.asp" || path == "/main.asp" || |
155 path == "/index.py" || path == "/home.py" || path == "/main.py" || | 215 path == "/index.py" || path == "/home.py" || path == "/main.py" || |
156 path == "/index.pl" || path == "/home.pl" || path == "/main.pl"; | 216 path == "/index.pl" || path == "/home.pl" || path == "/main.pl"; |
157 } | 217 } |
158 | 218 |
159 bool IsRootPageURL(const GURL& url) { | 219 bool IsRootPageURL(const GURL& url) { |
160 return (url.path() == "/" || url.path() == "" || IsExtendedRootURL(url)) && | 220 return (url.path() == "/" || url.path() == "" || IsExtendedRootURL(url)) && |
161 (!url.has_query()) && (!url.has_ref()); | 221 (!url.has_query()) && (!url.has_ref()); |
162 } | 222 } |
163 | 223 |
224 bool IsLogInURL(const GURL& url) { | |
225 return StringContainsIgnoringCase(url.spec().c_str(), "login") || | |
226 StringContainsIgnoringCase(url.spec().c_str(), "signin"); | |
227 } | |
228 | |
229 bool IsLogOutURL(const GURL& url) { | |
230 return StringContainsIgnoringCase(url.spec().c_str(), "logout") || | |
231 StringContainsIgnoringCase(url.spec().c_str(), "signout"); | |
232 } | |
233 | |
164 int64 URLHashToInt64(const unsigned char* data) { | 234 int64 URLHashToInt64(const unsigned char* data) { |
165 COMPILE_ASSERT(kURLHashSize < sizeof(int64), url_hash_must_fit_in_int64); | 235 COMPILE_ASSERT(kURLHashSize < sizeof(int64), url_hash_must_fit_in_int64); |
166 int64 value = 0; | 236 int64 value = 0; |
167 memcpy(&value, data, kURLHashSize); | 237 memcpy(&value, data, kURLHashSize); |
168 return value; | 238 return value; |
169 } | 239 } |
170 | 240 |
171 int64 GetInt64URLHashForURL(const GURL& url) { | 241 int64 GetInt64URLHashForURL(const GURL& url) { |
172 COMPILE_ASSERT(kURLHashSize < sizeof(int64), url_hash_must_fit_in_int64); | 242 COMPILE_ASSERT(kURLHashSize < sizeof(int64), url_hash_must_fit_in_int64); |
173 scoped_ptr<crypto::SecureHash> hash( | 243 scoped_ptr<crypto::SecureHash> hash( |
174 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | 244 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
175 int64 hash_value = 0; | 245 int64 hash_value = 0; |
176 const char* url_string = url.spec().c_str(); | 246 const char* url_string = url.spec().c_str(); |
177 hash->Update(url_string, strlen(url_string)); | 247 hash->Update(url_string, strlen(url_string)); |
178 hash->Finish(&hash_value, kURLHashSize); | 248 hash->Finish(&hash_value, kURLHashSize); |
179 return hash_value; | 249 return hash_value; |
180 } | 250 } |
181 | 251 |
252 bool URLsIdenticalIgnoringFragments(const GURL& url1, const GURL& url2) { | |
253 url_canon::Replacements<char> replacement; | |
254 replacement.ClearRef(); | |
255 GURL u1 = url1.ReplaceComponents(replacement); | |
256 GURL u2 = url2.ReplaceComponents(replacement); | |
257 return (u1 == u2); | |
258 } | |
259 | |
260 void LookupLoggedInStatesOnDBThread( | |
261 scoped_refptr<LoggedInPredictorTable> logged_in_predictor_table, | |
262 PrerenderLocalPredictor::LocalPredictorURLLookupInfo* request_) { | |
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
264 for (int i = 0; i < static_cast<int>(request_->candidate_urls_.size()); i++) { | |
265 PrerenderLocalPredictor::LocalPredictorURLInfo* info = | |
266 &request_->candidate_urls_[i]; | |
267 if (info->url_lookup_success) { | |
268 logged_in_predictor_table->HasUserLoggedIn( | |
269 info->url, &info->logged_in, &info->logged_in_lookup_ok); | |
270 } else { | |
271 info->logged_in_lookup_ok = false; | |
272 } | |
273 } | |
274 } | |
275 | |
182 } // namespace | 276 } // namespace |
183 | 277 |
184 struct PrerenderLocalPredictor::PrerenderData { | 278 struct PrerenderLocalPredictor::PrerenderProperties { |
185 PrerenderData(URLID url_id, const GURL& url, double priority, | 279 PrerenderProperties(URLID url_id, const GURL& url, double priority, |
186 base::Time start_time) | 280 base::Time start_time) |
187 : url_id(url_id), | 281 : url_id(url_id), |
188 url(url), | 282 url(url), |
189 priority(priority), | 283 priority(priority), |
190 start_time(start_time) { | 284 start_time(start_time) { |
191 } | 285 } |
192 | 286 |
193 URLID url_id; | 287 URLID url_id; |
194 GURL url; | 288 GURL url; |
195 double priority; | 289 double priority; |
196 // For expiration purposes, this is a synthetic start time consisting either | 290 // For expiration purposes, this is a synthetic start time consisting either |
197 // of the actual start time, or of the last time the page was re-requested | 291 // of the actual start time, or of the last time the page was re-requested |
198 // for prerendering - 10 seconds (unless the original request came after | 292 // for prerendering - 10 seconds (unless the original request came after |
199 // that). This is to emulate the effect of re-prerendering a page that is | 293 // that). This is to emulate the effect of re-prerendering a page that is |
200 // about to expire, because it was re-requested for prerendering a second | 294 // about to expire, because it was re-requested for prerendering a second |
201 // time after the actual prerender being kept around. | 295 // time after the actual prerender being kept around. |
202 base::Time start_time; | 296 base::Time start_time; |
203 // The actual time this page was last requested for prerendering. | 297 // The actual time this page was last requested for prerendering. |
204 base::Time actual_start_time; | 298 base::Time actual_start_time; |
205 | 299 |
206 private: | 300 private: |
207 DISALLOW_IMPLICIT_CONSTRUCTORS(PrerenderData); | 301 DISALLOW_IMPLICIT_CONSTRUCTORS(PrerenderProperties); |
208 }; | 302 }; |
209 | 303 |
210 PrerenderLocalPredictor::PrerenderLocalPredictor( | 304 PrerenderLocalPredictor::PrerenderLocalPredictor( |
211 PrerenderManager* prerender_manager) | 305 PrerenderManager* prerender_manager) |
212 : prerender_manager_(prerender_manager), | 306 : prerender_manager_(prerender_manager), |
213 is_visit_database_observer_(false) { | 307 is_visit_database_observer_(false), |
308 weak_factory_(this) { | |
214 RecordEvent(EVENT_CONSTRUCTED); | 309 RecordEvent(EVENT_CONSTRUCTED); |
215 if (MessageLoop::current()) { | 310 if (MessageLoop::current()) { |
216 timer_.Start(FROM_HERE, | 311 timer_.Start(FROM_HERE, |
217 base::TimeDelta::FromMilliseconds(kInitDelayMs), | 312 base::TimeDelta::FromMilliseconds(kInitDelayMs), |
218 this, | 313 this, |
219 &PrerenderLocalPredictor::Init); | 314 &PrerenderLocalPredictor::Init); |
220 RecordEvent(EVENT_INIT_SCHEDULED); | 315 RecordEvent(EVENT_INIT_SCHEDULED); |
221 } | 316 } |
222 | 317 |
223 static const size_t kChecksumHashSize = 32; | 318 static const size_t kChecksumHashSize = 32; |
(...skipping 19 matching lines...) Expand all Loading... | |
243 for (const unsigned char* p = front + kChecksumHashSize; | 338 for (const unsigned char* p = front + kChecksumHashSize; |
244 p < front + size; | 339 p < front + size; |
245 p += kURLHashSize) { | 340 p += kURLHashSize) { |
246 url_whitelist_.insert(URLHashToInt64(p)); | 341 url_whitelist_.insert(URLHashToInt64(p)); |
247 } | 342 } |
248 RecordEvent(EVENT_URL_WHITELIST_OK); | 343 RecordEvent(EVENT_URL_WHITELIST_OK); |
249 } | 344 } |
250 | 345 |
251 PrerenderLocalPredictor::~PrerenderLocalPredictor() { | 346 PrerenderLocalPredictor::~PrerenderLocalPredictor() { |
252 Shutdown(); | 347 Shutdown(); |
348 if (prerender_handle_.get()) | |
349 prerender_handle_->OnCancel(); | |
253 } | 350 } |
254 | 351 |
255 void PrerenderLocalPredictor::Shutdown() { | 352 void PrerenderLocalPredictor::Shutdown() { |
256 timer_.Stop(); | 353 timer_.Stop(); |
257 if (is_visit_database_observer_) { | 354 if (is_visit_database_observer_) { |
258 HistoryService* history = GetHistoryIfExists(); | 355 HistoryService* history = GetHistoryIfExists(); |
259 CHECK(history); | 356 CHECK(history); |
260 history->RemoveVisitDatabaseObserver(this); | 357 history->RemoveVisitDatabaseObserver(this); |
261 is_visit_database_observer_ = false; | 358 is_visit_database_observer_ = false; |
262 } | 359 } |
(...skipping 26 matching lines...) Expand all Loading... | |
289 return; | 386 return; |
290 RecordEvent(EVENT_ADD_VISIT_RELEVANT_TRANSITION); | 387 RecordEvent(EVENT_ADD_VISIT_RELEVANT_TRANSITION); |
291 base::TimeDelta max_age = | 388 base::TimeDelta max_age = |
292 base::TimeDelta::FromMilliseconds(kMaxLocalPredictionTimeMs); | 389 base::TimeDelta::FromMilliseconds(kMaxLocalPredictionTimeMs); |
293 base::TimeDelta min_age = | 390 base::TimeDelta min_age = |
294 base::TimeDelta::FromMilliseconds(kMinLocalPredictionTimeMs); | 391 base::TimeDelta::FromMilliseconds(kMinLocalPredictionTimeMs); |
295 std::set<URLID> next_urls_currently_found; | 392 std::set<URLID> next_urls_currently_found; |
296 std::map<URLID, int> next_urls_num_found; | 393 std::map<URLID, int> next_urls_num_found; |
297 int num_occurrences_of_current_visit = 0; | 394 int num_occurrences_of_current_visit = 0; |
298 base::Time last_visited; | 395 base::Time last_visited; |
299 URLID best_next_url = 0; | 396 scoped_ptr<LocalPredictorURLLookupInfo> lookup_info( |
300 int best_next_url_count = 0; | 397 new LocalPredictorURLLookupInfo(info.url_id)); |
301 const std::vector<history::BriefVisitInfo>& visits = *(visit_history_.get()); | 398 const vector<history::BriefVisitInfo>& visits = *(visit_history_.get()); |
302 for (int i = 0; i < static_cast<int>(visits.size()); i++) { | 399 for (int i = 0; i < static_cast<int>(visits.size()); i++) { |
303 if (!ShouldExcludeTransitionForPrediction(visits[i].transition)) { | 400 if (!ShouldExcludeTransitionForPrediction(visits[i].transition)) { |
304 if (visits[i].url_id == info.url_id) { | 401 if (visits[i].url_id == info.url_id) { |
305 last_visited = visits[i].time; | 402 last_visited = visits[i].time; |
306 num_occurrences_of_current_visit++; | 403 num_occurrences_of_current_visit++; |
307 next_urls_currently_found.clear(); | 404 next_urls_currently_found.clear(); |
308 continue; | 405 continue; |
309 } | 406 } |
310 if (!last_visited.is_null() && | 407 if (!last_visited.is_null() && |
311 last_visited > visits[i].time - max_age && | 408 last_visited > visits[i].time - max_age && |
312 last_visited < visits[i].time - min_age) { | 409 last_visited < visits[i].time - min_age) { |
313 next_urls_currently_found.insert(visits[i].url_id); | 410 next_urls_currently_found.insert(visits[i].url_id); |
314 } | 411 } |
315 } | 412 } |
316 if (i == static_cast<int>(visits.size()) - 1 || | 413 if (i == static_cast<int>(visits.size()) - 1 || |
317 visits[i+1].url_id == info.url_id) { | 414 visits[i+1].url_id == info.url_id) { |
318 for (std::set<URLID>::iterator it = next_urls_currently_found.begin(); | 415 for (std::set<URLID>::iterator it = next_urls_currently_found.begin(); |
319 it != next_urls_currently_found.end(); | 416 it != next_urls_currently_found.end(); |
320 ++it) { | 417 ++it) { |
321 std::pair<std::map<URLID, int>::iterator, bool> insert_ret = | 418 std::pair<std::map<URLID, int>::iterator, bool> insert_ret = |
322 next_urls_num_found.insert(std::pair<URLID, int>(*it, 0)); | 419 next_urls_num_found.insert(std::pair<URLID, int>(*it, 0)); |
323 std::map<URLID, int>::iterator num_found_it = insert_ret.first; | 420 std::map<URLID, int>::iterator num_found_it = insert_ret.first; |
324 num_found_it->second++; | 421 num_found_it->second++; |
325 if (num_found_it->second > best_next_url_count) { | |
326 best_next_url_count = num_found_it->second; | |
327 best_next_url = *it; | |
328 } | |
329 } | 422 } |
330 } | 423 } |
331 } | 424 } |
332 | 425 |
333 // Only consider a candidate next page for prerendering if it was viewed | 426 for (std::map<URLID, int>::const_iterator it = next_urls_num_found.begin(); |
334 // at least twice, and at least 10% of the time. | 427 it != next_urls_num_found.end(); |
335 if (num_occurrences_of_current_visit > 0 && | 428 ++it) { |
336 best_next_url_count > 1 && | 429 // Only consider a candidate next page for prerendering if it was viewed |
337 best_next_url_count * 10 >= num_occurrences_of_current_visit) { | 430 // at least twice, and at least 10% of the time. |
338 RecordEvent(EVENT_ADD_VISIT_IDENTIFIED_PRERENDER_CANDIDATE); | 431 if (num_occurrences_of_current_visit > 0 && |
339 double priority = static_cast<double>(best_next_url_count) / | 432 it->second > 1 && |
340 static_cast<double>(num_occurrences_of_current_visit); | 433 it->second * 10 >= num_occurrences_of_current_visit) { |
341 if (ShouldReplaceCurrentPrerender(priority)) { | 434 RecordEvent(EVENT_ADD_VISIT_IDENTIFIED_PRERENDER_CANDIDATE); |
342 RecordEvent(EVENT_START_URL_LOOKUP); | 435 double priority = static_cast<double>(it->second) / |
343 HistoryService* history = GetHistoryIfExists(); | 436 static_cast<double>(num_occurrences_of_current_visit); |
344 if (history) { | 437 lookup_info->MaybeAddCandidateURL(it->first, priority); |
345 history->ScheduleDBTask( | |
346 new GetURLForURLIDTask( | |
347 best_next_url, | |
348 base::Bind(&PrerenderLocalPredictor::OnLookupURL, | |
349 base::Unretained(this), | |
350 best_next_url, | |
351 priority)), | |
352 &history_db_consumer_); | |
353 } | |
354 } | 438 } |
355 } | 439 } |
440 | |
441 if (lookup_info->candidate_urls_.size() == 0) { | |
442 RecordEvent(EVENT_NO_PRERENDER_CANDIDATES); | |
443 return; | |
444 } | |
445 | |
446 RecordEvent(EVENT_START_URL_LOOKUP); | |
447 HistoryService* history = GetHistoryIfExists(); | |
448 if (history) { | |
449 RecordEvent(EVENT_GOT_HISTORY_ISSUING_LOOKUP); | |
450 LocalPredictorURLLookupInfo* lookup_info_ptr = lookup_info.get(); | |
451 history->ScheduleDBTask( | |
452 new GetURLForURLIDTask( | |
453 lookup_info_ptr, | |
454 base::Bind(&PrerenderLocalPredictor::OnLookupURL, | |
455 base::Unretained(this), | |
456 base::Passed(&lookup_info))), | |
457 &history_db_consumer_); | |
458 } | |
356 } | 459 } |
357 | 460 |
358 void PrerenderLocalPredictor::OnLookupURL(history::URLID url_id, | 461 void PrerenderLocalPredictor::OnLookupURL( |
359 double priority, | 462 scoped_ptr<LocalPredictorURLLookupInfo> info) { |
360 const GURL& url) { | |
361 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT); | 463 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT); |
362 | 464 |
363 base::Time current_time = GetCurrentTime(); | 465 DCHECK(info->candidate_urls_.size() >= 1); |
Shishir
2013/05/08 20:19:20
DCHECK_GE(info.., 1);
tburkard
2013/05/08 20:35:47
Done.
| |
364 if (ShouldReplaceCurrentPrerender(priority)) { | 466 |
365 if (IsRootPageURL(url)) { | 467 if (!info->source_url_.url_lookup_success) { |
366 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); | 468 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_FAILED); |
367 if (current_prerender_.get() && current_prerender_->url_id == url_id) { | 469 return; |
368 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); | 470 } |
369 if (priority > current_prerender_->priority) | 471 |
370 current_prerender_->priority = priority; | 472 LogCandidateURLStats(info->candidate_urls_[0].url); |
371 // If the prerender already existed, we want to extend it. However, | 473 |
372 // we do not want to set its start_time to the current time to | 474 WebContents* source_web_contents = NULL; |
373 // disadvantage PLT computations when the prerender is swapped in. | 475 |
374 // So we set the new start time to current_time - 10s (since the vast | 476 #if !defined(OS_ANDROID) |
375 // majority of PLTs are < 10s), provided that is not before the actual | 477 // We need to figure out what tab launched the prerender. We do this by |
376 // time the prerender was started (so as to not artificially advantage | 478 // comparing URLs. This may not always work: the URL may occur in two |
377 // the PLT computation). | 479 // tabs, and we pick the wrong one, or the tab we should have picked |
378 base::Time simulated_new_start_time = | 480 // may have navigated elsewhere. Hopefully, this doesn't happen to often, |
Shishir
2013/05/08 20:19:20
s/to/too
tburkard
2013/05/08 20:35:47
Done.
| |
379 current_time - base::TimeDelta::FromSeconds(10); | 481 // so we ignore these cases for now. |
380 if (simulated_new_start_time > current_prerender_->start_time) | 482 // TODO(tburkard): Reconsider this, potentially measure it, and fix this |
381 current_prerender_->start_time = simulated_new_start_time; | 483 // in the future. |
382 } else { | 484 for (TabContentsIterator it; !it.done(); it.Next()) { |
383 current_prerender_.reset( | 485 if (it->GetURL() == info->source_url_.url) { |
384 new PrerenderData(url_id, url, priority, current_time)); | 486 source_web_contents = *it; |
385 } | 487 break; |
386 current_prerender_->actual_start_time = current_time; | |
387 } else { | |
388 RecordEvent(EVENT_ADD_VISIT_NOT_ROOTPAGE); | |
389 } | 488 } |
390 } | 489 } |
490 #endif | |
391 | 491 |
492 if (!source_web_contents) { | |
493 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_SOURCE_WEBCONTENTS_FOUND); | |
494 return; | |
495 } | |
496 | |
497 scoped_refptr<SessionStorageNamespace> session_storage_namespace = | |
498 source_web_contents->GetController().GetDefaultSessionStorageNamespace(); | |
499 | |
500 gfx::Rect container_bounds; | |
501 source_web_contents->GetView()->GetContainerBounds(&container_bounds); | |
502 scoped_ptr<gfx::Size> size(new gfx::Size(container_bounds.size())); | |
503 | |
504 scoped_refptr<LoggedInPredictorTable> logged_in_table = | |
505 prerender_manager_->logged_in_predictor_table(); | |
506 | |
507 if (!logged_in_table.get()) { | |
508 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_NO_LOGGED_IN_TABLE_FOUND); | |
509 return; | |
510 } | |
511 | |
512 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_ISSUING_LOGGED_IN_LOOKUP); | |
513 | |
514 LocalPredictorURLLookupInfo* info_ptr = info.get(); | |
515 BrowserThread::PostTaskAndReply( | |
516 BrowserThread::DB, FROM_HERE, | |
517 base::Bind(&LookupLoggedInStatesOnDBThread, | |
518 logged_in_table, | |
519 info_ptr), | |
520 base::Bind(&PrerenderLocalPredictor::ContinuePrerenderCheck, | |
521 weak_factory_.GetWeakPtr(), | |
522 session_storage_namespace, | |
523 base::Passed(&size), | |
524 base::Passed(&info))); | |
525 } | |
526 | |
527 void PrerenderLocalPredictor::LogCandidateURLStats(const GURL& url) const { | |
392 if (url_whitelist_.count(GetInt64URLHashForURL(url)) > 0) { | 528 if (url_whitelist_.count(GetInt64URLHashForURL(url)) > 0) { |
393 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST); | 529 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST); |
394 if (IsRootPageURL(url)) | 530 if (IsRootPageURL(url)) |
395 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST_ROOT_PAGE); | 531 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ON_WHITELIST_ROOT_PAGE); |
396 } | 532 } |
397 if (IsRootPageURL(url)) | 533 if (IsRootPageURL(url)) |
398 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ROOT_PAGE); | 534 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ROOT_PAGE); |
399 if (IsExtendedRootURL(url)) | 535 if (IsExtendedRootURL(url)) |
400 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_EXTENDED_ROOT_PAGE); | 536 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_EXTENDED_ROOT_PAGE); |
401 if (IsRootPageURL(url) && url.SchemeIs("http")) | 537 if (IsRootPageURL(url) && url.SchemeIs("http")) |
402 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ROOT_PAGE_HTTP); | 538 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_ROOT_PAGE_HTTP); |
403 if (url.SchemeIs("http")) | 539 if (url.SchemeIs("http")) |
404 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_IS_HTTP); | 540 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_IS_HTTP); |
405 if (url.has_query()) | 541 if (url.has_query()) |
406 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_HAS_QUERY_STRING); | 542 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_HAS_QUERY_STRING); |
407 if (StrCaseStr(url.spec().c_str(), "logout") || | 543 if (IsLogOutURL(url)) |
408 StrCaseStr(url.spec().c_str(), "signout")) | |
409 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_CONTAINS_LOGOUT); | 544 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_CONTAINS_LOGOUT); |
410 if (StrCaseStr(url.spec().c_str(), "login") || | 545 if (IsLogInURL(url)) |
411 StrCaseStr(url.spec().c_str(), "signin")) | |
412 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_CONTAINS_LOGIN); | 546 RecordEvent(EVENT_PRERENDER_URL_LOOKUP_RESULT_CONTAINS_LOGIN); |
413 } | 547 } |
414 | 548 |
415 void PrerenderLocalPredictor::OnGetInitialVisitHistory( | 549 void PrerenderLocalPredictor::OnGetInitialVisitHistory( |
416 scoped_ptr<std::vector<history::BriefVisitInfo> > visit_history) { | 550 scoped_ptr<vector<history::BriefVisitInfo> > visit_history) { |
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
418 DCHECK(!visit_history_.get()); | 552 DCHECK(!visit_history_.get()); |
419 RecordEvent(EVENT_INIT_SUCCEEDED); | 553 RecordEvent(EVENT_INIT_SUCCEEDED); |
420 // Since the visit history has descending timestamps, we must reverse it. | 554 // Since the visit history has descending timestamps, we must reverse it. |
421 visit_history_.reset(new std::vector<history::BriefVisitInfo>( | 555 visit_history_.reset(new vector<history::BriefVisitInfo>( |
422 visit_history->rbegin(), visit_history->rend())); | 556 visit_history->rbegin(), visit_history->rend())); |
423 } | 557 } |
424 | 558 |
425 HistoryService* PrerenderLocalPredictor::GetHistoryIfExists() const { | 559 HistoryService* PrerenderLocalPredictor::GetHistoryIfExists() const { |
426 Profile* profile = prerender_manager_->profile(); | 560 Profile* profile = prerender_manager_->profile(); |
427 if (!profile) | 561 if (!profile) |
428 return NULL; | 562 return NULL; |
429 return HistoryServiceFactory::GetForProfileWithoutCreating(profile); | 563 return HistoryServiceFactory::GetForProfileWithoutCreating(profile); |
430 } | 564 } |
431 | 565 |
432 void PrerenderLocalPredictor::Init() { | 566 void PrerenderLocalPredictor::Init() { |
433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
434 RecordEvent(EVENT_INIT_STARTED); | 568 RecordEvent(EVENT_INIT_STARTED); |
435 HistoryService* history = GetHistoryIfExists(); | 569 HistoryService* history = GetHistoryIfExists(); |
436 if (history) { | 570 if (history) { |
437 CHECK(!is_visit_database_observer_); | 571 CHECK(!is_visit_database_observer_); |
438 history->ScheduleDBTask( | 572 history->ScheduleDBTask( |
439 new GetVisitHistoryTask(this, kMaxVisitHistory), | 573 new GetVisitHistoryTask(this, kMaxVisitHistory), |
440 &history_db_consumer_); | 574 &history_db_consumer_); |
441 history->AddVisitDatabaseObserver(this); | 575 history->AddVisitDatabaseObserver(this); |
442 is_visit_database_observer_ = true; | 576 is_visit_database_observer_ = true; |
443 } else { | 577 } else { |
444 RecordEvent(EVENT_INIT_FAILED_NO_HISTORY); | 578 RecordEvent(EVENT_INIT_FAILED_NO_HISTORY); |
445 } | 579 } |
446 } | 580 } |
447 | 581 |
448 void PrerenderLocalPredictor::OnPLTEventForURL(const GURL& url, | 582 void PrerenderLocalPredictor::OnPLTEventForURL(const GURL& url, |
449 base::TimeDelta page_load_time) { | 583 base::TimeDelta page_load_time) { |
450 scoped_ptr<PrerenderData> prerender; | 584 scoped_ptr<PrerenderProperties> prerender; |
451 if (DoesPrerenderMatchPLTRecord(last_swapped_in_prerender_.get(), | 585 if (DoesPrerenderMatchPLTRecord(last_swapped_in_prerender_.get(), |
452 url, page_load_time)) { | 586 url, page_load_time)) { |
453 prerender.reset(last_swapped_in_prerender_.release()); | 587 prerender.reset(last_swapped_in_prerender_.release()); |
454 } | 588 } |
455 if (DoesPrerenderMatchPLTRecord(current_prerender_.get(), | 589 if (DoesPrerenderMatchPLTRecord(current_prerender_.get(), |
456 url, page_load_time)) { | 590 url, page_load_time)) { |
457 prerender.reset(current_prerender_.release()); | 591 prerender.reset(current_prerender_.release()); |
458 } | 592 } |
459 if (!prerender.get()) | 593 if (!prerender.get()) |
460 return; | 594 return; |
(...skipping 12 matching lines...) Expand all Loading... | |
473 UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.SimulatedLocalBrowsingPLT", | 607 UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.SimulatedLocalBrowsingPLT", |
474 new_plt, | 608 new_plt, |
475 base::TimeDelta::FromMilliseconds(10), | 609 base::TimeDelta::FromMilliseconds(10), |
476 base::TimeDelta::FromSeconds(60), | 610 base::TimeDelta::FromSeconds(60), |
477 100); | 611 100); |
478 } | 612 } |
479 } | 613 } |
480 } | 614 } |
481 | 615 |
482 bool PrerenderLocalPredictor::IsPrerenderStillValid( | 616 bool PrerenderLocalPredictor::IsPrerenderStillValid( |
483 PrerenderLocalPredictor::PrerenderData* prerender) const { | 617 PrerenderLocalPredictor::PrerenderProperties* prerender) const { |
484 return (prerender && | 618 return (prerender && |
485 (prerender->start_time + | 619 (prerender->start_time + |
486 base::TimeDelta::FromMilliseconds(kMaxLocalPredictionTimeMs)) | 620 base::TimeDelta::FromMilliseconds(kMaxLocalPredictionTimeMs)) |
487 > GetCurrentTime()); | 621 > GetCurrentTime()); |
488 } | 622 } |
489 | 623 |
490 void PrerenderLocalPredictor::RecordEvent( | 624 void PrerenderLocalPredictor::RecordEvent( |
491 PrerenderLocalPredictor::Event event) const { | 625 PrerenderLocalPredictor::Event event) const { |
492 UMA_HISTOGRAM_ENUMERATION("Prerender.LocalPredictorEvent", | 626 UMA_HISTOGRAM_ENUMERATION("Prerender.LocalPredictorEvent", |
493 event, PrerenderLocalPredictor::EVENT_MAX_VALUE); | 627 event, PrerenderLocalPredictor::EVENT_MAX_VALUE); |
494 } | 628 } |
495 | 629 |
496 bool PrerenderLocalPredictor::DoesPrerenderMatchPLTRecord( | 630 bool PrerenderLocalPredictor::DoesPrerenderMatchPLTRecord( |
497 PrerenderData* prerender, const GURL& url, base::TimeDelta plt) const { | 631 PrerenderProperties* prerender, |
632 const GURL& url, | |
633 base::TimeDelta plt) const { | |
498 if (prerender && prerender->start_time < GetCurrentTime() - plt) { | 634 if (prerender && prerender->start_time < GetCurrentTime() - plt) { |
499 if (prerender->url.is_empty()) | 635 if (prerender->url.is_empty()) |
500 RecordEvent(EVENT_ERROR_NO_PRERENDER_URL_FOR_PLT); | 636 RecordEvent(EVENT_ERROR_NO_PRERENDER_URL_FOR_PLT); |
501 return (prerender->url == url); | 637 return (prerender->url == url); |
502 } else { | 638 } else { |
503 return false; | 639 return false; |
504 } | 640 } |
505 } | 641 } |
506 | 642 |
507 bool PrerenderLocalPredictor::ShouldReplaceCurrentPrerender( | 643 bool PrerenderLocalPredictor::ShouldReplaceCurrentPrerender( |
508 double priority) const { | 644 double priority) const { |
509 base::TimeDelta max_age = | 645 return (!prerender_handle_.get() || |
510 base::TimeDelta::FromMilliseconds(kMaxLocalPredictionTimeMs); | 646 !prerender_handle_->IsPrerendering() || |
511 return (!current_prerender_.get()) || | 647 current_prerender_priority_ < priority); |
512 current_prerender_->priority < priority || | 648 } |
513 current_prerender_->start_time < GetCurrentTime() - max_age; | 649 |
650 void PrerenderLocalPredictor::ContinuePrerenderCheck( | |
651 scoped_refptr<SessionStorageNamespace> session_storage_namespace, | |
652 scoped_ptr<gfx::Size> size, | |
653 scoped_ptr<LocalPredictorURLLookupInfo> info) { | |
654 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_STARTED); | |
655 scoped_ptr<LocalPredictorURLInfo> url_info; | |
656 for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { | |
657 url_info.reset(new LocalPredictorURLInfo(info->candidate_urls_[i])); | |
658 if (!url_info->url_lookup_success) { | |
659 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NO_URL); | |
660 url_info.reset(NULL); | |
661 continue; | |
662 } | |
663 if (!ShouldReplaceCurrentPrerender(url_info->priority)) { | |
664 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_PRIORITY_TOO_LOW); | |
665 url_info.reset(NULL); | |
666 continue; | |
667 } | |
668 if (URLsIdenticalIgnoringFragments(info->source_url_.url, | |
669 url_info->url)) { | |
670 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_URLS_IDENTICAL_BUT_FRAGMENT); | |
671 url_info.reset(NULL); | |
672 continue; | |
673 } | |
674 if (url_info->url.SchemeIs("https")) { | |
675 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_HTTPS); | |
676 url_info.reset(NULL); | |
677 continue; | |
678 } | |
679 if (IsRootPageURL(url_info->url)) { | |
680 // For root pages, we assume that they are reasonably safe, and we | |
681 // will just prerender them without any additional checks. | |
682 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ROOT_PAGE); | |
683 break; | |
684 } | |
685 if (IsLogOutURL(url_info->url)) { | |
686 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGOUT_URL); | |
687 url_info.reset(NULL); | |
688 continue; | |
689 } | |
690 if (IsLogInURL(url_info->url)) { | |
691 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_LOGIN_URL); | |
692 url_info.reset(NULL); | |
693 continue; | |
694 } | |
695 if (!url_info->logged_in && url_info->logged_in_lookup_ok) { | |
696 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_NOT_LOGGED_IN); | |
697 break; | |
698 } | |
699 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_NOT_PRERENDERING); | |
700 url_info.reset(NULL); | |
701 } | |
702 if (!url_info.get()) | |
703 return; | |
704 RecordEvent(EVENT_CONTINUE_PRERENDER_CHECK_ISSUING_PRERENDER); | |
705 IssuePrerender(session_storage_namespace, size.Pass(), | |
706 url_info.Pass()); | |
707 } | |
708 | |
709 void PrerenderLocalPredictor::IssuePrerender( | |
710 scoped_refptr<SessionStorageNamespace> session_storage_namespace, | |
711 scoped_ptr<gfx::Size> size, | |
712 scoped_ptr<LocalPredictorURLInfo> info) { | |
713 URLID url_id = info->id; | |
714 const GURL& url = info->url; | |
715 double priority = info->priority; | |
716 base::Time current_time = GetCurrentTime(); | |
717 RecordEvent(EVENT_ISSUING_PRERENDER); | |
718 | |
719 current_prerender_priority_ = priority; | |
720 scoped_ptr<prerender::PrerenderHandle> old_prerender_handle( | |
721 prerender_handle_.release()); | |
722 prerender_handle_.reset(prerender_manager_->AddPrerenderFromLocalPredictor( | |
723 url, session_storage_namespace.get(), *size)); | |
724 if (old_prerender_handle) | |
725 old_prerender_handle->OnCancel(); | |
726 | |
727 RecordEvent(EVENT_ADD_VISIT_PRERENDERING); | |
728 if (current_prerender_.get() && current_prerender_->url_id == url_id) { | |
729 RecordEvent(EVENT_ADD_VISIT_PRERENDERING_EXTENDED); | |
730 if (priority > current_prerender_->priority) | |
731 current_prerender_->priority = priority; | |
732 // If the prerender already existed, we want to extend it. However, | |
733 // we do not want to set its start_time to the current time to | |
734 // disadvantage PLT computations when the prerender is swapped in. | |
735 // So we set the new start time to current_time - 10s (since the vast | |
736 // majority of PLTs are < 10s), provided that is not before the actual | |
737 // time the prerender was started (so as to not artificially advantage | |
738 // the PLT computation). | |
739 base::Time simulated_new_start_time = | |
740 current_time - base::TimeDelta::FromSeconds(10); | |
741 if (simulated_new_start_time > current_prerender_->start_time) | |
742 current_prerender_->start_time = simulated_new_start_time; | |
743 } else { | |
744 current_prerender_.reset( | |
745 new PrerenderProperties(url_id, url, priority, current_time)); | |
746 } | |
747 current_prerender_->actual_start_time = current_time; | |
514 } | 748 } |
515 | 749 |
516 } // namespace prerender | 750 } // namespace prerender |
OLD | NEW |