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