| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/history/top_sites_impl.h" | 5 #include "chrome/browser/history/top_sites_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // likely the user is first running Chrome. During this time we throttle | 318 // likely the user is first running Chrome. During this time we throttle |
| 319 // updating from history by 30 seconds. If the user creates a new tab page | 319 // updating from history by 30 seconds. If the user creates a new tab page |
| 320 // during this window of time we force updating from history so that the new | 320 // during this window of time we force updating from history so that the new |
| 321 // tab page isn't so far out of date. | 321 // tab page isn't so far out of date. |
| 322 timer_.Stop(); | 322 timer_.Stop(); |
| 323 StartQueryForMostVisited(); | 323 StartQueryForMostVisited(); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool TopSitesImpl::HasBlacklistedItems() const { | 327 bool TopSitesImpl::HasBlacklistedItems() const { |
| 328 const DictionaryValue* blacklist = | 328 const base::DictionaryValue* blacklist = |
| 329 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); | 329 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); |
| 330 return blacklist && !blacklist->empty(); | 330 return blacklist && !blacklist->empty(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void TopSitesImpl::AddBlacklistedURL(const GURL& url) { | 333 void TopSitesImpl::AddBlacklistedURL(const GURL& url) { |
| 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 335 | 335 |
| 336 Value* dummy = Value::CreateNullValue(); | 336 base::Value* dummy = base::Value::CreateNullValue(); |
| 337 { | 337 { |
| 338 DictionaryPrefUpdate update(profile_->GetPrefs(), | 338 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 339 prefs::kNtpMostVisitedURLsBlacklist); | 339 prefs::kNtpMostVisitedURLsBlacklist); |
| 340 DictionaryValue* blacklist = update.Get(); | 340 base::DictionaryValue* blacklist = update.Get(); |
| 341 blacklist->SetWithoutPathExpansion(GetURLHash(url), dummy); | 341 blacklist->SetWithoutPathExpansion(GetURLHash(url), dummy); |
| 342 } | 342 } |
| 343 | 343 |
| 344 ResetThreadSafeCache(); | 344 ResetThreadSafeCache(); |
| 345 NotifyTopSitesChanged(); | 345 NotifyTopSitesChanged(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void TopSitesImpl::RemoveBlacklistedURL(const GURL& url) { | 348 void TopSitesImpl::RemoveBlacklistedURL(const GURL& url) { |
| 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 350 { | 350 { |
| 351 DictionaryPrefUpdate update(profile_->GetPrefs(), | 351 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 352 prefs::kNtpMostVisitedURLsBlacklist); | 352 prefs::kNtpMostVisitedURLsBlacklist); |
| 353 DictionaryValue* blacklist = update.Get(); | 353 base::DictionaryValue* blacklist = update.Get(); |
| 354 blacklist->RemoveWithoutPathExpansion(GetURLHash(url), NULL); | 354 blacklist->RemoveWithoutPathExpansion(GetURLHash(url), NULL); |
| 355 } | 355 } |
| 356 ResetThreadSafeCache(); | 356 ResetThreadSafeCache(); |
| 357 NotifyTopSitesChanged(); | 357 NotifyTopSitesChanged(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 bool TopSitesImpl::IsBlacklisted(const GURL& url) { | 360 bool TopSitesImpl::IsBlacklisted(const GURL& url) { |
| 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 362 const DictionaryValue* blacklist = | 362 const base::DictionaryValue* blacklist = |
| 363 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); | 363 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); |
| 364 return blacklist && blacklist->HasKey(GetURLHash(url)); | 364 return blacklist && blacklist->HasKey(GetURLHash(url)); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void TopSitesImpl::ClearBlacklistedURLs() { | 367 void TopSitesImpl::ClearBlacklistedURLs() { |
| 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 369 { | 369 { |
| 370 DictionaryPrefUpdate update(profile_->GetPrefs(), | 370 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 371 prefs::kNtpMostVisitedURLsBlacklist); | 371 prefs::kNtpMostVisitedURLsBlacklist); |
| 372 DictionaryValue* blacklist = update.Get(); | 372 base::DictionaryValue* blacklist = update.Get(); |
| 373 blacklist->Clear(); | 373 blacklist->Clear(); |
| 374 } | 374 } |
| 375 ResetThreadSafeCache(); | 375 ResetThreadSafeCache(); |
| 376 NotifyTopSitesChanged(); | 376 NotifyTopSitesChanged(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void TopSitesImpl::Shutdown() { | 379 void TopSitesImpl::Shutdown() { |
| 380 profile_ = NULL; | 380 profile_ = NULL; |
| 381 // Cancel all requests so that the service doesn't callback to us after we've | 381 // Cancel all requests so that the service doesn't callback to us after we've |
| 382 // invoked Shutdown (this could happen if we have a pending request and | 382 // invoked Shutdown (this could happen if we have a pending request and |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 num_forced = kForcedTopSitesNumber; | 689 num_forced = kForcedTopSitesNumber; |
| 690 } | 690 } |
| 691 | 691 |
| 692 return num_forced; | 692 return num_forced; |
| 693 } | 693 } |
| 694 | 694 |
| 695 void TopSitesImpl::ApplyBlacklist(const MostVisitedURLList& urls, | 695 void TopSitesImpl::ApplyBlacklist(const MostVisitedURLList& urls, |
| 696 MostVisitedURLList* out) { | 696 MostVisitedURLList* out) { |
| 697 // Log the number of times ApplyBlacklist is called so we can compute the | 697 // Log the number of times ApplyBlacklist is called so we can compute the |
| 698 // average number of blacklisted items per user. | 698 // average number of blacklisted items per user. |
| 699 const DictionaryValue* blacklist = | 699 const base::DictionaryValue* blacklist = |
| 700 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); | 700 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); |
| 701 UMA_HISTOGRAM_BOOLEAN("TopSites.NumberOfApplyBlacklist", true); | 701 UMA_HISTOGRAM_BOOLEAN("TopSites.NumberOfApplyBlacklist", true); |
| 702 UMA_HISTOGRAM_COUNTS_100("TopSites.NumberOfBlacklistedItems", | 702 UMA_HISTOGRAM_COUNTS_100("TopSites.NumberOfBlacklistedItems", |
| 703 (blacklist ? blacklist->size() : 0)); | 703 (blacklist ? blacklist->size() : 0)); |
| 704 size_t num_non_forced_urls = 0; | 704 size_t num_non_forced_urls = 0; |
| 705 size_t num_forced_urls = 0; | 705 size_t num_forced_urls = 0; |
| 706 for (size_t i = 0; i < urls.size(); ++i) { | 706 for (size_t i = 0; i < urls.size(); ++i) { |
| 707 if (!IsBlacklisted(urls[i].url)) { | 707 if (!IsBlacklisted(urls[i].url)) { |
| 708 if (urls[i].last_forced_time.is_null()) { | 708 if (urls[i].last_forced_time.is_null()) { |
| 709 // Non-forced URL. | 709 // Non-forced URL. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 NotifyTopSitesChanged(); | 834 NotifyTopSitesChanged(); |
| 835 | 835 |
| 836 // Restart the timer that queries history for top sites. This is done to | 836 // Restart the timer that queries history for top sites. This is done to |
| 837 // ensure we stay in sync with history. | 837 // ensure we stay in sync with history. |
| 838 RestartQueryForTopSitesTimer(GetUpdateDelay()); | 838 RestartQueryForTopSitesTimer(GetUpdateDelay()); |
| 839 } | 839 } |
| 840 | 840 |
| 841 int TopSitesImpl::num_results_to_request_from_history() const { | 841 int TopSitesImpl::num_results_to_request_from_history() const { |
| 842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 843 | 843 |
| 844 const DictionaryValue* blacklist = | 844 const base::DictionaryValue* blacklist = |
| 845 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); | 845 profile_->GetPrefs()->GetDictionary(prefs::kNtpMostVisitedURLsBlacklist); |
| 846 return kNonForcedTopSitesNumber + (blacklist ? blacklist->size() : 0); | 846 return kNonForcedTopSitesNumber + (blacklist ? blacklist->size() : 0); |
| 847 } | 847 } |
| 848 | 848 |
| 849 void TopSitesImpl::MoveStateToLoaded() { | 849 void TopSitesImpl::MoveStateToLoaded() { |
| 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 851 | 851 |
| 852 MostVisitedURLList filtered_urls_all; | 852 MostVisitedURLList filtered_urls_all; |
| 853 MostVisitedURLList filtered_urls_nonforced; | 853 MostVisitedURLList filtered_urls_nonforced; |
| 854 PendingCallbacks pending_callbacks; | 854 PendingCallbacks pending_callbacks; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 SetTopSites(pages); | 936 SetTopSites(pages); |
| 937 | 937 |
| 938 // Used only in testing. | 938 // Used only in testing. |
| 939 content::NotificationService::current()->Notify( | 939 content::NotificationService::current()->Notify( |
| 940 chrome::NOTIFICATION_TOP_SITES_UPDATED, | 940 chrome::NOTIFICATION_TOP_SITES_UPDATED, |
| 941 content::Source<TopSitesImpl>(this), | 941 content::Source<TopSitesImpl>(this), |
| 942 content::Details<CancelableRequestProvider::Handle>(&handle)); | 942 content::Details<CancelableRequestProvider::Handle>(&handle)); |
| 943 } | 943 } |
| 944 | 944 |
| 945 } // namespace history | 945 } // namespace history |
| OLD | NEW |