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

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

Issue 2085643002: Don't clear the net predictors prefs on startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dont clear prefs on startup Created 4 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>
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 net::URLRequestContextGetter* getter, 150 net::URLRequestContextGetter* getter,
151 ProfileIOData* profile_io_data) { 151 ProfileIOData* profile_io_data) {
152 DCHECK_CURRENTLY_ON(BrowserThread::UI); 152 DCHECK_CURRENTLY_ON(BrowserThread::UI);
153 153
154 user_prefs_ = user_prefs; 154 user_prefs_ = user_prefs;
155 url_request_context_getter_ = getter; 155 url_request_context_getter_ = getter;
156 156
157 // Gather the list of hostnames to prefetch on startup. 157 // Gather the list of hostnames to prefetch on startup.
158 std::vector<GURL> urls = GetPredictedUrlListAtStartup(user_prefs); 158 std::vector<GURL> urls = GetPredictedUrlListAtStartup(user_prefs);
159 159
160 base::ListValue* referral_list = 160 const base::ListValue* referral_list =
161 static_cast<base::ListValue*>(user_prefs->GetList( 161 user_prefs->GetList(prefs::kDnsPrefetchingHostReferralList);
162 prefs::kDnsPrefetchingHostReferralList)->DeepCopy());
163
164 // Now that we have the statistics in memory, wipe them from the Preferences
165 // file. They will be serialized back on a clean shutdown. This way we only
166 // have to worry about clearing our in-memory state when Clearing Browsing
167 // Data.
168 user_prefs->ClearPref(prefs::kDnsPrefetchingStartupList);
169 user_prefs->ClearPref(prefs::kDnsPrefetchingHostReferralList);
170 162
171 BrowserThread::PostTask( 163 BrowserThread::PostTask(
172 BrowserThread::IO, 164 BrowserThread::IO,
173 FROM_HERE, 165 FROM_HERE,
174 base::Bind( 166 base::Bind(
175 &Predictor::FinalizeInitializationOnIOThread, 167 &Predictor::FinalizeInitializationOnIOThread,
176 base::Unretained(this), 168 base::Unretained(this),
177 urls, referral_list, 169 urls, referral_list,
178 io_thread, profile_io_data)); 170 io_thread, profile_io_data));
179 } 171 }
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 if (!motivator->Get(1, &subresource_list)) { 611 if (!motivator->Get(1, &subresource_list)) {
620 NOTREACHED(); 612 NOTREACHED();
621 return; 613 return;
622 } 614 }
623 615
624 referrers_[GURL(motivating_url_spec)].Deserialize(*subresource_list); 616 referrers_[GURL(motivating_url_spec)].Deserialize(*subresource_list);
625 } 617 }
626 } 618 }
627 } 619 }
628 620
629 void Predictor::DeserializeReferrersThenDelete(
630 base::ListValue* referral_list) {
631 DeserializeReferrers(*referral_list);
632 delete referral_list;
633 }
634
635 void Predictor::DiscardInitialNavigationHistory() { 621 void Predictor::DiscardInitialNavigationHistory() {
636 DCHECK_CURRENTLY_ON(BrowserThread::IO); 622 DCHECK_CURRENTLY_ON(BrowserThread::IO);
637 if (initial_observer_.get()) 623 if (initial_observer_.get())
638 initial_observer_->DiscardInitialNavigationHistory(); 624 initial_observer_->DiscardInitialNavigationHistory();
639 } 625 }
640 626
641 void Predictor::FinalizeInitializationOnIOThread( 627 void Predictor::FinalizeInitializationOnIOThread(
642 const std::vector<GURL>& startup_urls, 628 const std::vector<GURL>& startup_urls,
643 base::ListValue* referral_list, 629 const base::ListValue* referral_list,
644 IOThread* io_thread, 630 IOThread* io_thread,
645 ProfileIOData* profile_io_data) { 631 ProfileIOData* profile_io_data) {
646 DCHECK_CURRENTLY_ON(BrowserThread::IO); 632 DCHECK_CURRENTLY_ON(BrowserThread::IO);
647 633
648 profile_io_data_ = profile_io_data; 634 profile_io_data_ = profile_io_data;
649 initial_observer_.reset(new InitialObserver()); 635 initial_observer_.reset(new InitialObserver());
650 636
651 net::URLRequestContext* context = 637 net::URLRequestContext* context =
652 url_request_context_getter_->GetURLRequestContext(); 638 url_request_context_getter_->GetURLRequestContext();
653 transport_security_state_ = context->transport_security_state(); 639 transport_security_state_ = context->transport_security_state();
654 ssl_config_service_ = context->ssl_config_service(); 640 ssl_config_service_ = context->ssl_config_service();
655 proxy_service_ = context->proxy_service(); 641 proxy_service_ = context->proxy_service();
656 642
657 // base::WeakPtrFactory instances need to be created and destroyed 643 // base::WeakPtrFactory instances need to be created and destroyed
658 // on the same thread. The predictor lives on the IO thread and will die 644 // on the same thread. The predictor lives on the IO thread and will die
659 // from there so now that we're on the IO thread we need to properly 645 // from there so now that we're on the IO thread we need to properly
660 // initialize the base::WeakPtrFactory. 646 // initialize the base::WeakPtrFactory.
661 // TODO(groby): Check if WeakPtrFactory has the same constraint. 647 // TODO(groby): Check if WeakPtrFactory has the same constraint.
662 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this)); 648 weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this));
663 649
664 // Prefetch these hostnames on startup. 650 // Prefetch these hostnames on startup.
665 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED); 651 DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED);
666 652
667 DeserializeReferrersThenDelete(referral_list); 653 DeserializeReferrers(*referral_list);
668 654
669 LogStartupMetrics(); 655 LogStartupMetrics();
670 } 656 }
671 657
672 //----------------------------------------------------------------------------- 658 //-----------------------------------------------------------------------------
673 // This section intermingles prefetch results with actual browser HTTP 659 // This section intermingles prefetch results with actual browser HTTP
674 // network activity. It supports calculating of the benefit of a prefetch, as 660 // network activity. It supports calculating of the benefit of a prefetch, as
675 // well as recording what prefetched hostname resolutions might be potentially 661 // well as recording what prefetched hostname resolutions might be potentially
676 // helpful during the next chrome-startup. 662 // helpful during the next chrome-startup.
677 //----------------------------------------------------------------------------- 663 //-----------------------------------------------------------------------------
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 891
906 bool Predictor::CanPreresolveAndPreconnect() const { 892 bool Predictor::CanPreresolveAndPreconnect() const {
907 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 893 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
908 return chrome_browser_net::CanPreresolveAndPreconnectUI(user_prefs_); 894 return chrome_browser_net::CanPreresolveAndPreconnectUI(user_prefs_);
909 } else { 895 } else {
910 DCHECK_CURRENTLY_ON(BrowserThread::IO); 896 DCHECK_CURRENTLY_ON(BrowserThread::IO);
911 return chrome_browser_net::CanPreresolveAndPreconnectIO(profile_io_data_); 897 return chrome_browser_net::CanPreresolveAndPreconnectIO(profile_io_data_);
912 } 898 }
913 } 899 }
914 900
901 void Predictor::ClearPrefsOnUIThread() {
902 DCHECK_CURRENTLY_ON(BrowserThread::UI);
903 user_prefs_->ClearPref(prefs::kDnsPrefetchingStartupList);
904 user_prefs_->ClearPref(prefs::kDnsPrefetchingHostReferralList);
905 }
906
915 enum SubresourceValue { 907 enum SubresourceValue {
916 PRECONNECTION, 908 PRECONNECTION,
917 PRERESOLUTION, 909 PRERESOLUTION,
918 TOO_NEW, 910 TOO_NEW,
919 SUBRESOURCE_VALUE_MAX 911 SUBRESOURCE_VALUE_MAX
920 }; 912 };
921 913
922 void Predictor::PrepareFrameSubresources(const GURL& original_url, 914 void Predictor::PrepareFrameSubresources(const GURL& original_url,
923 const GURL& first_party_for_cookies) { 915 const GURL& first_party_for_cookies) {
924 // Apply HSTS redirect early so it is taken into account when looking up 916 // Apply HSTS redirect early so it is taken into account when looking up
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 } 1313 }
1322 1314
1323 void SimplePredictor::ShutdownOnUIThread() { 1315 void SimplePredictor::ShutdownOnUIThread() {
1324 SetShutdown(true); 1316 SetShutdown(true);
1325 } 1317 }
1326 1318
1327 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1319 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1328 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1320 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1329 1321
1330 } // namespace chrome_browser_net 1322 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698