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 | |
141 void RegisterUserPrefs(PrefService* user_prefs) { | 136 void RegisterUserPrefs(PrefService* user_prefs) { |
137 user_prefs->RegisterListPref(prefs::kDnsStartupPrefetchList); | |
138 user_prefs->RegisterListPref(prefs::kDnsHostReferralList); | |
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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 bool preconnect_enabled) { | 382 bool preconnect_enabled) { |
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 |
392 // Migrate HostReferralList from local_state to user prefs if needed. | |
395 ListValue* referral_list = | 393 ListValue* referral_list = |
396 static_cast<ListValue*>( | 394 (local_state->FindPreference(prefs::kDnsHostReferralList)) ? |
jar (doing other things)
2010/12/13 20:27:29
If this is where you migrate the data, perhaps it
Miranda Callahan
2010/12/14 01:03:49
I think everything you say about deleting old data
| |
397 local_state->GetMutableList(prefs::kDnsHostReferralList)->DeepCopy()); | 395 static_cast<ListValue*>( |
396 local_state->GetMutableList(prefs::kDnsHostReferralList)->DeepCopy()) : | |
397 static_cast<ListValue*>( | |
398 user_prefs->GetMutableList(prefs::kDnsHostReferralList)->DeepCopy()); | |
398 | 399 |
399 g_browser_process->io_thread()->InitNetworkPredictor( | 400 g_browser_process->io_thread()->InitNetworkPredictor( |
400 prefetching_enabled, max_dns_queue_delay, max_parallel_resolves, urls, | 401 prefetching_enabled, max_dns_queue_delay, max_parallel_resolves, urls, |
401 referral_list, preconnect_enabled); | 402 referral_list, preconnect_enabled); |
402 } | 403 } |
403 | 404 |
404 void FinalizePredictorInitialization( | 405 void FinalizePredictorInitialization( |
405 Predictor* global_predictor, | 406 Predictor* global_predictor, |
406 const UrlList& startup_urls, | 407 const UrlList& startup_urls, |
407 ListValue* referral_list) { | 408 ListValue* referral_list) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 } | 473 } |
473 | 474 |
474 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, | 475 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, |
475 PrefService* local_state) { | 476 PrefService* local_state) { |
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
477 UrlList urls; | 478 UrlList urls; |
478 // Recall list of URLs we learned about during last session. | 479 // Recall list of URLs we learned about during last session. |
479 // This may catch secondary hostnames, pulled in by the homepages. It will | 480 // 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) | 481 // also catch more of the "primary" home pages, since that was (presumably) |
481 // rendered first (and will be rendered first this time too). | 482 // rendered first (and will be rendered first this time too). |
483 // Migrate StartupPrefetchList from local_state to user prefs if needed. | |
482 ListValue* startup_list = | 484 ListValue* startup_list = |
483 local_state->GetMutableList(prefs::kDnsStartupPrefetchList); | 485 (local_state->FindPreference(prefs::kDnsStartupPrefetchList)) ? |
486 local_state->GetMutableList(prefs::kDnsStartupPrefetchList) : | |
487 user_prefs->GetMutableList(prefs::kDnsStartupPrefetchList); | |
488 | |
484 if (startup_list) { | 489 if (startup_list) { |
485 ListValue::iterator it = startup_list->begin(); | 490 ListValue::iterator it = startup_list->begin(); |
486 int format_version = -1; | 491 int format_version = -1; |
487 if (it != startup_list->end() && | 492 if (it != startup_list->end() && |
488 (*it)->GetAsInteger(&format_version) && | 493 (*it)->GetAsInteger(&format_version) && |
489 format_version == kPredictorStartupFormatVersion) { | 494 format_version == kPredictorStartupFormatVersion) { |
490 ++it; | 495 ++it; |
491 for (; it != startup_list->end(); ++it) { | 496 for (; it != startup_list->end(); ++it) { |
492 std::string url_spec; | 497 std::string url_spec; |
493 if (!(*it)->GetAsString(&url_spec)) { | 498 if (!(*it)->GetAsString(&url_spec)) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 DCHECK(!g_predictor); | 619 DCHECK(!g_predictor); |
615 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, | 620 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, |
616 local_state, preconnect_enabled); | 621 local_state, preconnect_enabled); |
617 } | 622 } |
618 } | 623 } |
619 | 624 |
620 PredictorInit::~PredictorInit() { | 625 PredictorInit::~PredictorInit() { |
621 } | 626 } |
622 | 627 |
623 } // namespace chrome_browser_net | 628 } // namespace chrome_browser_net |
OLD | NEW |