NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / most_visited_handler.h
bloba00218551e01f0b3640030e50d4b6bba571d6a1e
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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/common/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"
18 class GURL;
19 class PageUsageData;
21 namespace base {
22 class ListValue;
23 class Value;
26 namespace user_prefs {
27 class PrefRegistrySyncable;
30 // The handler for Javascript messages related to the "most visited" view.
32 // This class manages one preference:
33 // - The URL blacklist: URLs we do not want to show in the thumbnails list. It
34 // is a dictionary for quick access (it associates a dummy boolean to the URL
35 // string).
36 class MostVisitedHandler : public content::WebUIMessageHandler,
37 public content::NotificationObserver {
38 public:
40 MostVisitedHandler();
41 virtual ~MostVisitedHandler();
43 // WebUIMessageHandler override and implementation.
44 virtual void RegisterMessages() OVERRIDE;
46 // Callback for the "getMostVisited" message.
47 void HandleGetMostVisited(const base::ListValue* args);
49 // Callback for the "blacklistURLFromMostVisited" message.
50 void HandleBlacklistUrl(const base::ListValue* args);
52 // Callback for the "removeURLsFromMostVisitedBlacklist" message.
53 void HandleRemoveUrlsFromBlacklist(const base::ListValue* args);
55 // Callback for the "clearMostVisitedURLsBlacklist" message.
56 void HandleClearBlacklist(const base::ListValue* args);
58 // Callback for the "mostVisitedAction" message.
59 void HandleMostVisitedAction(const base::ListValue* args);
61 // Callback for the "mostVisitedSelected" message.
62 void HandleMostVisitedSelected(const base::ListValue* args);
64 // content::NotificationObserver implementation.
65 virtual void Observe(int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) OVERRIDE;
69 const std::vector<GURL>& most_visited_urls() const {
70 return most_visited_urls_;
73 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
75 private:
76 struct MostVisitedPage;
78 // Send a request to the HistoryService to get the most visited pages.
79 void StartQueryForMostVisited();
81 // Sets pages_value_ from a format produced by TopSites.
82 void SetPagesValueFromTopSites(const history::MostVisitedURLList& data);
84 // Callback for TopSites.
85 void OnMostVisitedUrlsAvailable(const history::MostVisitedURLList& data);
87 // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
88 void BlacklistUrl(const GURL& url);
90 // Returns the key used in url_blacklist_ for the passed |url|.
91 std::string GetDictionaryKeyForUrl(const std::string& url);
93 // Removes recommended URLs if a matching URL is already open in the Browser,
94 // if the Most Visited Tile Placement experiment is enabled, and the client is
95 // in the experiment group.
96 void MaybeRemovePageValues();
98 // Sends pages_value_ to the javascript side and resets page_value_.
99 void SendPagesValue();
101 content::NotificationRegistrar registrar_;
103 // The most visited URLs, in priority order.
104 // Only used for matching up clicks on the page to which most visited entry
105 // was clicked on for metrics purposes.
106 std::vector<GURL> most_visited_urls_;
108 // We pre-fetch the first set of result pages. This variable is false until
109 // we get the first getMostVisited() call.
110 bool got_first_most_visited_request_;
112 // Keep the results of the db query here.
113 scoped_ptr<base::ListValue> pages_value_;
115 // Whether the user has viewed the 'most visited' pane.
116 bool most_visited_viewed_;
118 // Whether the user has performed a "tracked" action to leave the page or not.
119 bool user_action_logged_;
121 // For callbacks which may be run after destruction.
122 base::WeakPtrFactory<MostVisitedHandler> weak_ptr_factory_;
124 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler);
127 #endif // CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_