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_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 PrerenderManager::PrerenderManager(Profile* profile, | 234 PrerenderManager::PrerenderManager(Profile* profile, |
235 PrerenderTracker* prerender_tracker) | 235 PrerenderTracker* prerender_tracker) |
236 : enabled_(profile && profile->GetPrefs() && | 236 : enabled_(profile && profile->GetPrefs() && |
237 profile->GetPrefs()->GetBoolean(prefs::kNetworkPredictionEnabled)), | 237 profile->GetPrefs()->GetBoolean(prefs::kNetworkPredictionEnabled)), |
238 profile_(profile), | 238 profile_(profile), |
239 prerender_tracker_(prerender_tracker), | 239 prerender_tracker_(prerender_tracker), |
240 prerender_contents_factory_(PrerenderContents::CreateFactory()), | 240 prerender_contents_factory_(PrerenderContents::CreateFactory()), |
241 last_prerender_start_time_(GetCurrentTimeTicks() - | 241 last_prerender_start_time_(GetCurrentTimeTicks() - |
242 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), | 242 base::TimeDelta::FromMilliseconds(kMinTimeBetweenPrerendersMs)), |
243 prerender_history_(new PrerenderHistory(kHistoryLength)), | 243 prerender_history_(new PrerenderHistory(kHistoryLength)), |
244 histograms_(new PrerenderHistograms()) { | 244 histograms_(new PrerenderHistograms()), |
245 profile_network_bytes_(0), | |
246 last_recorded_profile_network_bytes_(0) { | |
245 // There are some assumptions that the PrerenderManager is on the UI thread. | 247 // There are some assumptions that the PrerenderManager is on the UI thread. |
246 // Any other checks simply make sure that the PrerenderManager is accessed on | 248 // Any other checks simply make sure that the PrerenderManager is accessed on |
247 // the same thread that it was created on. | 249 // the same thread that it was created on. |
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
249 | 251 |
250 if (IsLocalPredictorEnabled()) | 252 if (IsLocalPredictorEnabled()) |
251 local_predictor_.reset(new PrerenderLocalPredictor(this)); | 253 local_predictor_.reset(new PrerenderLocalPredictor(this)); |
252 | 254 |
253 if (IsLoggedInPredictorEnabled() && !profile_->IsOffTheRecord()) { | 255 if (IsLoggedInPredictorEnabled() && !profile_->IsOffTheRecord()) { |
254 predictors::PredictorDatabase* predictor_db = | 256 predictors::PredictorDatabase* predictor_db = |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1760 const history::URLRow* url_row, | 1762 const history::URLRow* url_row, |
1761 history::VisitVector* visists) { | 1763 history::VisitVector* visists) { |
1762 histograms_->RecordPrerenderPageVisitedStatus(origin, experiment_id, success); | 1764 histograms_->RecordPrerenderPageVisitedStatus(origin, experiment_id, success); |
1763 } | 1765 } |
1764 | 1766 |
1765 // static | 1767 // static |
1766 void PrerenderManager::HangSessionStorageMergesForTesting() { | 1768 void PrerenderManager::HangSessionStorageMergesForTesting() { |
1767 g_hang_session_storage_merges_for_testing = true; | 1769 g_hang_session_storage_merges_for_testing = true; |
1768 } | 1770 } |
1769 | 1771 |
1772 void PrerenderManager::RecordNetworkBytes(bool used, int64 prerender_bytes) { | |
1773 if (!ActuallyPrerendering()) | |
1774 return; | |
1775 int64 recent_profile_bytes = | |
tburkard
2014/02/13 13:39:35
Maybe add a DCHECK that recent_profile_bytes is >=
jkarlin
2014/02/13 13:48:09
Done.
| |
1776 profile_network_bytes_ - last_recorded_profile_network_bytes_; | |
1777 last_recorded_profile_network_bytes_ = profile_network_bytes_; | |
1778 histograms_->RecordNetworkBytes(used, prerender_bytes, recent_profile_bytes); | |
1779 } | |
1780 | |
1781 void PrerenderManager::AddProfileNetworkBytesIfEnabled(int64 bytes) { | |
1782 if (IsEnabled() && ActuallyPrerendering()) | |
1783 profile_network_bytes_ += bytes; | |
tburkard
2014/02/13 13:39:35
Add a DCHECK that bytes is >= 0.
jkarlin
2014/02/13 13:48:09
Done.
| |
1784 } | |
1785 | |
1770 } // namespace prerender | 1786 } // namespace prerender |
OLD | NEW |