Chromium Code Reviews| 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 <map> | |
| 8 #include <memory> | 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/optional.h" | 14 #include "base/optional.h" |
| 15 #include "base/task/cancelable_task_tracker.h" | |
| 16 #include "components/favicon_base/favicon_types.h" | |
| 14 #include "components/ntp_tiles/most_visited_sites.h" | 17 #include "components/ntp_tiles/most_visited_sites.h" |
| 15 | 18 |
| 16 namespace base { | 19 namespace base { |
| 17 class ListValue; | 20 class ListValue; |
| 18 } // namespace base | 21 } // namespace base |
| 19 | 22 |
| 23 namespace favicon { | |
| 24 class FaviconService; | |
| 25 } // namespace favicon | |
| 26 | |
| 20 namespace ntp_tiles { | 27 namespace ntp_tiles { |
| 21 | 28 |
| 22 class MostVisitedSites; | 29 class MostVisitedSites; |
| 23 class NTPTilesInternalsMessageHandlerClient; | 30 class NTPTilesInternalsMessageHandlerClient; |
| 24 | 31 |
| 25 // Implements the WebUI message handler for chrome://ntp-tiles-internals/ | 32 // Implements the WebUI message handler for chrome://ntp-tiles-internals/ |
| 26 // | 33 // |
| 27 // Because content and iOS use different implementations of WebUI, this class | 34 // Because content and iOS use different implementations of WebUI, this class |
| 28 // implements the generic portion and depends on the embedder to inject a bridge | 35 // implements the generic portion and depends on the embedder to inject a bridge |
| 29 // to the embedder's API. It cannot itself implement either API directly. | 36 // to the embedder's API. It cannot itself implement either API directly. |
| 30 class NTPTilesInternalsMessageHandler : public MostVisitedSites::Observer { | 37 class NTPTilesInternalsMessageHandler : public MostVisitedSites::Observer { |
| 31 public: | 38 public: |
| 32 NTPTilesInternalsMessageHandler(); | 39 // |favicon_service| must not be null and must outlive this object. |
| 40 explicit NTPTilesInternalsMessageHandler( | |
| 41 favicon::FaviconService* favicon_service); | |
| 33 ~NTPTilesInternalsMessageHandler() override; | 42 ~NTPTilesInternalsMessageHandler() override; |
| 34 | 43 |
| 35 // Called when the WebUI page's JavaScript has loaded and it is ready to | 44 // Called when the WebUI page's JavaScript has loaded and it is ready to |
| 36 // receive RegisterMessageCallback() calls. |client| must outlive this object. | 45 // receive RegisterMessageCallback() calls. |client| must outlive this object. |
| 37 void RegisterMessages(NTPTilesInternalsMessageHandlerClient* client); | 46 void RegisterMessages(NTPTilesInternalsMessageHandlerClient* client); |
| 38 | 47 |
| 39 private: | 48 private: |
| 49 using FaviconResultMap = std::map<std::pair<GURL, favicon_base::IconType>, | |
| 50 favicon_base::FaviconRawBitmapResult>; | |
| 51 | |
| 40 // Callbacks registered in RegisterMessages(). | 52 // Callbacks registered in RegisterMessages(). |
| 41 void HandleRegisterForEvents(const base::ListValue* args); | 53 void HandleRegisterForEvents(const base::ListValue* args); |
| 42 void HandleUpdate(const base::ListValue* args); | 54 void HandleUpdate(const base::ListValue* args); |
| 43 void HandleFetchSuggestions(const base::ListValue* args); | 55 void HandleFetchSuggestions(const base::ListValue* args); |
| 44 void HandleViewPopularSitesJson(const base::ListValue* args); | 56 void HandleViewPopularSitesJson(const base::ListValue* args); |
| 45 | 57 |
| 46 void SendSourceInfo(); | 58 void SendSourceInfo(); |
| 47 void SendTiles(const NTPTilesVector& tiles); | 59 void SendTiles(const NTPTilesVector& tiles, |
| 60 const FaviconResultMap& result_map); | |
| 48 | 61 |
| 49 // MostVisitedSites::Observer. | 62 // MostVisitedSites::Observer. |
| 50 void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; | 63 void OnMostVisitedURLsAvailable(const NTPTilesVector& tiles) override; |
| 51 void OnIconMadeAvailable(const GURL& site_url) override; | 64 void OnIconMadeAvailable(const GURL& site_url) override; |
| 52 | 65 |
| 66 void OnFaviconLookupDone(const NTPTilesVector& tiles, | |
| 67 size_t num_lookups, | |
| 68 FaviconResultMap* result_map, | |
| 69 const GURL& page_url, | |
| 70 const favicon_base::FaviconRawBitmapResult& result); | |
| 71 | |
| 72 favicon::FaviconService* favicon_service_; | |
|
sfiera
2017/06/13 08:56:01
Nit: * const
| |
| 73 const std::map<favicon_base::IconType, std::string> icon_types_and_names_; | |
| 74 | |
| 53 // Bridge to embedder's API. | 75 // Bridge to embedder's API. |
| 54 NTPTilesInternalsMessageHandlerClient* client_; | 76 NTPTilesInternalsMessageHandlerClient* client_; |
| 55 | 77 |
| 56 int site_count_; | 78 int site_count_; |
| 57 std::unique_ptr<MostVisitedSites> most_visited_sites_; | 79 std::unique_ptr<MostVisitedSites> most_visited_sites_; |
| 58 | 80 |
| 59 std::string suggestions_status_; | 81 std::string suggestions_status_; |
| 60 std::string popular_sites_json_; | 82 std::string popular_sites_json_; |
| 61 | 83 |
| 84 base::CancelableTaskTracker cancelable_task_tracker_; | |
| 62 base::WeakPtrFactory<NTPTilesInternalsMessageHandler> weak_ptr_factory_; | 85 base::WeakPtrFactory<NTPTilesInternalsMessageHandler> weak_ptr_factory_; |
| 63 | 86 |
| 64 DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler); | 87 DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler); |
| 65 }; | 88 }; |
| 66 | 89 |
| 67 } // namespace ntp_tiles | 90 } // namespace ntp_tiles |
| 68 | 91 |
| 69 #endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ | 92 #endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ |
| OLD | NEW |