Index: components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h |
diff --git a/components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h b/components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..23727465e8450faa656fd557caa4f180916241f8 |
--- /dev/null |
+++ b/components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h |
@@ -0,0 +1,61 @@ |
+// 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_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ |
+#define COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_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 NTPTilesInternalsMessageHandlerClient; |
+ |
+// Implements the WebUI message handler for chrome://ntp-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 NTPTilesInternalsMessageHandler : public MostVisitedSites::Observer { |
+ public: |
+ NTPTilesInternalsMessageHandler(); |
+ ~NTPTilesInternalsMessageHandler() override; |
+ |
+ // Called when the WebUI page's JavaScript has loaded and it is ready to |
+ // receive RegisterMessageCallback() calls. |client| must outlive this object. |
+ void RegisterMessages(NTPTilesInternalsMessageHandlerClient* client); |
+ |
+ private: |
+ // Callbacks registered in RegisterMessages(). |
+ void HandleRegisterForEvents(const base::ListValue* args); |
+ void HandleUpdate(const base::ListValue* args); |
+ |
+ void SendSourceInfo(); |
+ void SendTiles(const NTPTilesVector& tiles); |
+ |
+ // MostVisitedSites::Observer. |
+ void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; |
+ void OnIconMadeAvailable(const GURL& site_url) override; |
+ |
+ // Bridge to embedder's API. |
+ NTPTilesInternalsMessageHandlerClient* client_; |
+ |
+ int site_count_; |
+ std::unique_ptr<MostVisitedSites> most_visited_sites_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler); |
+}; |
+ |
+} // namespace ntp_tiles |
+ |
+#endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ |