Chromium Code Reviews| Index: chrome/browser/ui/webui/ntp/suggestions_page_handler.h |
| diff --git a/chrome/browser/ui/webui/ntp/suggestions_page_handler.h b/chrome/browser/ui/webui/ntp/suggestions_page_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23dc3a0e763746b60913db1eb74bbc26dd35a40a |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/ntp/suggestions_page_handler.h |
| @@ -0,0 +1,106 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ |
| +#define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "chrome/browser/cancelable_request.h" |
| +#include "chrome/browser/history/history_types.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| +#include "content/public/browser/web_ui_message_handler.h" |
| + |
| +class GURL; |
| +class PageUsageData; |
| +class PrefService; |
| + |
| +namespace base { |
| +class ListValue; |
| +class Value; |
| +} |
| + |
| +// The handler for Javascript messages related to the "most visited" view. |
|
Dan Beam
2012/02/28 20:14:24
s/"most visited"/"suggestions"/ (or "suggested", w
GeorgeY
2012/02/28 21:17:42
Done.
|
| +// |
| +// This class manages one preference: |
| +// - The URL blacklist: URLs we do not want to show in the thumbnails list. It |
| +// is a dictionary for quick access (it associates a dummy boolean to the URL |
| +// string). |
| +class SuggestionsHandler : public content::WebUIMessageHandler, |
| + public content::NotificationObserver { |
| + public: |
| + |
| + SuggestionsHandler(); |
| + virtual ~SuggestionsHandler(); |
| + |
| + // WebUIMessageHandler override and implementation. |
| + virtual void RegisterMessages() OVERRIDE; |
| + |
| + // Callback for the "getSuggestions" message. |
| + void HandleGetSuggestions(const base::ListValue* args); |
| + |
| + // Callback for the "blacklistURLFromSuggestions" message. |
| + void HandleBlacklistURL(const base::ListValue* args); |
| + |
| + // Callback for the "removeURLsFromSuggestionsBlacklist" message. |
| + void HandleRemoveURLsFromBlacklist(const base::ListValue* args); |
| + |
| + // Callback for the "clearSuggestionsURLsBlacklist" message. |
| + void HandleClearBlacklist(const base::ListValue* args); |
| + |
| + // content::NotificationObserver implementation. |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + const std::vector<GURL>& most_visited_urls() const { |
| + return most_visited_urls_; |
| + } |
| + |
| + static void RegisterUserPrefs(PrefService* prefs); |
| + |
| + private: |
| + // Send a request to the HistoryService to get the most visited pages. |
|
Dan Beam
2012/02/28 20:14:24
s/most visited/suggest{ions,ed}/
GeorgeY
2012/02/28 21:17:42
Done.
|
| + void StartQueryForSuggestions(); |
| + |
| + // Sets pages_value_ from a format produced by TopSites. |
| + void SetPagesValueFromTopSites(const history::MostVisitedURLList& data); |
|
Dan Beam
2012/02/28 20:14:24
should these be a history::MostVisitedURLList?
GeorgeY
2012/02/28 21:17:42
Yes, this is the container we use now
|
| + |
| + // Callback for TopSites. |
| + void OnSuggestionsURLsAvailable(const history::MostVisitedURLList& data); |
| + |
| + // Puts the passed URL in the blacklist (so it does not show as a thumbnail). |
| + void BlacklistURL(const GURL& url); |
| + |
| + // Returns the key used in url_blacklist_ for the passed |url|. |
| + std::string GetDictionaryKeyForURL(const std::string& url); |
| + |
| + // Sends pages_value_ to the javascript side to and resets page_value_. |
| + void SendPagesValue(); |
| + |
| + content::NotificationRegistrar registrar_; |
| + |
| + // Our consumer for the history service. |
| + CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_; |
| + CancelableRequestConsumer topsites_consumer_; |
| + |
| + // The most visited URLs, in priority order. |
|
Dan Beam
2012/02/28 20:14:24
s/most visited/ ... you get the idea
GeorgeY
2012/02/28 21:17:42
removed
|
| + // Only used for matching up clicks on the page to which most visited entry |
| + // was clicked on for metrics purposes. |
| + std::vector<GURL> most_visited_urls_; |
| + |
| + // We pre-fetch the first set of result pages. This variable is false until |
| + // we get the first getSuggestions() call. |
| + bool got_first_suggestions_request_; |
| + |
| + // Keep the results of the db query here. |
| + scoped_ptr<base::ListValue> pages_value_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ |