Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: chrome/browser/net/predictor.cc

Issue 8589012: base::Bind fixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/predictor.h" 5 #include "chrome/browser/net/predictor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <set> 9 #include <set>
10 #include <sstream> 10 #include <sstream>
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 const UrlList& startup_urls, 693 const UrlList& startup_urls,
694 base::ListValue* referral_list, 694 base::ListValue* referral_list,
695 IOThread* io_thread, 695 IOThread* io_thread,
696 bool predictor_enabled) { 696 bool predictor_enabled) {
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
698 698
699 predictor_enabled_ = predictor_enabled; 699 predictor_enabled_ = predictor_enabled;
700 initial_observer_.reset(new InitialObserver()); 700 initial_observer_.reset(new InitialObserver());
701 host_resolver_ = io_thread->globals()->host_resolver.get(); 701 host_resolver_ = io_thread->globals()->host_resolver.get();
702 702
703 // ScopedRunnableMethodFactory instances need to be created and destroyed 703 // ScopedRunnableMethodFactory instances need to be created and destroyed
wtc 2011/11/17 08:16:21 This comment should not mention ScopedRunnableMeth
704 // on the same thread. The predictor lives on the IO thread and will die 704 // on the same thread. The predictor lives on the IO thread and will die
705 // from there so now that we're on the IO thread we need to properly 705 // from there so now that we're on the IO thread we need to properly
706 // initialize the ScopedrunnableMethodFactory. 706 // initialize the ScopedrunnableMethodFactory.
707 trim_task_factory_.reset(new ScopedRunnableMethodFactory<Predictor>(this)); 707 // TODO(groby): Check if WeakPtrFactory has the same constraint.
708 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this));
708 709
709 // Prefetch these hostnames on startup. 710 // Prefetch these hostnames on startup.
710 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); 711 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED);
711 DeserializeReferrersThenDelete(referral_list); 712 DeserializeReferrersThenDelete(referral_list);
712 } 713 }
713 714
714 //----------------------------------------------------------------------------- 715 //-----------------------------------------------------------------------------
715 // This section intermingles prefetch results with actual browser HTTP 716 // This section intermingles prefetch results with actual browser HTTP
716 // network activity. It supports calculating of the benefit of a prefetch, as 717 // network activity. It supports calculating of the benefit of a prefetch, as
717 // well as recording what prefetched hostname resolutions might be potentially 718 // well as recording what prefetched hostname resolutions might be potentially
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 it != referrers_.end(); ++it) 1051 it != referrers_.end(); ++it)
1051 urls_being_trimmed_.push_back(it->first); 1052 urls_being_trimmed_.push_back(it->first);
1052 UMA_HISTOGRAM_COUNTS("Net.PredictionTrimSize", urls_being_trimmed_.size()); 1053 UMA_HISTOGRAM_COUNTS("Net.PredictionTrimSize", urls_being_trimmed_.size());
1053 } 1054 }
1054 1055
1055 void Predictor::PostIncrementalTrimTask() { 1056 void Predictor::PostIncrementalTrimTask() {
1056 if (urls_being_trimmed_.empty()) 1057 if (urls_being_trimmed_.empty())
1057 return; 1058 return;
1058 MessageLoop::current()->PostDelayedTask( 1059 MessageLoop::current()->PostDelayedTask(
1059 FROM_HERE, 1060 FROM_HERE,
1060 trim_task_factory_->NewRunnableMethod( 1061 base::Bind(&Predictor::IncrementalTrimReferrers,
1061 &Predictor::IncrementalTrimReferrers, false), 1062 weak_factory_->GetWeakPtr(), false),
1062 kDurationBetweenTrimmingIncrements.InMilliseconds()); 1063 kDurationBetweenTrimmingIncrements.InMilliseconds());
1063 } 1064 }
1064 1065
1065 void Predictor::IncrementalTrimReferrers(bool trim_all_now) { 1066 void Predictor::IncrementalTrimReferrers(bool trim_all_now) {
1066 size_t trim_count = urls_being_trimmed_.size(); 1067 size_t trim_count = urls_being_trimmed_.size();
1067 if (!trim_all_now) 1068 if (!trim_all_now)
1068 trim_count = std::min(trim_count, kUrlsTrimmedPerIncrement); 1069 trim_count = std::min(trim_count, kUrlsTrimmedPerIncrement);
1069 while (trim_count-- != 0) { 1070 while (trim_count-- != 0) {
1070 Referrers::iterator it = referrers_.find(urls_being_trimmed_.back()); 1071 Referrers::iterator it = referrers_.find(urls_being_trimmed_.back());
1071 urls_being_trimmed_.pop_back(); 1072 urls_being_trimmed_.pop_back();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 PrefService* local_state, 1208 PrefService* local_state,
1208 IOThread* io_thread) { 1209 IOThread* io_thread) {
1209 // Empty function for unittests. 1210 // Empty function for unittests.
1210 } 1211 }
1211 1212
1212 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) { 1213 void SimplePredictor::ShutdownOnUIThread(PrefService* user_prefs) {
1213 SetShutdown(true); 1214 SetShutdown(true);
1214 } 1215 }
1215 1216
1216 } // namespace chrome_browser_net 1217 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698