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

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

Issue 2084093002: Use lossy prefs in the net predictor, and update them more frequently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@predictor_lru
Patch Set: Fix browser tests Created 4 years, 4 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 <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
11 #include <sstream> 11 #include <sstream>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback.h"
15 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
16 #include "base/containers/mru_cache.h" 17 #include "base/containers/mru_cache.h"
17 #include "base/location.h" 18 #include "base/location.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #include "base/macros.h" 20 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 21 #include "base/memory/ptr_util.h"
21 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
22 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
23 #include "base/stl_util.h" 24 #include "base/stl_util.h"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 Predictor* Predictor::CreatePredictor(bool preconnect_enabled, 122 Predictor* Predictor::CreatePredictor(bool preconnect_enabled,
122 bool predictor_enabled, 123 bool predictor_enabled,
123 bool simple_shutdown) { 124 bool simple_shutdown) {
124 if (simple_shutdown) 125 if (simple_shutdown)
125 return new SimplePredictor(preconnect_enabled, predictor_enabled); 126 return new SimplePredictor(preconnect_enabled, predictor_enabled);
126 return new Predictor(preconnect_enabled, predictor_enabled); 127 return new Predictor(preconnect_enabled, predictor_enabled);
127 } 128 }
128 129
129 void Predictor::RegisterProfilePrefs( 130 void Predictor::RegisterProfilePrefs(
130 user_prefs::PrefRegistrySyncable* registry) { 131 user_prefs::PrefRegistrySyncable* registry) {
131 registry->RegisterListPref(prefs::kDnsPrefetchingStartupList); 132 registry->RegisterListPref(prefs::kDnsPrefetchingStartupList,
132 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList); 133 PrefRegistry::LOSSY_PREF);
134 registry->RegisterListPref(prefs::kDnsPrefetchingHostReferralList,
135 PrefRegistry::LOSSY_PREF);
133 } 136 }
134 137
135 // --------------------- Start UI methods. ------------------------------------ 138 // --------------------- Start UI methods. ------------------------------------
136 139
137 void Predictor::InitNetworkPredictor(PrefService* user_prefs, 140 void Predictor::InitNetworkPredictor(PrefService* user_prefs,
138 IOThread* io_thread, 141 IOThread* io_thread,
139 net::URLRequestContextGetter* getter, 142 net::URLRequestContextGetter* getter,
140 ProfileIOData* profile_io_data) { 143 ProfileIOData* profile_io_data) {
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); 144 DCHECK_CURRENTLY_ON(BrowserThread::UI);
142 145
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 FROM_HERE, 669 FROM_HERE,
667 base::Bind(&Predictor::ResolveList, base::Unretained(this), 670 base::Bind(&Predictor::ResolveList, base::Unretained(this),
668 urls, motivation)); 671 urls, motivation));
669 } 672 }
670 } 673 }
671 674
672 //----------------------------------------------------------------------------- 675 //-----------------------------------------------------------------------------
673 // Functions to handle saving of hostnames from one session to the next, to 676 // Functions to handle saving of hostnames from one session to the next, to
674 // expedite startup times. 677 // expedite startup times.
675 678
676 static void SaveDnsPrefetchStateForNextStartupOnIOThread( 679 static void RetainUpdateClosure(ListPrefUpdate* update_startup_list,
Bernhard Bauer 2016/07/29 11:07:53 Move this to an anonymous namespace?
Charlie Harrison 2016/07/29 13:42:13 This was changed to actually perform the update, s
677 base::ListValue* startup_list, 680 ListPrefUpdate* update_referral_list) {}
678 base::ListValue* referral_list,
679 base::WaitableEvent* completion,
680 Predictor* predictor) {
681 DCHECK_CURRENTLY_ON(BrowserThread::IO);
682
683 if (nullptr == predictor) {
684 completion->Signal();
685 return;
686 }
687 predictor->SaveDnsPrefetchStateForNextStartup(startup_list, referral_list,
688 completion);
689 }
690 681
691 void Predictor::SaveStateForNextStartup() { 682 void Predictor::SaveStateForNextStartup() {
692 if (!predictor_enabled_) 683 DCHECK_CURRENTLY_ON(BrowserThread::UI);
693 return; 684 if (!predictor_enabled_ || !CanPreresolveAndPreconnect())
694 if (!CanPreresolveAndPreconnect())
695 return; 685 return;
696 686
697 base::WaitableEvent completion( 687 ListPrefUpdate* update_startup_list =
Bernhard Bauer 2016/07/29 11:07:53 This is not allowed, because ownership of the retu
Charlie Harrison 2016/07/29 13:42:13 Thanks this is a good suggestion. We can clear the
Bernhard Bauer 2016/07/29 14:08:14 Hm, that's a tricky one. Like I said, it all depen
Charlie Harrison 2016/07/29 16:50:12 Hm okay so I chatted with mmenke@ about this (cced
698 base::WaitableEvent::ResetPolicy::MANUAL, 688 new ListPrefUpdate(user_prefs_, prefs::kDnsPrefetchingStartupList);
699 base::WaitableEvent::InitialState::NOT_SIGNALED); 689 ListPrefUpdate* update_referral_list =
700 690 new ListPrefUpdate(user_prefs_, prefs::kDnsPrefetchingHostReferralList);
701 ListPrefUpdate update_startup_list(user_prefs_, 691 BrowserThread::PostTaskAndReply(
702 prefs::kDnsPrefetchingStartupList); 692 BrowserThread::IO, FROM_HERE,
703 ListPrefUpdate update_referral_list(user_prefs_, 693 base::Bind(&Predictor::SaveDnsPrefetchStateForNextStartup,
704 prefs::kDnsPrefetchingHostReferralList); 694 weak_factory_->GetWeakPtr(), update_startup_list->Get(),
705 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { 695 update_referral_list->Get()),
Bernhard Bauer 2016/07/29 11:07:53 Thanks for cleaning this up, BTW! This looks like
Charlie Harrison 2016/07/29 13:42:13 No problem, this also triggers a synchronous threa
706 SaveDnsPrefetchStateForNextStartupOnIOThread(update_startup_list.Get(), 696 base::Bind(&RetainUpdateClosure, base::Owned(update_startup_list),
707 update_referral_list.Get(), 697 base::Owned(update_referral_list)));
708 &completion, this);
709 } else {
710 bool posted = BrowserThread::PostTask(
711 BrowserThread::IO, FROM_HERE,
712 base::Bind(&SaveDnsPrefetchStateForNextStartupOnIOThread,
713 update_startup_list.Get(), update_referral_list.Get(),
714 &completion, this));
715
716 // TODO(jar): Synchronous waiting for the IO thread is a potential source
717 // to deadlocks and should be investigated. See http://crbug.com/78451.
718 DCHECK(posted);
719 if (posted) {
720 // http://crbug.com/124954
721 base::ThreadRestrictions::ScopedAllowWait allow_wait;
722 completion.Wait();
723 }
724 }
725 } 698 }
726 699
727 void Predictor::SaveDnsPrefetchStateForNextStartup( 700 void Predictor::SaveDnsPrefetchStateForNextStartup(
728 base::ListValue* startup_list, 701 base::ListValue* startup_list,
729 base::ListValue* referral_list, 702 base::ListValue* referral_list) {
730 base::WaitableEvent* completion) {
731 DCHECK_CURRENTLY_ON(BrowserThread::IO); 703 DCHECK_CURRENTLY_ON(BrowserThread::IO);
732 if (initial_observer_.get()) 704 if (initial_observer_.get())
733 initial_observer_->GetInitialDnsResolutionList(startup_list); 705 initial_observer_->GetInitialDnsResolutionList(startup_list);
734 706
735 SerializeReferrers(referral_list); 707 SerializeReferrers(referral_list);
736
737 completion->Signal();
738 } 708 }
739 709
740 void Predictor::PreconnectUrl(const GURL& url, 710 void Predictor::PreconnectUrl(const GURL& url,
741 const GURL& first_party_for_cookies, 711 const GURL& first_party_for_cookies,
742 UrlInfo::ResolutionMotivation motivation, 712 UrlInfo::ResolutionMotivation motivation,
743 bool allow_credentials, 713 bool allow_credentials,
744 int count) { 714 int count) {
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
746 BrowserThread::CurrentlyOn(BrowserThread::IO)); 716 BrowserThread::CurrentlyOn(BrowserThread::IO));
747 717
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 } 1194 }
1225 1195
1226 void SimplePredictor::ShutdownOnUIThread() { 1196 void SimplePredictor::ShutdownOnUIThread() {
1227 SetShutdown(true); 1197 SetShutdown(true);
1228 } 1198 }
1229 1199
1230 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1200 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1231 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1201 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1232 1202
1233 } // namespace chrome_browser_net 1203 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698