| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ |
| 6 #define COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 |
| 14 namespace base { |
| 15 class ListValue; |
| 16 } // namespace base |
| 17 |
| 18 namespace ntp_tiles { |
| 19 |
| 20 class PopularSites; |
| 21 class PopularSitesInternalsMessageHandlerClient; |
| 22 |
| 23 // Implements the WebUI message handler for chrome://popular-sites-internals/ |
| 24 // |
| 25 // Because content and iOS use different implementations of WebUI, this class |
| 26 // implements the generic portion and depends on the embedder to inject a bridge |
| 27 // to the embedder's API. It cannot itself implement either API directly. |
| 28 class PopularSitesInternalsMessageHandler { |
| 29 public: |
| 30 explicit PopularSitesInternalsMessageHandler( |
| 31 PopularSitesInternalsMessageHandlerClient* web_ui); |
| 32 ~PopularSitesInternalsMessageHandler(); |
| 33 |
| 34 // Called when the WebUI page's JavaScript has loaded and it is ready to |
| 35 // receive RegisterMessageCallback() calls. |
| 36 void RegisterMessages(); |
| 37 |
| 38 private: |
| 39 // Callbacks registered in RegisterMessages(). |
| 40 void HandleRegisterForEvents(const base::ListValue* args); |
| 41 void HandleUpdate(const base::ListValue* args); |
| 42 void HandleViewJson(const base::ListValue* args); |
| 43 |
| 44 void SendOverrides(); |
| 45 void SendDownloadResult(bool success); |
| 46 void SendSites(); |
| 47 void SendJson(const std::string& json); |
| 48 |
| 49 // Completion handler for popular_sites_->StartFetch(). |
| 50 void OnPopularSitesAvailable(bool explicit_request, bool success); |
| 51 |
| 52 // Bridge to embedder's API. |
| 53 PopularSitesInternalsMessageHandlerClient* web_ui_; |
| 54 |
| 55 std::unique_ptr<PopularSites> popular_sites_; |
| 56 |
| 57 base::WeakPtrFactory<PopularSitesInternalsMessageHandler> weak_ptr_factory_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandler); |
| 60 }; |
| 61 |
| 62 } // namespace ntp_tiles |
| 63 |
| 64 #endif // COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ |
| OLD | NEW |