Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/browser/ui/webui/ntp/most_visited_handler.h

Issue 845013002: Remove TopSites notification in favor of Observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing typo causing compilation issues on win Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/scoped_observer.h"
12 #include "components/history/core/browser/history_types.h" 13 #include "components/history/core/browser/history_types.h"
13 #include "content/public/browser/notification_observer.h" 14 #include "components/history/core/browser/top_sites_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_ui_message_handler.h" 15 #include "content/public/browser/web_ui_message_handler.h"
16 16
17 class GURL; 17 class GURL;
18 class PageUsageData; 18 class PageUsageData;
19 19
20 namespace base { 20 namespace base {
21 class ListValue; 21 class ListValue;
22 class Value; 22 class Value;
23 } 23 }
24 24
25 namespace user_prefs { 25 namespace user_prefs {
26 class PrefRegistrySyncable; 26 class PrefRegistrySyncable;
27 } 27 }
28 28
29 // The handler for Javascript messages related to the "most visited" view. 29 // The handler for Javascript messages related to the "most visited" view.
30 // 30 //
31 // This class manages one preference: 31 // This class manages one preference:
32 // - The URL blacklist: URLs we do not want to show in the thumbnails list. It 32 // - The URL blacklist: URLs we do not want to show in the thumbnails list. It
33 // is a dictionary for quick access (it associates a dummy boolean to the URL 33 // is a dictionary for quick access (it associates a dummy boolean to the URL
34 // string). 34 // string).
35 class MostVisitedHandler : public content::WebUIMessageHandler, 35 class MostVisitedHandler : public content::WebUIMessageHandler,
36 public content::NotificationObserver { 36 public history::TopSitesObserver {
37 public: 37 public:
38 38
39 MostVisitedHandler(); 39 MostVisitedHandler();
40 ~MostVisitedHandler() override; 40 ~MostVisitedHandler() override;
41 41
42 // WebUIMessageHandler override and implementation. 42 // WebUIMessageHandler override and implementation.
43 void RegisterMessages() override; 43 void RegisterMessages() override;
44 44
45 // Callback for the "getMostVisited" message. 45 // Callback for the "getMostVisited" message.
46 void HandleGetMostVisited(const base::ListValue* args); 46 void HandleGetMostVisited(const base::ListValue* args);
47 47
48 // Callback for the "blacklistURLFromMostVisited" message. 48 // Callback for the "blacklistURLFromMostVisited" message.
49 void HandleBlacklistUrl(const base::ListValue* args); 49 void HandleBlacklistUrl(const base::ListValue* args);
50 50
51 // Callback for the "removeURLsFromMostVisitedBlacklist" message. 51 // Callback for the "removeURLsFromMostVisitedBlacklist" message.
52 void HandleRemoveUrlsFromBlacklist(const base::ListValue* args); 52 void HandleRemoveUrlsFromBlacklist(const base::ListValue* args);
53 53
54 // Callback for the "clearMostVisitedURLsBlacklist" message. 54 // Callback for the "clearMostVisitedURLsBlacklist" message.
55 void HandleClearBlacklist(const base::ListValue* args); 55 void HandleClearBlacklist(const base::ListValue* args);
56 56
57 // Callback for the "mostVisitedAction" message. 57 // Callback for the "mostVisitedAction" message.
58 void HandleMostVisitedAction(const base::ListValue* args); 58 void HandleMostVisitedAction(const base::ListValue* args);
59 59
60 // Callback for the "mostVisitedSelected" message. 60 // Callback for the "mostVisitedSelected" message.
61 void HandleMostVisitedSelected(const base::ListValue* args); 61 void HandleMostVisitedSelected(const base::ListValue* args);
62 62
63 // content::NotificationObserver implementation.
64 void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) override;
67
68 const std::vector<GURL>& most_visited_urls() const { 63 const std::vector<GURL>& most_visited_urls() const {
69 return most_visited_urls_; 64 return most_visited_urls_;
70 } 65 }
71 66
72 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 67 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
73 68
74 private: 69 private:
75 struct MostVisitedPage; 70 struct MostVisitedPage;
76 71
77 // Send a request to the HistoryService to get the most visited pages. 72 // Send a request to the HistoryService to get the most visited pages.
78 void StartQueryForMostVisited(); 73 void StartQueryForMostVisited();
79 74
80 // Sets pages_value_ from a format produced by TopSites. 75 // Sets pages_value_ from a format produced by TopSites.
81 void SetPagesValueFromTopSites(const history::MostVisitedURLList& data); 76 void SetPagesValueFromTopSites(const history::MostVisitedURLList& data);
82 77
83 // Callback for TopSites. 78 // Callback for TopSites.
84 void OnMostVisitedUrlsAvailable(const history::MostVisitedURLList& data); 79 void OnMostVisitedUrlsAvailable(const history::MostVisitedURLList& data);
85 80
86 // Puts the passed URL in the blacklist (so it does not show as a thumbnail). 81 // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
87 void BlacklistUrl(const GURL& url); 82 void BlacklistUrl(const GURL& url);
88 83
89 // Returns the key used in url_blacklist_ for the passed |url|. 84 // Returns the key used in url_blacklist_ for the passed |url|.
90 std::string GetDictionaryKeyForUrl(const std::string& url); 85 std::string GetDictionaryKeyForUrl(const std::string& url);
91 86
92 // Sends pages_value_ to the javascript side and resets page_value_. 87 // Sends pages_value_ to the javascript side and resets page_value_.
93 void SendPagesValue(); 88 void SendPagesValue();
94 89
95 content::NotificationRegistrar registrar_; 90 // history::TopSitesObserver implementation.
91 void TopSitesLoaded(history::TopSites* top_sites) override;
92 void TopSitesChanged(history::TopSites* top_sites) override;
93
94 // Scoped observer to help with TopSitesObserver registration.
95 ScopedObserver<history::TopSites, history::TopSitesObserver> scoped_observer_;
96 96
97 // The most visited URLs, in priority order. 97 // The most visited URLs, in priority order.
98 // Only used for matching up clicks on the page to which most visited entry 98 // Only used for matching up clicks on the page to which most visited entry
99 // was clicked on for metrics purposes. 99 // was clicked on for metrics purposes.
100 std::vector<GURL> most_visited_urls_; 100 std::vector<GURL> most_visited_urls_;
101 101
102 // We pre-fetch the first set of result pages. This variable is false until 102 // We pre-fetch the first set of result pages. This variable is false until
103 // we get the first getMostVisited() call. 103 // we get the first getMostVisited() call.
104 bool got_first_most_visited_request_; 104 bool got_first_most_visited_request_;
105 105
106 // Keep the results of the db query here. 106 // Keep the results of the db query here.
107 scoped_ptr<base::ListValue> pages_value_; 107 scoped_ptr<base::ListValue> pages_value_;
108 108
109 // Whether the user has viewed the 'most visited' pane. 109 // Whether the user has viewed the 'most visited' pane.
110 bool most_visited_viewed_; 110 bool most_visited_viewed_;
111 111
112 // Whether the user has performed a "tracked" action to leave the page or not. 112 // Whether the user has performed a "tracked" action to leave the page or not.
113 bool user_action_logged_; 113 bool user_action_logged_;
114 114
115 // For callbacks which may be run after destruction. 115 // For callbacks which may be run after destruction.
116 base::WeakPtrFactory<MostVisitedHandler> weak_ptr_factory_; 116 base::WeakPtrFactory<MostVisitedHandler> weak_ptr_factory_;
117 117
118 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); 118 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler);
119 }; 119 };
120 120
121 #endif // CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ 121 #endif // CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698