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

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

Issue 1143343005: chrome/browser: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 months 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
OLDNEW
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/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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/containers/mru_cache.h" 15 #include "base/containers/mru_cache.h"
16 #include "base/location.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/prefs/pref_service.h" 19 #include "base/prefs/pref_service.h"
19 #include "base/prefs/scoped_user_pref_update.h" 20 #include "base/prefs/scoped_user_pref_update.h"
20 #include "base/profiler/scoped_tracker.h" 21 #include "base/profiler/scoped_tracker.h"
22 #include "base/single_thread_task_runner.h"
21 #include "base/stl_util.h" 23 #include "base/stl_util.h"
22 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
25 #include "base/synchronization/waitable_event.h" 27 #include "base/synchronization/waitable_event.h"
28 #include "base/thread_task_runner_handle.h"
26 #include "base/threading/thread_restrictions.h" 29 #include "base/threading/thread_restrictions.h"
27 #include "base/time/time.h" 30 #include "base/time/time.h"
28 #include "base/values.h" 31 #include "base/values.h"
29 #include "chrome/browser/io_thread.h" 32 #include "chrome/browser/io_thread.h"
30 #include "chrome/browser/net/preconnect.h" 33 #include "chrome/browser/net/preconnect.h"
31 #include "chrome/browser/prefs/session_startup_pref.h" 34 #include "chrome/browser/prefs/session_startup_pref.h"
32 #include "chrome/browser/profiles/profile_io_data.h" 35 #include "chrome/browser/profiles/profile_io_data.h"
33 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
35 #include "components/pref_registry/pref_registry_syncable.h" 38 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 it != referrers_.end(); ++it) 1138 it != referrers_.end(); ++it)
1136 urls_being_trimmed_.push_back(it->first); 1139 urls_being_trimmed_.push_back(it->first);
1137 UMA_HISTOGRAM_COUNTS("Net.PredictionTrimSize", urls_being_trimmed_.size()); 1140 UMA_HISTOGRAM_COUNTS("Net.PredictionTrimSize", urls_being_trimmed_.size());
1138 } 1141 }
1139 1142
1140 void Predictor::PostIncrementalTrimTask() { 1143 void Predictor::PostIncrementalTrimTask() {
1141 if (urls_being_trimmed_.empty()) 1144 if (urls_being_trimmed_.empty())
1142 return; 1145 return;
1143 const TimeDelta kDurationBetweenTrimmingIncrements = 1146 const TimeDelta kDurationBetweenTrimmingIncrements =
1144 TimeDelta::FromSeconds(kDurationBetweenTrimmingIncrementsSeconds); 1147 TimeDelta::FromSeconds(kDurationBetweenTrimmingIncrementsSeconds);
1145 base::MessageLoop::current()->PostDelayedTask( 1148 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1146 FROM_HERE, 1149 FROM_HERE, base::Bind(&Predictor::IncrementalTrimReferrers,
1147 base::Bind(&Predictor::IncrementalTrimReferrers, 1150 weak_factory_->GetWeakPtr(), false),
1148 weak_factory_->GetWeakPtr(), false),
1149 kDurationBetweenTrimmingIncrements); 1151 kDurationBetweenTrimmingIncrements);
1150 } 1152 }
1151 1153
1152 void Predictor::IncrementalTrimReferrers(bool trim_all_now) { 1154 void Predictor::IncrementalTrimReferrers(bool trim_all_now) {
1153 size_t trim_count = urls_being_trimmed_.size(); 1155 size_t trim_count = urls_being_trimmed_.size();
1154 if (!trim_all_now) 1156 if (!trim_all_now)
1155 trim_count = std::min(trim_count, kUrlsTrimmedPerIncrement); 1157 trim_count = std::min(trim_count, kUrlsTrimmedPerIncrement);
1156 while (trim_count-- != 0) { 1158 while (trim_count-- != 0) {
1157 Referrers::iterator it = referrers_.find(urls_being_trimmed_.back()); 1159 Referrers::iterator it = referrers_.find(urls_being_trimmed_.back());
1158 urls_being_trimmed_.pop_back(); 1160 urls_being_trimmed_.pop_back();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 } 1318 }
1317 1319
1318 void SimplePredictor::ShutdownOnUIThread() { 1320 void SimplePredictor::ShutdownOnUIThread() {
1319 SetShutdown(true); 1321 SetShutdown(true);
1320 } 1322 }
1321 1323
1322 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1324 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1323 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1325 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1324 1326
1325 } // namespace chrome_browser_net 1327 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context_getter.cc ('k') | chrome/browser/net/predictor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698