OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/io_thread.h" | 18 #include "chrome/browser/io_thread.h" |
19 #include "chrome/browser/net/preconnect.h" | 19 #include "chrome/browser/net/preconnect.h" |
20 #include "chrome/browser/net/referrer.h" | 20 #include "chrome/browser/net/referrer.h" |
21 #include "chrome/browser/net/url_info.h" | 21 #include "chrome/browser/net/url_info.h" |
22 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
24 #include "chrome/browser/prefs/scoped_user_pref_update.h" | |
24 #include "chrome/browser/prefs/session_startup_pref.h" | 25 #include "chrome/browser/prefs/session_startup_pref.h" |
25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "content/browser/browser_thread.h" | 29 #include "content/browser/browser_thread.h" |
29 #include "content/common/notification_registrar.h" | 30 #include "content/common/notification_registrar.h" |
30 #include "content/common/notification_service.h" | 31 #include "content/common/notification_service.h" |
31 #include "net/base/host_resolver.h" | 32 #include "net/base/host_resolver.h" |
32 #include "net/base/host_resolver_impl.h" | 33 #include "net/base/host_resolver_impl.h" |
33 | 34 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
401 | 402 |
402 bool prefetching_enabled = | 403 bool prefetching_enabled = |
403 user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); | 404 user_prefs->GetBoolean(prefs::kDnsPrefetchingEnabled); |
404 | 405 |
405 // Gather the list of hostnames to prefetch on startup. | 406 // Gather the list of hostnames to prefetch on startup. |
406 UrlList urls = | 407 UrlList urls = |
407 GetPredictedUrlListAtStartup(user_prefs, local_state); | 408 GetPredictedUrlListAtStartup(user_prefs, local_state); |
408 | 409 |
409 ListValue* referral_list = | 410 ListValue* referral_list = |
410 static_cast<ListValue*>(user_prefs->GetMutableList( | 411 static_cast<ListValue*>(user_prefs->GetList( |
411 prefs::kDnsPrefetchingHostReferralList)->DeepCopy()); | 412 prefs::kDnsPrefetchingHostReferralList)->DeepCopy()); |
412 | 413 |
413 // Remove obsolete preferences from local state if necessary. | 414 // Remove obsolete preferences from local state if necessary. |
414 int current_version = | 415 int current_version = |
415 local_state->GetInteger(prefs::kMultipleProfilePrefMigration); | 416 local_state->GetInteger(prefs::kMultipleProfilePrefMigration); |
416 if ((current_version & browser::DNS_PREFS) == 0) { | 417 if ((current_version & browser::DNS_PREFS) == 0) { |
417 local_state->RegisterListPref(prefs::kDnsStartupPrefetchList); | 418 local_state->RegisterListPref(prefs::kDnsStartupPrefetchList); |
418 local_state->RegisterListPref(prefs::kDnsHostReferralList); | 419 local_state->RegisterListPref(prefs::kDnsHostReferralList); |
419 local_state->ClearPref(prefs::kDnsStartupPrefetchList); | 420 local_state->ClearPref(prefs::kDnsStartupPrefetchList); |
420 local_state->ClearPref(prefs::kDnsHostReferralList); | 421 local_state->ClearPref(prefs::kDnsHostReferralList); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 } | 478 } |
478 | 479 |
479 void SavePredictorStateForNextStartupAndTrim(PrefService* prefs) { | 480 void SavePredictorStateForNextStartupAndTrim(PrefService* prefs) { |
480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
481 | 482 |
482 if (!predictor_enabled || g_predictor == NULL) | 483 if (!predictor_enabled || g_predictor == NULL) |
483 return; | 484 return; |
484 | 485 |
485 base::WaitableEvent completion(true, false); | 486 base::WaitableEvent completion(true, false); |
486 | 487 |
488 ListPrefUpdate update_startup_list(prefs, prefs::kDnsPrefetchingStartupList); | |
489 ListPrefUpdate update_referral_list(prefs, | |
490 prefs::kDnsPrefetchingHostReferralList); | |
487 bool posted = BrowserThread::PostTask( | 491 bool posted = BrowserThread::PostTask( |
488 BrowserThread::IO, | 492 BrowserThread::IO, |
489 FROM_HERE, | 493 FROM_HERE, |
490 NewRunnableFunction(SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread, | 494 NewRunnableFunction(SaveDnsPrefetchStateForNextStartupAndTrimOnIOThread, |
491 prefs->GetMutableList(prefs::kDnsPrefetchingStartupList), | 495 update_startup_list.Get(), |
jar (doing other things)
2011/04/04 19:18:33
This makes very little sense to me. I'm *guessing
jar (doing other things)
2011/04/05 06:18:39
I suspect this may actually be the source of a lar
battre
2011/04/05 14:09:50
I thought about this.
I think the code is safe be
jar (doing other things)
2011/04/05 16:03:11
<sigh> Ok... I'm convinced your change is correct
| |
492 prefs->GetMutableList(prefs::kDnsPrefetchingHostReferralList), | 496 update_referral_list.Get(), |
493 &completion)); | 497 &completion)); |
494 | 498 |
495 DCHECK(posted); | 499 DCHECK(posted); |
496 if (posted) | 500 if (posted) |
497 completion.Wait(); | 501 completion.Wait(); |
498 } | 502 } |
499 | 503 |
500 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, | 504 static UrlList GetPredictedUrlListAtStartup(PrefService* user_prefs, |
501 PrefService* local_state) { | 505 PrefService* local_state) { |
502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
503 UrlList urls; | 507 UrlList urls; |
504 // Recall list of URLs we learned about during last session. | 508 // Recall list of URLs we learned about during last session. |
505 // This may catch secondary hostnames, pulled in by the homepages. It will | 509 // This may catch secondary hostnames, pulled in by the homepages. It will |
506 // also catch more of the "primary" home pages, since that was (presumably) | 510 // also catch more of the "primary" home pages, since that was (presumably) |
507 // rendered first (and will be rendered first this time too). | 511 // rendered first (and will be rendered first this time too). |
508 ListValue* startup_list = | 512 const ListValue* startup_list = |
509 user_prefs->GetMutableList(prefs::kDnsPrefetchingStartupList); | 513 user_prefs->GetList(prefs::kDnsPrefetchingStartupList); |
510 | 514 |
511 if (startup_list) { | 515 if (startup_list) { |
512 ListValue::iterator it = startup_list->begin(); | 516 ListValue::const_iterator it = startup_list->begin(); |
513 int format_version = -1; | 517 int format_version = -1; |
514 if (it != startup_list->end() && | 518 if (it != startup_list->end() && |
515 (*it)->GetAsInteger(&format_version) && | 519 (*it)->GetAsInteger(&format_version) && |
516 format_version == kPredictorStartupFormatVersion) { | 520 format_version == kPredictorStartupFormatVersion) { |
517 ++it; | 521 ++it; |
518 for (; it != startup_list->end(); ++it) { | 522 for (; it != startup_list->end(); ++it) { |
519 std::string url_spec; | 523 std::string url_spec; |
520 if (!(*it)->GetAsString(&url_spec)) { | 524 if (!(*it)->GetAsString(&url_spec)) { |
521 LOG(DFATAL); | 525 LOG(DFATAL); |
522 break; // Format incompatibility. | 526 break; // Format incompatibility. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 DCHECK(!g_predictor); | 644 DCHECK(!g_predictor); |
641 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, | 645 InitNetworkPredictor(max_queueing_delay, max_parallel_resolves, user_prefs, |
642 local_state, preconnect_enabled); | 646 local_state, preconnect_enabled); |
643 } | 647 } |
644 } | 648 } |
645 | 649 |
646 PredictorInit::~PredictorInit() { | 650 PredictorInit::~PredictorInit() { |
647 } | 651 } |
648 | 652 |
649 } // namespace chrome_browser_net | 653 } // namespace chrome_browser_net |
OLD | NEW |