OLD | NEW |
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 Loading... |
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 |
136 void RegisterUserPrefs(PrefService* user_prefs) { | 141 void RegisterUserPrefs(PrefService* user_prefs) { |
137 user_prefs->RegisterListPref(prefs::kDnsPrefetchingStartupList); | |
138 user_prefs->RegisterListPref(prefs::kDnsPrefetchingHostReferralList); | |
139 user_prefs->RegisterBooleanPref(prefs::kDnsPrefetchingEnabled, true); | 142 user_prefs->RegisterBooleanPref(prefs::kDnsPrefetchingEnabled, true); |
140 } | 143 } |
141 | 144 |
142 // When enabled, we use the following instance to service all requests in the | 145 // When enabled, we use the following instance to service all requests in the |
143 // browser process. | 146 // browser process. |
144 // TODO(willchan): Look at killing this. | 147 // TODO(willchan): Look at killing this. |
145 static Predictor* g_predictor = NULL; | 148 static Predictor* g_predictor = NULL; |
146 | 149 |
147 // This API is only used in the browser process. | 150 // This API is only used in the browser process. |
148 // It is called from an IPC message originating in the renderer. It currently | 151 // 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 Loading... |
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
384 | 387 |
385 bool prefetching_enabled = | 388 bool prefetching_enabled = |
386 user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); | 389 user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); |
387 | 390 |
388 // Gather the list of hostnames to prefetch on startup. | 391 // Gather the list of hostnames to prefetch on startup. |
389 UrlList urls = | 392 UrlList urls = |
390 GetPredictedUrlListAtStartup(user_prefs, local_state); | 393 GetPredictedUrlListAtStartup(user_prefs, local_state); |
391 | 394 |
392 ListValue* referral_list = | 395 ListValue* referral_list = |
393 static_cast<ListValue*>(user_prefs->GetMutableList( | 396 static_cast<ListValue*>( |
394 prefs::kDnsPrefetchingHostReferralList)->DeepCopy()); | 397 local_state->GetMutableList(prefs::kDnsHostReferralList)->DeepCopy()); |
395 | |
396 // Remove obsolete preferences from local state if necessary. | |
397 bool 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 } | |
408 | 398 |
409 g_browser_process->io_thread()->InitNetworkPredictor( | 399 g_browser_process->io_thread()->InitNetworkPredictor( |
410 prefetching_enabled, max_dns_queue_delay, max_parallel_resolves, urls, | 400 prefetching_enabled, max_dns_queue_delay, max_parallel_resolves, urls, |
411 referral_list, preconnect_enabled); | 401 referral_list, preconnect_enabled); |
412 } | 402 } |
413 | 403 |
414 void FinalizePredictorInitialization( | 404 void FinalizePredictorInitialization( |
415 Predictor* global_predictor, | 405 Predictor* global_predictor, |
416 const UrlList& startup_urls, | 406 const UrlList& startup_urls, |
417 ListValue* referral_list) { | 407 ListValue* referral_list) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 455 |
466 if (!predictor_enabled || g_predictor == NULL) | 456 if (!predictor_enabled || g_predictor == NULL) |
467 return; | 457 return; |
468 | 458 |
469 base::WaitableEvent completion(true, false); | 459 base::WaitableEvent completion(true, false); |
470 | 460 |
471 bool posted = BrowserThread::PostTask( | 461 bool posted = BrowserThread::PostTask( |
472 BrowserThread::IO, | 462 BrowserThread::IO, |
473 FROM_HERE, | 463 FROM_HERE, |
474 NewRunnableFunction(SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread, | 464 NewRunnableFunction(SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread, |
475 prefs->GetMutableList(prefs::kDnsPrefetchingStartupList), | 465 prefs->GetMutableList(prefs::kDnsStartupPrefetchList), |
476 prefs->GetMutableList(prefs::kDnsPrefetchingHostReferralList), | 466 prefs->GetMutableList(prefs::kDnsHostReferralList), |
477 &completion)); | 467 &completion)); |
478 | 468 |
479 DCHECK(posted); | 469 DCHECK(posted); |
480 if (posted) | 470 if (posted) |
481 completion.Wait(); | 471 completion.Wait(); |
482 } | 472 } |
483 | 473 |
484 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, | 474 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, |
485 PrefService* local_state) { | 475 PrefService* local_state) { |
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
487 UrlList urls; | 477 UrlList urls; |
488 // Recall list of URLs we learned about during last session. | 478 // Recall list of URLs we learned about during last session. |
489 // This may catch secondary hostnames, pulled in by the homepages. It will | 479 // This may catch secondary hostnames, pulled in by the homepages. It will |
490 // also catch more of the "primary" home pages, since that was (presumably) | 480 // also catch more of the "primary" home pages, since that was (presumably) |
491 // rendered first (and will be rendered first this time too). | 481 // rendered first (and will be rendered first this time too). |
492 ListValue* startup_list = | 482 ListValue* startup_list = |
493 user_prefs->GetMutableList(prefs::kDnsPrefetchingStartupList); | 483 local_state->GetMutableList(prefs::kDnsStartupPrefetchList); |
494 | |
495 if (startup_list) { | 484 if (startup_list) { |
496 ListValue::iterator it = startup_list->begin(); | 485 ListValue::iterator it = startup_list->begin(); |
497 int format_version = -1; | 486 int format_version = -1; |
498 if (it != startup_list->end() && | 487 if (it != startup_list->end() && |
499 (*it)->GetAsInteger(&format_version) && | 488 (*it)->GetAsInteger(&format_version) && |
500 format_version == kPredictorStartupFormatVersion) { | 489 format_version == kPredictorStartupFormatVersion) { |
501 ++it; | 490 ++it; |
502 for (; it != startup_list->end(); ++it) { | 491 for (; it != startup_list->end(); ++it) { |
503 std::string url_spec; | 492 std::string url_spec; |
504 if (!(*it)->GetAsString(&url_spec)) { | 493 if (!(*it)->GetAsString(&url_spec)) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 DCHECK(!g_predictor); | 614 DCHECK(!g_predictor); |
626 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, | 615 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, |
627 local_state, preconnect_enabled); | 616 local_state, preconnect_enabled); |
628 } | 617 } |
629 } | 618 } |
630 | 619 |
631 PredictorInit::~PredictorInit() { | 620 PredictorInit::~PredictorInit() { |
632 } | 621 } |
633 | 622 |
634 } // namespace chrome_browser_net | 623 } // namespace chrome_browser_net |
OLD | NEW |