Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/history/top_sites.cc

Issue 5088001: Add pyauto hook for getting and manipulating the data underneath the NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/functional
Patch Set: ... Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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.h" 5 #include "chrome/browser/history/top_sites.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 433
434 // Any member without the special marker in the all_old_urls list means that 434 // Any member without the special marker in the all_old_urls list means that
435 // there wasn't a "new" URL that mapped to it, so it was deleted. 435 // there wasn't a "new" URL that mapped to it, so it was deleted.
436 for (std::map<GURL, size_t>::const_iterator i = all_old_urls.begin(); 436 for (std::map<GURL, size_t>::const_iterator i = all_old_urls.begin();
437 i != all_old_urls.end(); ++i) { 437 i != all_old_urls.end(); ++i) {
438 if (i->second != kAlreadyFoundMarker) 438 if (i->second != kAlreadyFoundMarker)
439 delta->deleted.push_back(old_list[i->second]); 439 delta->deleted.push_back(old_list[i->second]);
440 } 440 }
441 } 441 }
442 442
443 CancelableRequestProvider::Handle TopSites::StartQueryForMostVisited() {
444 DCHECK(loaded_);
445 if (!profile_)
446 return NULL;
447
448 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
449 // |hs| may be null during unit tests.
450 if (hs) {
451 return hs->QueryMostVisitedURLs(
452 num_results_to_request_from_history(),
453 kDaysOfHistory,
454 &cancelable_consumer_,
455 NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory));
456 }
457 return NULL;
458 }
459
443 TopSites::~TopSites() { 460 TopSites::~TopSites() {
444 } 461 }
445 462
446 bool TopSites::SetPageThumbnailNoDB(const GURL& url, 463 bool TopSites::SetPageThumbnailNoDB(const GURL& url,
447 const RefCountedBytes* thumbnail_data, 464 const RefCountedBytes* thumbnail_data,
448 const ThumbnailScore& score) { 465 const ThumbnailScore& score) {
449 // This should only be invoked when we know about the url. 466 // This should only be invoked when we know about the url.
450 DCHECK(cache_->IsKnownURL(url)); 467 DCHECK(cache_->IsKnownURL(url));
451 468
452 const MostVisitedURL& most_visited = 469 const MostVisitedURL& most_visited =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 if (temp_images_.size() == kMaxTempTopImages) 543 if (temp_images_.size() == kMaxTempTopImages)
527 temp_images_.erase(temp_images_.begin()); 544 temp_images_.erase(temp_images_.begin());
528 545
529 TempImage image; 546 TempImage image;
530 image.first = url; 547 image.first = url;
531 image.second.thumbnail = const_cast<RefCountedBytes*>(thumbnail); 548 image.second.thumbnail = const_cast<RefCountedBytes*>(thumbnail);
532 image.second.thumbnail_score = score; 549 image.second.thumbnail_score = score;
533 temp_images_.push_back(image); 550 temp_images_.push_back(image);
534 } 551 }
535 552
536 void TopSites::StartQueryForMostVisited() { 553 void TopSites::TimerFired() {
537 if (!profile_) 554 StartQueryForMostVisited();
538 return;
539
540 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
541 // |hs| may be null during unit tests.
542 if (hs) {
543 hs->QueryMostVisitedURLs(
544 num_results_to_request_from_history(),
545 kDaysOfHistory,
546 &cancelable_consumer_,
547 NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory));
548 }
549 } 555 }
550 556
551 // static 557 // static
552 int TopSites::GetRedirectDistanceForURL(const MostVisitedURL& most_visited, 558 int TopSites::GetRedirectDistanceForURL(const MostVisitedURL& most_visited,
553 const GURL& url) { 559 const GURL& url) {
554 for (size_t i = 0; i < most_visited.redirects.size(); i++) { 560 for (size_t i = 0; i < most_visited.redirects.size(); i++) {
555 if (most_visited.redirects[i] == url) 561 if (most_visited.redirects[i] == url)
556 return static_cast<int>(most_visited.redirects.size() - i - 1); 562 return static_cast<int>(most_visited.redirects.size() - i - 1);
557 } 563 }
558 NOTREACHED() << "URL should always be found."; 564 NOTREACHED() << "URL should always be found.";
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 } 843 }
838 844
839 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) { 845 void TopSites::RestartQueryForTopSitesTimer(base::TimeDelta delta) {
840 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) < 846 if (timer_.IsRunning() && ((timer_start_time_ + timer_.GetCurrentDelay()) <
841 (base::TimeTicks::Now() + delta))) { 847 (base::TimeTicks::Now() + delta))) {
842 return; 848 return;
843 } 849 }
844 850
845 timer_start_time_ = base::TimeTicks::Now(); 851 timer_start_time_ = base::TimeTicks::Now();
846 timer_.Stop(); 852 timer_.Stop();
847 timer_.Start(delta, this, &TopSites::StartQueryForMostVisited); 853 timer_.Start(delta, this, &TopSites::TimerFired);
848 } 854 }
849 855
850 void TopSites::OnHistoryMigrationWrittenToDisk(TopSitesBackend::Handle handle) { 856 void TopSites::OnHistoryMigrationWrittenToDisk(TopSitesBackend::Handle handle) {
851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
852 858
853 if (!profile_) 859 if (!profile_)
854 return; 860 return;
855 861
856 HistoryService* history = 862 HistoryService* history =
857 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 863 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 // finishes loading we'll do migration and/or move to loaded. 901 // finishes loading we'll do migration and/or move to loaded.
896 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 902 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
897 } 903 }
898 } 904 }
899 } 905 }
900 906
901 void TopSites::OnTopSitesAvailableFromHistory( 907 void TopSites::OnTopSitesAvailableFromHistory(
902 CancelableRequestProvider::Handle handle, 908 CancelableRequestProvider::Handle handle,
903 MostVisitedURLList pages) { 909 MostVisitedURLList pages) {
904 SetTopSites(pages); 910 SetTopSites(pages);
911
912 // Used only in testing.
913 NotificationService::current()->Notify(
914 NotificationType::TOP_SITES_UPDATED,
915 Source<TopSites>(this),
916 Details<CancelableRequestProvider::Handle>(&handle));
905 } 917 }
906 918
907 } // namespace history 919 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698