Chromium Code Reviews| 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..586e4dda9406b41f767a17c341bdd540010fd765 |
| --- /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_HANDLER_H_ |
| +#define COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_HANDLER_H_ |
|
Marc Treib
2016/12/12 10:51:22
Doesn't match the file name.
sfiera
2016/12/12 16:08:32
Done.
|
| + |
| +#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: |
| + explicit NTPTilesInternalsMessageHandler(); |
|
Marc Treib
2016/12/12 10:51:22
nit: explicit not needed
sfiera
2016/12/12 16:08:32
Done.
|
| + ~NTPTilesInternalsMessageHandler() override; |
| + |
| + // Called when the WebUI page's JavaScript has loaded and it is ready to |
| + // receive RegisterMessageCallback() calls. |
| + void RegisterMessages(NTPTilesInternalsMessageHandlerClient* client); |
|
Marc Treib
2016/12/12 10:51:22
|client| must outlive us.
sfiera
2016/12/12 16:08:32
Done.
|
| + |
| + 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_HANDLER_H_ |