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

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

Issue 5800004: Migrate HostReferralList and StartupDNSPrefetchList from local_state to user ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years 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
« no previous file with comments | « chrome/browser/net/predictor_api.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_api.h" 5 #include "chrome/browser/net/predictor_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 void OnTheRecord(bool enable) { 127 void OnTheRecord(bool enable) {
128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
129 if (on_the_record_switch == enable) 129 if (on_the_record_switch == enable)
130 return; 130 return;
131 on_the_record_switch = enable; 131 on_the_record_switch = enable;
132 if (on_the_record_switch) 132 if (on_the_record_switch)
133 g_browser_process->io_thread()->ChangedToOnTheRecord(); 133 g_browser_process->io_thread()->ChangedToOnTheRecord();
134 } 134 }
135 135
136 void RegisterPrefs(PrefService* local_state) {
137 local_state->RegisterListPref(prefs::kDnsStartupPrefetchList);
138 local_state->RegisterListPref(prefs::kDnsHostReferralList);
139 }
140
141 void RegisterUserPrefs(PrefService* user_prefs) { 136 void RegisterUserPrefs(PrefService* user_prefs) {
137 user_prefs->RegisterListPref(prefs::kDnsPrefetchingStartupList);
138 user_prefs->RegisterListPref(prefs::kDnsPrefetchingHostReferralList);
142 user_prefs->RegisterBooleanPref(prefs::kDnsPrefetchingEnabled, true); 139 user_prefs->RegisterBooleanPref(prefs::kDnsPrefetchingEnabled, true);
143 } 140 }
144 141
145 // When enabled, we use the following instance to service all requests in the 142 // When enabled, we use the following instance to service all requests in the
146 // browser process. 143 // browser process.
147 // TODO(willchan): Look at killing this. 144 // TODO(willchan): Look at killing this.
148 static Predictor* g_predictor = NULL; 145 static Predictor* g_predictor = NULL;
149 146
150 // This API is only used in the browser process. 147 // This API is only used in the browser process.
151 // It is called from an IPC message originating in the renderer. It currently 148 // It is called from an IPC message originating in the renderer. It currently
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
387 384
388 bool prefetching_enabled = 385 bool prefetching_enabled =
389 user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); 386 user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled);
390 387
391 // Gather the list of hostnames to prefetch on startup. 388 // Gather the list of hostnames to prefetch on startup.
392 UrlList urls = 389 UrlList urls =
393 GetPredictedUrlListAtStartup(user_prefs, local_state); 390 GetPredictedUrlListAtStartup(user_prefs, local_state);
394 391
395 ListValue* referral_list = 392 ListValue* referral_list =
396 static_cast<ListValue*>( 393 static_cast<ListValue*>(user_prefs->GetMutableList(
397 local_state->GetMutableList(prefs::kDnsHostReferralList)->DeepCopy()); 394 prefs::kDnsPrefetchingHostReferralList)->DeepCopy());
395
396 // Remove obsolete preferences from local state if necessary.
397 int dns_prefs_version =
398 user_prefs->GetInteger(prefs::kMultipleProfilePrefMigration);
399 if (dns_prefs_version < 1) {
400 // These prefs only need to be registered if they need to be cleared from
401 // local state.
402 local_state->RegisterListPref(prefs::kDnsStartupPrefetchList);
403 local_state->RegisterListPref(prefs::kDnsHostReferralList);
404 local_state->ClearPref(prefs::kDnsStartupPrefetchList);
405 local_state->ClearPref(prefs::kDnsHostReferralList);
406 user_prefs->SetInteger(prefs::kMultipleProfilePrefMigration, 1);
407 }
398 408
399 g_browser_process->io_thread()->InitNetworkPredictor( 409 g_browser_process->io_thread()->InitNetworkPredictor(
400 prefetching_enabled, max_dns_queue_delay, max_parallel_resolves, urls, 410 prefetching_enabled, max_dns_queue_delay, max_parallel_resolves, urls,
401 referral_list, preconnect_enabled); 411 referral_list, preconnect_enabled);
402 } 412 }
403 413
404 void FinalizePredictorInitialization( 414 void FinalizePredictorInitialization(
405 Predictor* global_predictor, 415 Predictor* global_predictor,
406 const UrlList& startup_urls, 416 const UrlList& startup_urls,
407 ListValue* referral_list) { 417 ListValue* referral_list) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 465
456 if (!predictor_enabled || g_predictor == NULL) 466 if (!predictor_enabled || g_predictor == NULL)
457 return; 467 return;
458 468
459 base::WaitableEvent completion(true, false); 469 base::WaitableEvent completion(true, false);
460 470
461 bool posted = BrowserThread::PostTask( 471 bool posted = BrowserThread::PostTask(
462 BrowserThread::IO, 472 BrowserThread::IO,
463 FROM_HERE, 473 FROM_HERE,
464 NewRunnableFunction(SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread, 474 NewRunnableFunction(SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread,
465 prefs->GetMutableList(prefs::kDnsStartupPrefetchList), 475 prefs->GetMutableList(prefs::kDnsPrefetchingStartupList),
466 prefs->GetMutableList(prefs::kDnsHostReferralList), 476 prefs->GetMutableList(prefs::kDnsPrefetchingHostReferralList),
467 &completion)); 477 &completion));
468 478
469 DCHECK(posted); 479 DCHECK(posted);
470 if (posted) 480 if (posted)
471 completion.Wait(); 481 completion.Wait();
472 } 482 }
473 483
474 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, 484 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs,
475 PrefService* local_state) { 485 PrefService* local_state) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
477 UrlList urls; 487 UrlList urls;
478 // Recall list of URLs we learned about during last session. 488 // Recall list of URLs we learned about during last session.
479 // This may catch secondary hostnames, pulled in by the homepages. It will 489 // This may catch secondary hostnames, pulled in by the homepages. It will
480 // also catch more of the "primary" home pages, since that was (presumably) 490 // also catch more of the "primary" home pages, since that was (presumably)
481 // rendered first (and will be rendered first this time too). 491 // rendered first (and will be rendered first this time too).
482 ListValue* startup_list = 492 ListValue* startup_list =
483 local_state->GetMutableList(prefs::kDnsStartupPrefetchList); 493 user_prefs->GetMutableList(prefs::kDnsPrefetchingStartupList);
494
484 if (startup_list) { 495 if (startup_list) {
485 ListValue::iterator it = startup_list->begin(); 496 ListValue::iterator it = startup_list->begin();
486 int format_version = -1; 497 int format_version = -1;
487 if (it != startup_list->end() && 498 if (it != startup_list->end() &&
488 (*it)->GetAsInteger(&format_version) && 499 (*it)->GetAsInteger(&format_version) &&
489 format_version == kPredictorStartupFormatVersion) { 500 format_version == kPredictorStartupFormatVersion) {
490 ++it; 501 ++it;
491 for (; it != startup_list->end(); ++it) { 502 for (; it != startup_list->end(); ++it) {
492 std::string url_spec; 503 std::string url_spec;
493 if (!(*it)->GetAsString(&url_spec)) { 504 if (!(*it)->GetAsString(&url_spec)) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 DCHECK(!g_predictor); 625 DCHECK(!g_predictor);
615 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, 626 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs,
616 local_state, preconnect_enabled); 627 local_state, preconnect_enabled);
617 } 628 }
618 } 629 }
619 630
620 PredictorInit::~PredictorInit() { 631 PredictorInit::~PredictorInit() {
621 } 632 }
622 633
623 } // namespace chrome_browser_net 634 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor_api.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698