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

Unified Diff: chrome/browser/net/predictor.cc

Issue 2950533002: android: Disable the startup DNS resolutions. (Closed)
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/predictor.cc
diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc
index 566818448a5ca13bba5baa48e56c8e0ad055ca52..be2f921ea9413325aa5fba94618ba67a40c0e31d 100644
--- a/chrome/browser/net/predictor.cc
+++ b/chrome/browser/net/predictor.cc
@@ -27,7 +27,9 @@
#include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
+#include "base/trace_event/trace_event.h"
Charlie Harrison 2017/06/20 13:24:29 Is it used?
Benoit L 2017/06/20 13:30:17 Yes, there is a TRACE_EVENT0() added below.
Charlie Harrison 2017/06/20 13:32:22 Ahh sorry. It's early :)
#include "base/values.h"
+#include "build/build_config.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile_io_data.h"
@@ -60,6 +62,15 @@ namespace {
const base::Feature kNetworkPrediction{"NetworkPrediction",
base::FEATURE_ENABLED_BY_DEFAULT};
+#if defined(OS_ANDROID)
+// Disabled on Android, as there are no "pinned tabs", meaning that a startup
+// is unlikely to request the same URL, and hence to resolve the same domains
+// as the previous one.
+constexpr bool kInitialDnsPrefetchListEnabled = false;
+#else
+constexpr bool kInitialDnsPrefetchListEnabled = true;
+#endif // defined(OS_ANDROID)
+
} // namespace
// static
@@ -506,7 +517,7 @@ void Predictor::GetHtmlReferrerLists(std::string* output) {
void Predictor::GetHtmlInfo(std::string* output) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (initial_observer_.get())
+ if (initial_observer_)
initial_observer_->GetFirstResolutionsHtml(output);
// Show list of subresource predictions and stats.
GetHtmlReferrerLists(output);
@@ -587,7 +598,7 @@ void Predictor::DeserializeReferrers(const base::ListValue& referral_list) {
void Predictor::DiscardInitialNavigationHistory() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (initial_observer_.get())
+ if (initial_observer_)
initial_observer_->DiscardInitialNavigationHistory();
}
@@ -597,9 +608,11 @@ void Predictor::FinalizeInitializationOnIOThread(
IOThread* io_thread,
ProfileIOData* profile_io_data) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ TRACE_EVENT0("net", "Predictor::FinalizeInitializationOnIOThread");
profile_io_data_ = profile_io_data;
- initial_observer_.reset(new InitialObserver());
+ if (kInitialDnsPrefetchListEnabled)
+ initial_observer_ = base::MakeUnique<InitialObserver>();
net::URLRequestContext* context =
url_request_context_getter_->GetURLRequestContext();
@@ -612,7 +625,8 @@ void Predictor::FinalizeInitializationOnIOThread(
io_weak_factory_.reset(new base::WeakPtrFactory<Predictor>(this));
// Prefetch these hostnames on startup.
- DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED);
+ if (kInitialDnsPrefetchListEnabled)
+ DnsPrefetchMotivatedList(startup_urls, UrlInfo::STARTUP_LIST_MOTIVATED);
DeserializeReferrers(*referral_list);
@@ -628,8 +642,8 @@ void Predictor::FinalizeInitializationOnIOThread(
void Predictor::LearnAboutInitialNavigation(const GURL& url) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (!PredictorEnabled() || nullptr == initial_observer_.get() ||
- !CanPreresolveAndPreconnect()) {
+ if (!PredictorEnabled() || !kInitialDnsPrefetchListEnabled ||
+ !initial_observer_ || !CanPreresolveAndPreconnect()) {
return;
}
initial_observer_->Append(url, this);
@@ -683,8 +697,8 @@ void Predictor::SaveStateForNextStartup() {
if (!CanPreresolveAndPreconnect())
return;
- std::unique_ptr<base::ListValue> startup_list(new base::ListValue);
- std::unique_ptr<base::ListValue> referral_list(new base::ListValue);
+ auto startup_list = base::MakeUnique<base::ListValue>();
+ auto referral_list = base::MakeUnique<base::ListValue>();
// Get raw pointers to pass to the first task. Ownership of the unique_ptrs
// will be passed to the reply task.
@@ -708,13 +722,15 @@ void Predictor::UpdatePrefsOnUIThread(
std::unique_ptr<base::ListValue> referral_list) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
user_prefs_->Set(prefs::kDnsPrefetchingStartupList, *startup_list);
+ // May be empty if kInitialDnsPrefetchListEnabled is false. Still update the
+ // prefs to clear the state.
user_prefs_->Set(prefs::kDnsPrefetchingHostReferralList, *referral_list);
}
void Predictor::WriteDnsPrefetchState(base::ListValue* startup_list,
base::ListValue* referral_list) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (initial_observer_.get())
+ if (initial_observer_)
initial_observer_->GetInitialDnsResolutionList(startup_list);
SerializeReferrers(referral_list);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698