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

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

Issue 8369017: ntp: remove dead code for pinning (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't crash Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/most_visited_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "chrome/browser/history/history_types.h" 12 #include "chrome/browser/history/history_types.h"
13 #include "content/browser/cancelable_request.h" 13 #include "content/browser/cancelable_request.h"
14 #include "content/browser/webui/web_ui.h" 14 #include "content/browser/webui/web_ui.h"
15 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 17
18 class GURL; 18 class GURL;
19 class PageUsageData; 19 class PageUsageData;
20 class PrefService; 20 class PrefService;
21 21
22 namespace base { 22 namespace base {
23 class ListValue; 23 class ListValue;
24 class Value; 24 class Value;
25 } 25 }
26 26
27 // The handler for Javascript messages related to the "most visited" view. 27 // The handler for Javascript messages related to the "most visited" view.
28 // 28 //
29 // This class manages two preferences: 29 // This class manages one preference:
30 // - The URL blacklist: URLs we do not want to show in the thumbnails list. It 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 31 // is a dictionary for quick access (it associates a dummy boolean to the URL
32 // string). 32 // string).
33 // - Pinned URLs: This is a dictionary for the pinned URLs for the the most
34 // visited part of the new tab page. The key of the dictionary is a hash of
35 // the URL and the value is a dictionary with title, url and index. This is
36 // owned by the PrefService.
37 class MostVisitedHandler : public WebUIMessageHandler, 33 class MostVisitedHandler : public WebUIMessageHandler,
38 public content::NotificationObserver { 34 public content::NotificationObserver {
39 public: 35 public:
40 36
41 MostVisitedHandler(); 37 MostVisitedHandler();
42 virtual ~MostVisitedHandler(); 38 virtual ~MostVisitedHandler();
43 39
44 // WebUIMessageHandler override and implementation. 40 // WebUIMessageHandler override and implementation.
45 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; 41 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE;
46 virtual void RegisterMessages() OVERRIDE; 42 virtual void RegisterMessages() OVERRIDE;
47 43
48 // Callback for the "getMostVisited" message. 44 // Callback for the "getMostVisited" message.
49 void HandleGetMostVisited(const base::ListValue* args); 45 void HandleGetMostVisited(const base::ListValue* args);
50 46
51 // Callback for the "blacklistURLFromMostVisited" message. 47 // Callback for the "blacklistURLFromMostVisited" message.
52 void HandleBlacklistURL(const base::ListValue* args); 48 void HandleBlacklistURL(const base::ListValue* args);
53 49
54 // Callback for the "removeURLsFromMostVisitedBlacklist" message. 50 // Callback for the "removeURLsFromMostVisitedBlacklist" message.
55 void HandleRemoveURLsFromBlacklist(const base::ListValue* args); 51 void HandleRemoveURLsFromBlacklist(const base::ListValue* args);
56 52
57 // Callback for the "clearMostVisitedURLsBlacklist" message. 53 // Callback for the "clearMostVisitedURLsBlacklist" message.
58 void HandleClearBlacklist(const base::ListValue* args); 54 void HandleClearBlacklist(const base::ListValue* args);
59 55
60 // Callback for the "addPinnedURL" message.
61 void HandleAddPinnedURL(const base::ListValue* args);
62
63 // Callback for the "removePinnedURL" message.
64 void HandleRemovePinnedURL(const base::ListValue* args);
65
66 // content::NotificationObserver implementation. 56 // content::NotificationObserver implementation.
67 virtual void Observe(int type, 57 virtual void Observe(int type,
68 const content::NotificationSource& source, 58 const content::NotificationSource& source,
69 const content::NotificationDetails& details) OVERRIDE; 59 const content::NotificationDetails& details) OVERRIDE;
70 60
71 const std::vector<GURL>& most_visited_urls() const { 61 const std::vector<GURL>& most_visited_urls() const {
72 return most_visited_urls_; 62 return most_visited_urls_;
73 } 63 }
74 64
75 static void RegisterUserPrefs(PrefService* prefs); 65 static void RegisterUserPrefs(PrefService* prefs);
76 66
77 private: 67 private:
78 struct MostVisitedPage; 68 struct MostVisitedPage;
79 69
80 // Send a request to the HistoryService to get the most visited pages. 70 // Send a request to the HistoryService to get the most visited pages.
81 void StartQueryForMostVisited(); 71 void StartQueryForMostVisited();
82 72
83 // Sets pages_value_ from a format produced by TopSites. 73 // Sets pages_value_ from a format produced by TopSites.
84 void SetPagesValueFromTopSites(const history::MostVisitedURLList& data); 74 void SetPagesValueFromTopSites(const history::MostVisitedURLList& data);
85 75
86 // Callback for TopSites. 76 // Callback for TopSites.
87 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data); 77 void OnMostVisitedURLsAvailable(const history::MostVisitedURLList& data);
88 78
89 // Puts the passed URL in the blacklist (so it does not show as a thumbnail). 79 // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
90 void BlacklistURL(const GURL& url); 80 void BlacklistURL(const GURL& url);
91 81
92 // Returns the key used in url_blacklist_ and pinned_urls_ for the passed 82 // Returns the key used in url_blacklist_ for the passed |url|.
93 // |url|.
94 std::string GetDictionaryKeyForURL(const std::string& url); 83 std::string GetDictionaryKeyForURL(const std::string& url);
95 84
96 // Gets the page data for a pinned URL at a given index. This returns
97 // true if found.
98 bool GetPinnedURLAtIndex(int index, MostVisitedPage* page);
99
100 void AddPinnedURL(const MostVisitedPage& page, int index);
101 void RemovePinnedURL(const GURL& url);
102
103 // Sends pages_value_ to the javascript side to and resets page_value_. 85 // Sends pages_value_ to the javascript side to and resets page_value_.
104 void SendPagesValue(); 86 void SendPagesValue();
105 87
106 content::NotificationRegistrar registrar_; 88 content::NotificationRegistrar registrar_;
107 89
108 // Our consumer for the history service. 90 // Our consumer for the history service.
109 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_; 91 CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
110 CancelableRequestConsumer topsites_consumer_; 92 CancelableRequestConsumer topsites_consumer_;
111 93
112 // The most visited URLs, in priority order. 94 // The most visited URLs, in priority order.
113 // Only used for matching up clicks on the page to which most visited entry 95 // Only used for matching up clicks on the page to which most visited entry
114 // was clicked on for metrics purposes. 96 // was clicked on for metrics purposes.
115 std::vector<GURL> most_visited_urls_; 97 std::vector<GURL> most_visited_urls_;
116 98
117 // We pre-fetch the first set of result pages. This variable is false until 99 // We pre-fetch the first set of result pages. This variable is false until
118 // we get the first getMostVisited() call. 100 // we get the first getMostVisited() call.
119 bool got_first_most_visited_request_; 101 bool got_first_most_visited_request_;
120 102
121 // Keep the results of the db query here. 103 // Keep the results of the db query here.
122 scoped_ptr<base::ListValue> pages_value_; 104 scoped_ptr<base::ListValue> pages_value_;
123 105
124 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler); 106 DISALLOW_COPY_AND_ASSIGN(MostVisitedHandler);
125 }; 107 };
126 108
127 #endif // CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_ 109 #endif // CHROME_BROWSER_UI_WEBUI_NTP_MOST_VISITED_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/most_visited_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698