| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ | 5 #ifndef COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ |
| 6 #define COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ | 6 #define COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/optional.h" |
| 13 #include "components/ntp_tiles/most_visited_sites.h" | 14 #include "components/ntp_tiles/most_visited_sites.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class ListValue; | 17 class ListValue; |
| 17 } // namespace base | 18 } // namespace base |
| 18 | 19 |
| 19 namespace ntp_tiles { | 20 namespace ntp_tiles { |
| 20 | 21 |
| 21 class MostVisitedSites; | 22 class MostVisitedSites; |
| 22 class NTPTilesInternalsMessageHandlerClient; | 23 class NTPTilesInternalsMessageHandlerClient; |
| 23 | 24 |
| 24 // Implements the WebUI message handler for chrome://ntp-tiles-internals/ | 25 // Implements the WebUI message handler for chrome://ntp-tiles-internals/ |
| 25 // | 26 // |
| 26 // Because content and iOS use different implementations of WebUI, this class | 27 // Because content and iOS use different implementations of WebUI, this class |
| 27 // implements the generic portion and depends on the embedder to inject a bridge | 28 // implements the generic portion and depends on the embedder to inject a bridge |
| 28 // to the embedder's API. It cannot itself implement either API directly. | 29 // to the embedder's API. It cannot itself implement either API directly. |
| 29 class NTPTilesInternalsMessageHandler : public MostVisitedSites::Observer { | 30 class NTPTilesInternalsMessageHandler : public MostVisitedSites::Observer { |
| 30 public: | 31 public: |
| 31 NTPTilesInternalsMessageHandler(); | 32 NTPTilesInternalsMessageHandler(); |
| 32 ~NTPTilesInternalsMessageHandler() override; | 33 ~NTPTilesInternalsMessageHandler() override; |
| 33 | 34 |
| 34 // Called when the WebUI page's JavaScript has loaded and it is ready to | 35 // Called when the WebUI page's JavaScript has loaded and it is ready to |
| 35 // receive RegisterMessageCallback() calls. |client| must outlive this object. | 36 // receive RegisterMessageCallback() calls. |client| must outlive this object. |
| 36 void RegisterMessages(NTPTilesInternalsMessageHandlerClient* client); | 37 void RegisterMessages(NTPTilesInternalsMessageHandlerClient* client); |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 // Callbacks registered in RegisterMessages(). | 40 // Callbacks registered in RegisterMessages(). |
| 40 void HandleRegisterForEvents(const base::ListValue* args); | 41 void HandleRegisterForEvents(const base::ListValue* args); |
| 41 void HandleUpdate(const base::ListValue* args); | 42 void HandleUpdate(const base::ListValue* args); |
| 43 void HandleFetchSuggestions(const base::ListValue* args); |
| 44 void HandleViewPopularSitesJson(const base::ListValue* args); |
| 42 | 45 |
| 43 void SendSourceInfo(); | 46 void SendSourceInfo(); |
| 44 void SendTiles(const NTPTilesVector& tiles); | 47 void SendTiles(const NTPTilesVector& tiles); |
| 45 | 48 |
| 46 // MostVisitedSites::Observer. | 49 // MostVisitedSites::Observer. |
| 47 void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; | 50 void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; |
| 48 void OnIconMadeAvailable(const GURL& site_url) override; | 51 void OnIconMadeAvailable(const GURL& site_url) override; |
| 49 | 52 |
| 50 // Bridge to embedder's API. | 53 // Bridge to embedder's API. |
| 51 NTPTilesInternalsMessageHandlerClient* client_; | 54 NTPTilesInternalsMessageHandlerClient* client_; |
| 52 | 55 |
| 53 int site_count_; | 56 int site_count_; |
| 54 std::unique_ptr<MostVisitedSites> most_visited_sites_; | 57 std::unique_ptr<MostVisitedSites> most_visited_sites_; |
| 55 | 58 |
| 59 std::string suggestions_status_; |
| 60 std::string popular_sites_json_; |
| 61 |
| 62 base::WeakPtrFactory<NTPTilesInternalsMessageHandler> weak_ptr_factory_; |
| 63 |
| 56 DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler); | 64 DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler); |
| 57 }; | 65 }; |
| 58 | 66 |
| 59 } // namespace ntp_tiles | 67 } // namespace ntp_tiles |
| 60 | 68 |
| 61 #endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ | 69 #endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ |
| OLD | NEW |