Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "chrome/browser/cancelable_request.h" | |
| 13 #include "chrome/browser/history/history_types.h" | |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 #include "content/public/browser/web_ui_message_handler.h" | |
| 17 | |
| 18 class GURL; | |
| 19 class PageUsageData; | |
| 20 class PrefService; | |
| 21 | |
| 22 namespace base { | |
| 23 class ListValue; | |
| 24 class Value; | |
| 25 } | |
| 26 | |
| 27 // 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.
| |
| 28 // | |
| 29 // This class manages one preference: | |
| 30 // - The URL blacklist: URLs we do not want to show in the thumbnails list. It | |
| 31 // is a dictionary for quick access (it associates a dummy boolean to the URL | |
| 32 // string). | |
| 33 class SuggestionsHandler : public content::WebUIMessageHandler, | |
| 34 public content::NotificationObserver { | |
| 35 public: | |
| 36 | |
| 37 SuggestionsHandler(); | |
| 38 virtual ~SuggestionsHandler(); | |
| 39 | |
| 40 // WebUIMessageHandler override and implementation. | |
| 41 virtual void RegisterMessages() OVERRIDE; | |
| 42 | |
| 43 // Callback for the "getSuggestions" message. | |
| 44 void HandleGetSuggestions(const base::ListValue* args); | |
| 45 | |
| 46 // Callback for the "blacklistURLFromSuggestions" message. | |
| 47 void HandleBlacklistURL(const base::ListValue* args); | |
| 48 | |
| 49 // Callback for the "removeURLsFromSuggestionsBlacklist" message. | |
| 50 void HandleRemoveURLsFromBlacklist(const base::ListValue* args); | |
| 51 | |
| 52 // Callback for the "clearSuggestionsURLsBlacklist" message. | |
| 53 void HandleClearBlacklist(const base::ListValue* args); | |
| 54 | |
| 55 // content::NotificationObserver implementation. | |
| 56 virtual void Observe(int type, | |
| 57 const content::NotificationSource& source, | |
| 58 const content::NotificationDetails& details) OVERRIDE; | |
| 59 | |
| 60 const std::vector<GURL>& most_visited_urls() const { | |
| 61 return most_visited_urls_; | |
| 62 } | |
| 63 | |
| 64 static void RegisterUserPrefs(PrefService* prefs); | |
| 65 | |
| 66 private: | |
| 67 // 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.
| |
| 68 void StartQueryForSuggestions(); | |
| 69 | |
| 70 // Sets pages_value_ from a format produced by TopSites. | |
| 71 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
| |
| 72 | |
| 73 // Callback for TopSites. | |
| 74 void OnSuggestionsURLsAvailable(const history::MostVisitedURLList& data); | |
| 75 | |
| 76 // Puts the passed URL in the blacklist (so it does not show as a thumbnail). | |
| 77 void BlacklistURL(const GURL& url); | |
| 78 | |
| 79 // Returns the key used in url_blacklist_ for the passed |url|. | |
| 80 std::string GetDictionaryKeyForURL(const std::string& url); | |
| 81 | |
| 82 // Sends pages_value_ to the javascript side to and resets page_value_. | |
| 83 void SendPagesValue(); | |
| 84 | |
| 85 content::NotificationRegistrar registrar_; | |
| 86 | |
| 87 // Our consumer for the history service. | |
| 88 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_; | |
| 89 CancelableRequestConsumer topsites_consumer_; | |
| 90 | |
| 91 // 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
| |
| 92 // Only used for matching up clicks on the page to which most visited entry | |
| 93 // was clicked on for metrics purposes. | |
| 94 std::vector<GURL> most_visited_urls_; | |
| 95 | |
| 96 // We pre-fetch the first set of result pages. This variable is false until | |
| 97 // we get the first getSuggestions() call. | |
| 98 bool got_first_suggestions_request_; | |
| 99 | |
| 100 // Keep the results of the db query here. | |
| 101 scoped_ptr<base::ListValue> pages_value_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler); | |
| 104 }; | |
| 105 | |
| 106 #endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ | |
| OLD | NEW |