| 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 "components/history/core/browser/top_sites_impl.h" | 5 #include "components/history/core/browser/top_sites_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 #include <set> | 10 #include <set> |
| 9 | 11 |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 12 #include "base/location.h" | 14 #include "base/location.h" |
| 13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 14 #include "base/md5.h" | 16 #include "base/md5.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 17 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/prefs/pref_registry_simple.h" | 19 #include "base/prefs/pref_registry_simple.h" |
| 18 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
| 19 #include "base/prefs/scoped_user_pref_update.h" | 21 #include "base/prefs/scoped_user_pref_update.h" |
| 20 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 21 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/task_runner.h" | 25 #include "base/task_runner.h" |
| 24 #include "base/thread_task_runner_handle.h" | 26 #include "base/thread_task_runner_handle.h" |
| 25 #include "base/values.h" | 27 #include "base/values.h" |
| 28 #include "build/build_config.h" |
| 26 #include "components/history/core/browser/history_backend.h" | 29 #include "components/history/core/browser/history_backend.h" |
| 27 #include "components/history/core/browser/history_constants.h" | 30 #include "components/history/core/browser/history_constants.h" |
| 28 #include "components/history/core/browser/history_db_task.h" | 31 #include "components/history/core/browser/history_db_task.h" |
| 29 #include "components/history/core/browser/page_usage_data.h" | 32 #include "components/history/core/browser/page_usage_data.h" |
| 30 #include "components/history/core/browser/top_sites_cache.h" | 33 #include "components/history/core/browser/top_sites_cache.h" |
| 31 #include "components/history/core/browser/top_sites_observer.h" | 34 #include "components/history/core/browser/top_sites_observer.h" |
| 32 #include "components/history/core/browser/url_utils.h" | 35 #include "components/history/core/browser/url_utils.h" |
| 33 #include "components/history/core/common/thumbnail_score.h" | 36 #include "components/history/core/common/thumbnail_score.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/layout.h" | 38 #include "ui/base/layout.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 71 |
| 69 // How many forced top sites to store in the cache. | 72 // How many forced top sites to store in the cache. |
| 70 const size_t kForcedTopSitesNumber = 20; | 73 const size_t kForcedTopSitesNumber = 20; |
| 71 | 74 |
| 72 // Max number of temporary images we'll cache. See comment above | 75 // Max number of temporary images we'll cache. See comment above |
| 73 // temp_images_ for details. | 76 // temp_images_ for details. |
| 74 const size_t kMaxTempTopImages = 8; | 77 const size_t kMaxTempTopImages = 8; |
| 75 | 78 |
| 76 const int kDaysOfHistory = 90; | 79 const int kDaysOfHistory = 90; |
| 77 // Time from startup to first HistoryService query. | 80 // Time from startup to first HistoryService query. |
| 78 const int64 kUpdateIntervalSecs = 15; | 81 const int64_t kUpdateIntervalSecs = 15; |
| 79 // Intervals between requests to HistoryService. | 82 // Intervals between requests to HistoryService. |
| 80 const int64 kMinUpdateIntervalMinutes = 1; | 83 const int64_t kMinUpdateIntervalMinutes = 1; |
| 81 #if !defined(OS_IOS) | 84 #if !defined(OS_IOS) |
| 82 const int64 kMaxUpdateIntervalMinutes = 60; | 85 const int64_t kMaxUpdateIntervalMinutes = 60; |
| 83 #else | 86 #else |
| 84 // On iOS, having the max at 60 results in the topsites database being | 87 // On iOS, having the max at 60 results in the topsites database being |
| 85 // not updated often enough since the app isn't usually running for long | 88 // not updated often enough since the app isn't usually running for long |
| 86 // stretches of time. | 89 // stretches of time. |
| 87 const int64 kMaxUpdateIntervalMinutes = 5; | 90 const int64_t kMaxUpdateIntervalMinutes = 5; |
| 88 #endif // !defined(OS_IOS) | 91 #endif // !defined(OS_IOS) |
| 89 | 92 |
| 90 // Use 100 quality (highest quality) because we're very sensitive to | 93 // Use 100 quality (highest quality) because we're very sensitive to |
| 91 // artifacts for these small sized, highly detailed images. | 94 // artifacts for these small sized, highly detailed images. |
| 92 const int kTopSitesImageQuality = 100; | 95 const int kTopSitesImageQuality = 100; |
| 93 | 96 |
| 94 // Key for preference listing the URLs that should not be shown as most | 97 // Key for preference listing the URLs that should not be shown as most |
| 95 // visited thumbnails. | 98 // visited thumbnails. |
| 96 const char kMostVisitedURLsBlacklist[] = "ntp.most_visited_blacklist"; | 99 const char kMostVisitedURLsBlacklist[] = "ntp.most_visited_blacklist"; |
| 97 | 100 |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 std::string TopSitesImpl::GetURLHash(const GURL& url) { | 731 std::string TopSitesImpl::GetURLHash(const GURL& url) { |
| 729 // We don't use canonical URLs here to be able to blacklist only one of | 732 // We don't use canonical URLs here to be able to blacklist only one of |
| 730 // the two 'duplicate' sites, e.g. 'gmail.com' and 'mail.google.com'. | 733 // the two 'duplicate' sites, e.g. 'gmail.com' and 'mail.google.com'. |
| 731 return base::MD5String(url.spec()); | 734 return base::MD5String(url.spec()); |
| 732 } | 735 } |
| 733 | 736 |
| 734 base::TimeDelta TopSitesImpl::GetUpdateDelay() { | 737 base::TimeDelta TopSitesImpl::GetUpdateDelay() { |
| 735 if (cache_->top_sites().size() <= prepopulated_pages_.size()) | 738 if (cache_->top_sites().size() <= prepopulated_pages_.size()) |
| 736 return base::TimeDelta::FromSeconds(30); | 739 return base::TimeDelta::FromSeconds(30); |
| 737 | 740 |
| 738 int64 range = kMaxUpdateIntervalMinutes - kMinUpdateIntervalMinutes; | 741 int64_t range = kMaxUpdateIntervalMinutes - kMinUpdateIntervalMinutes; |
| 739 int64 minutes = kMaxUpdateIntervalMinutes - | 742 int64_t minutes = kMaxUpdateIntervalMinutes - |
| 740 last_num_urls_changed_ * range / cache_->top_sites().size(); | 743 last_num_urls_changed_ * range / cache_->top_sites().size(); |
| 741 return base::TimeDelta::FromMinutes(minutes); | 744 return base::TimeDelta::FromMinutes(minutes); |
| 742 } | 745 } |
| 743 | 746 |
| 744 void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites, | 747 void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites, |
| 745 const CallLocation location) { | 748 const CallLocation location) { |
| 746 DCHECK(thread_checker_.CalledOnValidThread()); | 749 DCHECK(thread_checker_.CalledOnValidThread()); |
| 747 | 750 |
| 748 MostVisitedURLList top_sites(new_top_sites); | 751 MostVisitedURLList top_sites(new_top_sites); |
| 749 size_t num_forced_urls = MergeCachedForcedURLs(&top_sites); | 752 size_t num_forced_urls = MergeCachedForcedURLs(&top_sites); |
| 750 AddPrepopulatedPages(&top_sites, num_forced_urls); | 753 AddPrepopulatedPages(&top_sites, num_forced_urls); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); | 934 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); |
| 932 i != indices_to_delete.rend(); i++) { | 935 i != indices_to_delete.rend(); i++) { |
| 933 new_top_sites.erase(new_top_sites.begin() + *i); | 936 new_top_sites.erase(new_top_sites.begin() + *i); |
| 934 } | 937 } |
| 935 SetTopSites(new_top_sites, CALL_LOCATION_FROM_OTHER_PLACES); | 938 SetTopSites(new_top_sites, CALL_LOCATION_FROM_OTHER_PLACES); |
| 936 } | 939 } |
| 937 StartQueryForMostVisited(); | 940 StartQueryForMostVisited(); |
| 938 } | 941 } |
| 939 | 942 |
| 940 } // namespace history | 943 } // namespace history |
| OLD | NEW |