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

Unified Diff: chrome/browser/ui/webui/ntp/suggested_page_handler.h

Issue 9358031: Added new adaptive "Suggest" tab on the New Tab Page, behing the flag, for the experiments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove extra line Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/suggested_page_handler.h
diff --git a/chrome/browser/ui/webui/ntp/suggested_page_handler.h b/chrome/browser/ui/webui/ntp/suggested_page_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..0f59d233244a5e1e4fcc8ce34ef1dce1988c425b
--- /dev/null
+++ b/chrome/browser/ui/webui/ntp/suggested_page_handler.h
@@ -0,0 +1,108 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
Dan Beam 2012/02/09 01:43:06 2012
GeorgeY 2012/02/10 00:00:36 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTED_PAGE_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTED_PAGE_HANDLER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "chrome/browser/cancelable_request.h"
+#include "chrome/browser/history/history_types.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/web_ui_message_handler.h"
+
+class GURL;
+class PageUsageData;
+class PrefService;
+
+namespace base {
+class ListValue;
+class Value;
+}
+
+// The handler for Javascript messages related to the "most visited" view.
+//
+// This class manages one preference:
+// - The URL blacklist: URLs we do not want to show in the thumbnails list. It
+// is a dictionary for quick access (it associates a dummy boolean to the URL
+// string).
+class SuggestedHandler : public content::WebUIMessageHandler,
+ public content::NotificationObserver {
+ public:
+
+ SuggestedHandler();
+ virtual ~SuggestedHandler();
+
+ // WebUIMessageHandler override and implementation.
+ virtual void RegisterMessages() OVERRIDE;
+
+ // Callback for the "getSuggested" message.
+ void HandleGetSuggested(const base::ListValue* args);
+
+ // Callback for the "blacklistURLFromSuggested" message.
+ void HandleBlacklistURL(const base::ListValue* args);
+
+ // Callback for the "removeURLsFromSuggestedBlacklist" message.
+ void HandleRemoveURLsFromBlacklist(const base::ListValue* args);
+
+ // Callback for the "clearSuggestedURLsBlacklist" message.
+ void HandleClearBlacklist(const base::ListValue* args);
+
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ const std::vector<GURL>& most_visited_urls() const {
+ return most_visited_urls_;
+ }
+
+ static void RegisterUserPrefs(PrefService* prefs);
+
+ private:
+ struct SuggestedPage;
+
+ // Send a request to the HistoryService to get the most visited pages.
+ void StartQueryForSuggested();
+
+ // Sets pages_value_ from a format produced by TopSites.
+ void SetPagesValueFromTopSites(const history::MostVisitedURLList& data);
+
+ // Callback for TopSites.
+ void OnSuggestedURLsAvailable(const history::MostVisitedURLList& data);
+
+ // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
+ void BlacklistURL(const GURL& url);
+
+ // Returns the key used in url_blacklist_ for the passed |url|.
+ std::string GetDictionaryKeyForURL(const std::string& url);
+
+ // Sends pages_value_ to the javascript side to and resets page_value_.
+ void SendPagesValue();
+
+ content::NotificationRegistrar registrar_;
+
+ // Our consumer for the history service.
+ CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
+ CancelableRequestConsumer topsites_consumer_;
+
+ // The most visited URLs, in priority order.
+ // Only used for matching up clicks on the page to which most visited entry
+ // was clicked on for metrics purposes.
+ std::vector<GURL> most_visited_urls_;
+
+ // We pre-fetch the first set of result pages. This variable is false until
+ // we get the first getSuggested() call.
+ bool got_first_suggested_request_;
+
+ // Keep the results of the db query here.
+ scoped_ptr<base::ListValue> pages_value_;
+
+ DISALLOW_COPY_AND_ASSIGN(SuggestedHandler);
+};
+
+#endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTED_PAGE_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698