| Index: chrome/browser/ui/search/instant_controller.cc
|
| diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
|
| index f9fe9cd9c04b22cfbc39d9209ee4b4659fda823d..88635c43c77cd2508e027c14642de677fd6522f2 100644
|
| --- a/chrome/browser/ui/search/instant_controller.cc
|
| +++ b/chrome/browser/ui/search/instant_controller.cc
|
| @@ -16,7 +16,6 @@
|
| #include "chrome/browser/history/history_service.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/history/history_tab_helper.h"
|
| -#include "chrome/browser/history/top_sites.h"
|
| #include "chrome/browser/platform_util.h"
|
| #include "chrome/browser/search/instant_service.h"
|
| #include "chrome/browser/search/instant_service_factory.h"
|
| @@ -211,22 +210,6 @@ void EnsureSearchTermsAreSet(content::WebContents* contents,
|
| SearchTabHelper::FromWebContents(contents)->NavigationEntryUpdated();
|
| }
|
|
|
| -bool GetURLForMostVisitedItemID(Profile* profile,
|
| - InstantRestrictedID most_visited_item_id,
|
| - GURL* url) {
|
| - InstantService* instant_service =
|
| - InstantServiceFactory::GetForProfile(profile);
|
| - if (!instant_service)
|
| - return false;
|
| -
|
| - InstantMostVisitedItem item;
|
| - if (!instant_service->GetMostVisitedItemForID(most_visited_item_id, &item))
|
| - return false;
|
| -
|
| - *url = item.url;
|
| - return true;
|
| -}
|
| -
|
| template <typename T>
|
| void DeletePageSoon(scoped_ptr<T> page) {
|
| if (page->contents())
|
| @@ -252,8 +235,7 @@ InstantController::InstantController(BrowserInstantController* browser,
|
| last_match_was_search_(false),
|
| omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
|
| omnibox_bounds_(-1, -1, 0, 0),
|
| - allow_overlay_to_show_search_suggestions_(false),
|
| - weak_ptr_factory_(this) {
|
| + allow_overlay_to_show_search_suggestions_(false) {
|
|
|
| // When the InstantController lives, the InstantService should live.
|
| // InstantService sets up profile-level facilities such as the ThemeSource for
|
| @@ -1094,36 +1076,34 @@ void InstantController::ClearDebugEvents() {
|
| debug_events_.clear();
|
| }
|
|
|
| -void InstantController::DeleteMostVisitedItem(
|
| - InstantRestrictedID most_visited_item_id) {
|
| - history::TopSites* top_sites = browser_->profile()->GetTopSites();
|
| - if (!top_sites)
|
| +void InstantController::DeleteMostVisitedItem(const GURL& item_url) {
|
| + DCHECK(!item_url.is_empty());
|
| + InstantService* instant_service =
|
| + InstantServiceFactory::GetForProfile(profile());
|
| + if (!instant_service)
|
| return;
|
|
|
| - GURL url;
|
| - if (GetURLForMostVisitedItemID(browser_->profile(),
|
| - most_visited_item_id, &url))
|
| - top_sites->AddBlacklistedURL(url);
|
| + instant_service->DeleteMostVisitedItem(item_url);
|
| }
|
|
|
| void InstantController::UndoMostVisitedDeletion(
|
| - InstantRestrictedID most_visited_item_id) {
|
| - history::TopSites* top_sites = browser_->profile()->GetTopSites();
|
| - if (!top_sites)
|
| + const GURL& most_visited_item_url) {
|
| + DCHECK(!most_visited_item_url.is_empty());
|
| + InstantService* instant_service =
|
| + InstantServiceFactory::GetForProfile(profile());
|
| + if (!instant_service)
|
| return;
|
|
|
| - GURL url;
|
| - if (GetURLForMostVisitedItemID(browser_->profile(),
|
| - most_visited_item_id, &url))
|
| - top_sites->RemoveBlacklistedURL(url);
|
| + instant_service->UndoMostVisitedDeletion(most_visited_item_url);
|
| }
|
|
|
| void InstantController::UndoAllMostVisitedDeletions() {
|
| - history::TopSites* top_sites = browser_->profile()->GetTopSites();
|
| - if (!top_sites)
|
| + InstantService* instant_service =
|
| + InstantServiceFactory::GetForProfile(profile());
|
| + if (!instant_service)
|
| return;
|
|
|
| - top_sites->ClearBlacklistedURLs();
|
| + instant_service->UndoAllMostVisitedDeletions();
|
| }
|
|
|
| Profile* InstantController::profile() const {
|
| @@ -1142,13 +1122,6 @@ InstantNTP* InstantController::ntp() const {
|
| return ntp_.get();
|
| }
|
|
|
| -void InstantController::Observe(int type,
|
| - const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) {
|
| - DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED);
|
| - RequestMostVisitedItems();
|
| -}
|
| -
|
| // TODO(shishir): We assume that the WebContent's current RenderViewHost is the
|
| // RenderViewHost being created which is not always true. Fix this.
|
| void InstantController::InstantPageRenderViewCreated(
|
| @@ -1173,7 +1146,7 @@ void InstantController::InstantPageRenderViewCreated(
|
| } else {
|
| NOTREACHED();
|
| }
|
| - StartListeningToMostVisitedChanges();
|
| + UpdateMostVisitedItemsInfo();
|
| }
|
|
|
| void InstantController::InstantSupportDetermined(
|
| @@ -1542,7 +1515,7 @@ void InstantController::UpdateInfoForInstantTab() {
|
| instant_tab_->SetDisplayInstantResults(instant_enabled_);
|
| instant_tab_->SetOmniboxBounds(omnibox_bounds_);
|
| instant_tab_->InitializeFonts();
|
| - StartListeningToMostVisitedChanges();
|
| + UpdateMostVisitedItemsInfo();
|
| instant_tab_->KeyCaptureChanged(
|
| omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
|
| }
|
| @@ -1647,56 +1620,12 @@ void InstantController::SendPopupBoundsToPage() {
|
| overlay_->SetPopupBounds(intersection);
|
| }
|
|
|
| -void InstantController::StartListeningToMostVisitedChanges() {
|
| - history::TopSites* top_sites = browser_->profile()->GetTopSites();
|
| - if (top_sites) {
|
| - if (!registrar_.IsRegistered(
|
| - this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
|
| - content::Source<history::TopSites>(top_sites))) {
|
| - // TopSites updates itself after a delay. This is especially noticable
|
| - // when your profile is empty. Ask TopSites to update itself when we're
|
| - // about to show the new tab page.
|
| - top_sites->SyncWithHistory();
|
| -
|
| - RequestMostVisitedItems();
|
| -
|
| - // Register for notification when TopSites changes.
|
| - registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
|
| - content::Source<history::TopSites>(top_sites));
|
| - } else {
|
| - // We are already registered, so just get and send the most visited data.
|
| - RequestMostVisitedItems();
|
| - }
|
| - }
|
| -}
|
| -
|
| -void InstantController::RequestMostVisitedItems() {
|
| - history::TopSites* top_sites = browser_->profile()->GetTopSites();
|
| - if (top_sites) {
|
| - top_sites->GetMostVisitedURLs(
|
| - base::Bind(&InstantController::OnMostVisitedItemsReceived,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| - }
|
| -}
|
| -
|
| -void InstantController::OnMostVisitedItemsReceived(
|
| - const history::MostVisitedURLList& data) {
|
| +void InstantController::UpdateMostVisitedItemsInfo() {
|
| InstantService* instant_service =
|
| - InstantServiceFactory::GetForProfile(browser_->profile());
|
| + InstantServiceFactory::GetForProfile(profile());
|
| if (!instant_service)
|
| return;
|
|
|
| - std::vector<InstantMostVisitedItem> most_visited_items;
|
| - for (size_t i = 0; i < data.size(); i++) {
|
| - const history::MostVisitedURL& url = data[i];
|
| - InstantMostVisitedItem item;
|
| - item.url = url.url;
|
| - item.title = url.title;
|
| - most_visited_items.push_back(item);
|
| - }
|
| -
|
| - instant_service->AddMostVisitedItems(most_visited_items);
|
| -
|
| std::vector<InstantMostVisitedItemIDPair> items_with_ids;
|
| instant_service->GetCurrentMostVisitedItems(&items_with_ids);
|
| SendMostVisitedItems(items_with_ids);
|
|
|