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 "suggestions" view. |
| 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 static void RegisterUserPrefs(PrefService* prefs); |
| 61 |
| 62 private: |
| 63 // Send a request to the HistoryService to get the suggestions pages. |
| 64 void StartQueryForSuggestions(); |
| 65 |
| 66 // Sets pages_value_ from a format produced by TopSites. |
| 67 void SetPagesValueFromTopSites(const history::MostVisitedURLList& data); |
| 68 |
| 69 // Callback for History. |
| 70 void OnSuggestionsURLsAvailable( |
| 71 CancelableRequestProvider::Handle handle, |
| 72 history::MostVisitedURLList data); |
| 73 |
| 74 // Puts the passed URL in the blacklist (so it does not show as a thumbnail). |
| 75 void BlacklistURL(const GURL& url); |
| 76 |
| 77 // Returns the key used in url_blacklist_ for the passed |url|. |
| 78 std::string GetDictionaryKeyForURL(const std::string& url); |
| 79 |
| 80 // Sends pages_value_ to the javascript side to and resets page_value_. |
| 81 void SendPagesValue(); |
| 82 |
| 83 content::NotificationRegistrar registrar_; |
| 84 |
| 85 // Our consumer for the history service. |
| 86 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_; |
| 87 CancelableRequestConsumer history_consumer_; |
| 88 CancelableRequestConsumer topsites_consumer_; |
| 89 |
| 90 // We pre-fetch the first set of result pages. This variable is false until |
| 91 // we get the first getSuggestions() call. |
| 92 bool got_first_suggestions_request_; |
| 93 |
| 94 // Keep the results of the db query here. |
| 95 scoped_ptr<base::ListValue> pages_value_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler); |
| 98 }; |
| 99 |
| 100 #endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_ |
OLD | NEW |