Chromium Code Reviews| 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> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 // Always remove the existing entry and then add it back. That way if we end | 165 // Always remove the existing entry and then add it back. That way if we end |
| 166 // up with too many temp thumbnails we'll prune the oldest first. | 166 // up with too many temp thumbnails we'll prune the oldest first. |
| 167 RemoveTemporaryThumbnailByURL(url); | 167 RemoveTemporaryThumbnailByURL(url); |
| 168 AddTemporaryThumbnail(url, thumbnail_data.get(), score); | 168 AddTemporaryThumbnail(url, thumbnail_data.get(), score); |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 return SetPageThumbnailEncoded(url, thumbnail_data.get(), score); | 172 return SetPageThumbnailEncoded(url, thumbnail_data.get(), score); |
| 173 } | 173 } |
| 174 | 174 |
| 175 bool TopSitesImpl::SetPageThumbnailToJPEGBytes( | |
| 176 const GURL& url, | |
| 177 const base::RefCountedMemory* memory, | |
| 178 const ThumbnailScore& score) { | |
| 179 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 180 | |
| 181 if (!loaded_) { | |
| 182 // TODO(sky): I need to cache these and apply them after the load | |
| 183 // completes. | |
| 184 return false; | |
| 185 } | |
| 186 | |
| 187 bool add_temp_thumbnail = false; | |
| 188 if (!IsKnownURL(url)) { | |
| 189 if (!IsNonForcedFull()) { | |
| 190 add_temp_thumbnail = true; | |
| 191 } else { | |
| 192 return false; // This URL is not known to us. | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 if (!can_add_url_to_history_.Run(url)) | |
| 197 return false; // It's not a real webpage. | |
| 198 | |
| 199 if (add_temp_thumbnail) { | |
| 200 // Always remove the existing entry and then add it back. That way if we end | |
| 201 // up with too many temp thumbnails we'll prune the oldest first. | |
| 202 RemoveTemporaryThumbnailByURL(url); | |
| 203 AddTemporaryThumbnail(url, memory, score); | |
| 204 return true; | |
| 205 } | |
| 206 | |
| 207 return SetPageThumbnailEncoded(url, memory, score); | |
| 208 } | |
| 209 | |
| 210 // WARNING: this function may be invoked on any thread. | 175 // WARNING: this function may be invoked on any thread. |
| 211 void TopSitesImpl::GetMostVisitedURLs( | 176 void TopSitesImpl::GetMostVisitedURLs( |
| 212 const GetMostVisitedURLsCallback& callback, | 177 const GetMostVisitedURLsCallback& callback, |
| 213 bool include_forced_urls) { | 178 bool include_forced_urls) { |
| 214 MostVisitedURLList filtered_urls; | 179 MostVisitedURLList filtered_urls; |
| 215 { | 180 { |
| 216 base::AutoLock lock(lock_); | 181 base::AutoLock lock(lock_); |
| 217 if (!loaded_) { | 182 if (!loaded_) { |
| 218 // A request came in before we finished loading. Store the callback and | 183 // A request came in before we finished loading. Store the callback and |
| 219 // we'll run it on current thread when we finish loading. | 184 // we'll run it on current thread when we finish loading. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 402 |
| 438 // Any member without the special marker in the all_old_urls list means that | 403 // Any member without the special marker in the all_old_urls list means that |
| 439 // there wasn't a "new" URL that mapped to it, so it was deleted. | 404 // there wasn't a "new" URL that mapped to it, so it was deleted. |
| 440 for (std::map<GURL, size_t>::const_iterator i = all_old_urls.begin(); | 405 for (std::map<GURL, size_t>::const_iterator i = all_old_urls.begin(); |
| 441 i != all_old_urls.end(); ++i) { | 406 i != all_old_urls.end(); ++i) { |
| 442 if (i->second != kAlreadyFoundMarker) | 407 if (i->second != kAlreadyFoundMarker) |
| 443 delta->deleted.push_back(old_list[i->second]); | 408 delta->deleted.push_back(old_list[i->second]); |
| 444 } | 409 } |
| 445 } | 410 } |
| 446 | 411 |
| 447 base::CancelableTaskTracker::TaskId TopSitesImpl::StartQueryForMostVisited() { | 412 void TopSitesImpl::StartQueryForMostVisited() { |
|
msw
2016/12/13 22:31:53
nit: reorder to match new decl order
Marc Treib
2016/12/14 11:12:22
Done. There were some other things out of order wr
| |
| 448 DCHECK(loaded_); | 413 DCHECK(loaded_); |
| 449 if (!history_service_) | 414 if (!history_service_) |
| 450 return base::CancelableTaskTracker::kBadTaskId; | 415 return; |
| 451 | 416 |
| 452 return history_service_->QueryMostVisitedURLs( | 417 history_service_->QueryMostVisitedURLs( |
| 453 num_results_to_request_from_history(), kDaysOfHistory, | 418 num_results_to_request_from_history(), kDaysOfHistory, |
| 454 base::Bind(&TopSitesImpl::OnTopSitesAvailableFromHistory, | 419 base::Bind(&TopSitesImpl::OnTopSitesAvailableFromHistory, |
| 455 base::Unretained(this)), | 420 base::Unretained(this)), |
| 456 &cancelable_task_tracker_); | 421 &cancelable_task_tracker_); |
| 457 } | 422 } |
| 458 | 423 |
| 459 bool TopSitesImpl::IsKnownURL(const GURL& url) { | 424 bool TopSitesImpl::IsKnownURL(const GURL& url) { |
| 460 return loaded_ && cache_->IsKnownURL(url); | 425 return loaded_ && cache_->IsKnownURL(url); |
| 461 } | 426 } |
| 462 | 427 |
| 463 const std::string& TopSitesImpl::GetCanonicalURLString(const GURL& url) const { | |
| 464 return cache_->GetCanonicalURL(url).spec(); | |
| 465 } | |
| 466 | |
| 467 bool TopSitesImpl::IsNonForcedFull() { | 428 bool TopSitesImpl::IsNonForcedFull() { |
| 468 return loaded_ && cache_->GetNumNonForcedURLs() >= kNonForcedTopSitesNumber; | 429 return loaded_ && cache_->GetNumNonForcedURLs() >= kNonForcedTopSitesNumber; |
| 469 } | 430 } |
| 470 | 431 |
| 471 bool TopSitesImpl::IsForcedFull() { | 432 bool TopSitesImpl::IsForcedFull() { |
| 472 return loaded_ && cache_->GetNumForcedURLs() >= kForcedTopSitesNumber; | 433 return loaded_ && cache_->GetNumForcedURLs() >= kForcedTopSitesNumber; |
| 473 } | 434 } |
| 474 | 435 |
| 475 TopSitesImpl::~TopSitesImpl() { | 436 TopSitesImpl::~TopSitesImpl() { |
| 476 } | 437 } |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 930 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); | 891 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); |
| 931 i != indices_to_delete.rend(); i++) { | 892 i != indices_to_delete.rend(); i++) { |
| 932 new_top_sites.erase(new_top_sites.begin() + *i); | 893 new_top_sites.erase(new_top_sites.begin() + *i); |
| 933 } | 894 } |
| 934 SetTopSites(new_top_sites, CALL_LOCATION_FROM_OTHER_PLACES); | 895 SetTopSites(new_top_sites, CALL_LOCATION_FROM_OTHER_PLACES); |
| 935 } | 896 } |
| 936 StartQueryForMostVisited(); | 897 StartQueryForMostVisited(); |
| 937 } | 898 } |
| 938 | 899 |
| 939 } // namespace history | 900 } // namespace history |
| OLD | NEW |