Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: components/ntp_tiles/webui/ntp_tiles_internals_message_handler.h

Issue 2936793002: ntp_tiles: Extend chrome://ntp-tiles-internals with favicon data (Closed)
Patch Set: Avoid using std::pair with constexpr. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 FaviconResultMap* result_map,
68 size_t* num_pending_lookups,
69 const GURL& page_url,
70 const favicon_base::FaviconRawBitmapResult& result);
71
72 favicon::FaviconService* favicon_service_;
73
53 // Bridge to embedder's API. 74 // Bridge to embedder's API.
54 NTPTilesInternalsMessageHandlerClient* client_; 75 NTPTilesInternalsMessageHandlerClient* client_;
55 76
56 int site_count_; 77 int site_count_;
57 std::unique_ptr<MostVisitedSites> most_visited_sites_; 78 std::unique_ptr<MostVisitedSites> most_visited_sites_;
58 79
59 std::string suggestions_status_; 80 std::string suggestions_status_;
60 std::string popular_sites_json_; 81 std::string popular_sites_json_;
61 82
83 base::CancelableTaskTracker cancelable_task_tracker_;
62 base::WeakPtrFactory<NTPTilesInternalsMessageHandler> weak_ptr_factory_; 84 base::WeakPtrFactory<NTPTilesInternalsMessageHandler> weak_ptr_factory_;
63 85
64 DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler); 86 DISALLOW_COPY_AND_ASSIGN(NTPTilesInternalsMessageHandler);
65 }; 87 };
66 88
67 } // namespace ntp_tiles 89 } // namespace ntp_tiles
68 90
69 #endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_ 91 #endif // COMPONENTS_NTP_TILES_WEBUI_NTP_TILES_INTERNALS_MESSAGE_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp_tiles_internals_ui.cc ('k') | components/ntp_tiles/webui/ntp_tiles_internals_message_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698