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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/md5.h" | 13 #include "base/md5.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/prefs/scoped_user_pref_update.h" | 18 #include "base/prefs/scoped_user_pref_update.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "base/task_runner.h" | 22 #include "base/task_runner.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
25 #include "chrome/browser/history/history_backend.h" | 25 #include "chrome/browser/history/history_backend.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
| 27 #include "chrome/browser/history/history_utils.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "components/history/core/browser/history_db_task.h" | 30 #include "components/history/core/browser/history_db_task.h" |
30 #include "components/history/core/browser/page_usage_data.h" | 31 #include "components/history/core/browser/page_usage_data.h" |
31 #include "components/history/core/browser/top_sites_cache.h" | 32 #include "components/history/core/browser/top_sites_cache.h" |
32 #include "components/history/core/browser/url_utils.h" | 33 #include "components/history/core/browser/url_utils.h" |
33 #include "components/history/core/common/thumbnail_score.h" | 34 #include "components/history/core/common/thumbnail_score.h" |
34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/navigation_controller.h" | 36 #include "content/public/browser/navigation_controller.h" |
36 #include "content/public/browser/navigation_details.h" | 37 #include "content/public/browser/navigation_details.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 143 |
143 bool add_temp_thumbnail = false; | 144 bool add_temp_thumbnail = false; |
144 if (!IsKnownURL(url)) { | 145 if (!IsKnownURL(url)) { |
145 if (!IsNonForcedFull()) { | 146 if (!IsNonForcedFull()) { |
146 add_temp_thumbnail = true; | 147 add_temp_thumbnail = true; |
147 } else { | 148 } else { |
148 return false; // This URL is not known to us. | 149 return false; // This URL is not known to us. |
149 } | 150 } |
150 } | 151 } |
151 | 152 |
152 if (!HistoryService::CanAddURL(url)) | 153 if (!CanAddURLToHistory(url)) |
153 return false; // It's not a real webpage. | 154 return false; // It's not a real webpage. |
154 | 155 |
155 scoped_refptr<base::RefCountedBytes> thumbnail_data; | 156 scoped_refptr<base::RefCountedBytes> thumbnail_data; |
156 if (!EncodeBitmap(thumbnail, &thumbnail_data)) | 157 if (!EncodeBitmap(thumbnail, &thumbnail_data)) |
157 return false; | 158 return false; |
158 | 159 |
159 if (add_temp_thumbnail) { | 160 if (add_temp_thumbnail) { |
160 // Always remove the existing entry and then add it back. That way if we end | 161 // Always remove the existing entry and then add it back. That way if we end |
161 // up with too many temp thumbnails we'll prune the oldest first. | 162 // up with too many temp thumbnails we'll prune the oldest first. |
162 RemoveTemporaryThumbnailByURL(url); | 163 RemoveTemporaryThumbnailByURL(url); |
(...skipping 18 matching lines...) Expand all Loading... |
181 | 182 |
182 bool add_temp_thumbnail = false; | 183 bool add_temp_thumbnail = false; |
183 if (!IsKnownURL(url)) { | 184 if (!IsKnownURL(url)) { |
184 if (!IsNonForcedFull()) { | 185 if (!IsNonForcedFull()) { |
185 add_temp_thumbnail = true; | 186 add_temp_thumbnail = true; |
186 } else { | 187 } else { |
187 return false; // This URL is not known to us. | 188 return false; // This URL is not known to us. |
188 } | 189 } |
189 } | 190 } |
190 | 191 |
191 if (!HistoryService::CanAddURL(url)) | 192 if (!CanAddURLToHistory(url)) |
192 return false; // It's not a real webpage. | 193 return false; // It's not a real webpage. |
193 | 194 |
194 if (add_temp_thumbnail) { | 195 if (add_temp_thumbnail) { |
195 // Always remove the existing entry and then add it back. That way if we end | 196 // Always remove the existing entry and then add it back. That way if we end |
196 // up with too many temp thumbnails we'll prune the oldest first. | 197 // up with too many temp thumbnails we'll prune the oldest first. |
197 RemoveTemporaryThumbnailByURL(url); | 198 RemoveTemporaryThumbnailByURL(url); |
198 AddTemporaryThumbnail(url, memory, score); | 199 AddTemporaryThumbnail(url, memory, score); |
199 return true; | 200 return true; |
200 } | 201 } |
201 | 202 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 NavigationController* controller = | 737 NavigationController* controller = |
737 content::Source<NavigationController>(source).ptr(); | 738 content::Source<NavigationController>(source).ptr(); |
738 Profile* profile = Profile::FromBrowserContext( | 739 Profile* profile = Profile::FromBrowserContext( |
739 controller->GetWebContents()->GetBrowserContext()); | 740 controller->GetWebContents()->GetBrowserContext()); |
740 if (profile == profile_ && !IsNonForcedFull()) { | 741 if (profile == profile_ && !IsNonForcedFull()) { |
741 content::LoadCommittedDetails* load_details = | 742 content::LoadCommittedDetails* load_details = |
742 content::Details<content::LoadCommittedDetails>(details).ptr(); | 743 content::Details<content::LoadCommittedDetails>(details).ptr(); |
743 if (!load_details) | 744 if (!load_details) |
744 return; | 745 return; |
745 const GURL& url = load_details->entry->GetURL(); | 746 const GURL& url = load_details->entry->GetURL(); |
746 if (!cache_->IsKnownURL(url) && HistoryService::CanAddURL(url)) { | 747 if (!cache_->IsKnownURL(url) && CanAddURLToHistory(url)) { |
747 // To avoid slamming history we throttle requests when the url updates. | 748 // To avoid slamming history we throttle requests when the url updates. |
748 // To do otherwise negatively impacts perf tests. | 749 // To do otherwise negatively impacts perf tests. |
749 RestartQueryForTopSitesTimer(GetUpdateDelay()); | 750 RestartQueryForTopSitesTimer(GetUpdateDelay()); |
750 } | 751 } |
751 } | 752 } |
752 } | 753 } |
753 | 754 |
754 void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites) { | 755 void TopSitesImpl::SetTopSites(const MostVisitedURLList& new_top_sites) { |
755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
756 | 757 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 SetTopSites(new_top_sites); | 926 SetTopSites(new_top_sites); |
926 } | 927 } |
927 StartQueryForMostVisited(); | 928 StartQueryForMostVisited(); |
928 } | 929 } |
929 | 930 |
930 void TopSitesImpl::HistoryServiceBeingDeleted(HistoryService* history_service) { | 931 void TopSitesImpl::HistoryServiceBeingDeleted(HistoryService* history_service) { |
931 history_service_observer_.Remove(history_service); | 932 history_service_observer_.Remove(history_service); |
932 } | 933 } |
933 | 934 |
934 } // namespace history | 935 } // namespace history |
OLD | NEW |