Index: components/ntp_tiles/webui/site_tiles_internals_message_handler.h |
diff --git a/components/ntp_tiles/webui/site_tiles_internals_message_handler.h b/components/ntp_tiles/webui/site_tiles_internals_message_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7a5958fbd26dc6fd890c0f969c150954ee8cc65d |
--- /dev/null |
+++ b/components/ntp_tiles/webui/site_tiles_internals_message_handler.h |
@@ -0,0 +1,67 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_NTP_TILES_WEBUI_SITE_TILES_HANDLER_H_ |
+#define COMPONENTS_NTP_TILES_WEBUI_SITE_TILES_HANDLER_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "components/ntp_tiles/most_visited_sites.h" |
+ |
+namespace base { |
+class ListValue; |
+} // namespace base |
+ |
+namespace ntp_tiles { |
+ |
+class MostVisitedSites; |
+class SiteTilesInternalsMessageHandlerClient; |
+ |
+// Implements the WebUI message handler for chrome://site-tiles-internals/ |
+// |
+// Because content and iOS use different implementations of WebUI, this class |
+// implements the generic portion and depends on the embedder to inject a bridge |
+// to the embedder's API. It cannot itself implement either API directly. |
+class SiteTilesInternalsMessageHandler : public MostVisitedSites::Observer { |
Marc Treib
2016/12/08 15:41:50
I'm not entirely happy with the name, since it's n
sfiera
2016/12/08 16:44:35
If you were looking for the message handler for ch
|
+ public: |
+ explicit SiteTilesInternalsMessageHandler( |
+ SiteTilesInternalsMessageHandlerClient* web_ui); |
+ ~SiteTilesInternalsMessageHandler() override; |
+ |
+ // Called when the WebUI page's JavaScript has loaded and it is ready to |
+ // receive RegisterMessageCallback() calls. |
+ void RegisterMessages(); |
+ |
+ private: |
+ // Callbacks registered in RegisterMessages(). |
+ void HandleRegisterForEvents(const base::ListValue* args); |
+ void HandleUpdate(const base::ListValue* args); |
+ void HandleViewPopularSitesJson(const base::ListValue* args); |
+ void HandleGetFavicon(const base::ListValue* args); |
+ |
+ void SendSourceInfo(); |
+ void SendTiles(const NTPTilesVector& tiles); |
+ void SendPopularSitesJson(const std::string& json); |
+ |
+ // MostVisitedSites::Observer. |
+ void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; |
+ void OnIconMadeAvailable(const GURL& site_url) override; |
+ |
+ // Bridge to embedder's API. |
+ SiteTilesInternalsMessageHandlerClient* web_ui_; |
Marc Treib
2016/12/08 15:41:50
|client_|? IMO web_ui_ is a bit confusing.
sfiera
2016/12/08 16:44:35
Done.
|
+ |
+ int site_count_; |
+ std::unique_ptr<MostVisitedSites> most_visited_sites_; |
+ |
+ base::WeakPtrFactory<SiteTilesInternalsMessageHandler> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SiteTilesInternalsMessageHandler); |
+}; |
+ |
+} // namespace ntp_tiles |
+ |
+#endif // COMPONENTS_NTP_TILES_WEBUI_SITE_TILES_HANDLER_H_ |