Chromium Code Reviews| 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 #include <vector> | |
| 11 | |
| 12 #include "base/callback_forward.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 | |
| 16 class PrefService; | |
| 17 | |
| 18 namespace base { | |
| 19 class Value; | |
| 20 class ListValue; | |
| 21 class SequencedWorkerPool; | |
| 22 } // namespace base | |
| 23 | |
| 24 namespace ntp_tiles { | |
| 25 | |
| 26 class PopularSites; | |
| 27 | |
| 28 class PopularSitesInternalsMessageHandlerClient { | |
|
Bernhard Bauer
2016/10/28 16:56:38
Move this to a separate file?
| |
| 29 public: | |
| 30 // Returns the blocking pool for hte embedder. | |
| 31 virtual base::SequencedWorkerPool* GetBlockingPool() = 0; | |
| 32 | |
| 33 // Returns the PrefService for the embedder and containing WebUI page. | |
| 34 virtual PrefService* GetPrefs() = 0; | |
| 35 | |
| 36 // Creates a new PopularSites based on the context pf the WebUI page. | |
| 37 virtual std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() = 0; | |
| 38 | |
| 39 // Registers a callback in Javascript. See content::WebUI and web::WebUIIOS. | |
| 40 virtual void RegisterMessageCallback( | |
| 41 const std::string& message, | |
| 42 const base::Callback<void(const base::ListValue*)>& callback) = 0; | |
| 43 | |
| 44 // Invokes a function in Javascript. See content::WebUI and web::WebUIIOS. | |
| 45 virtual void CallJavascriptFunctionVector( | |
| 46 const std::string& name, | |
| 47 const std::vector<const base::Value*>& values) = 0; | |
| 48 | |
| 49 // Helper function for CallJavascriptFunctionVector(). | |
| 50 template <typename... Arg> | |
| 51 void CallJavascriptFunction(const std::string& name, const Arg&... arg) { | |
| 52 CallJavascriptFunctionVector(name, {&arg...}); | |
| 53 } | |
| 54 | |
| 55 protected: | |
| 56 PopularSitesInternalsMessageHandlerClient(); | |
| 57 virtual ~PopularSitesInternalsMessageHandlerClient(); | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandlerClient); | |
| 61 }; | |
| 62 | |
| 63 class PopularSitesInternalsMessageHandlerImpl { | |
| 64 public: | |
| 65 PopularSitesInternalsMessageHandlerImpl( | |
| 66 PopularSitesInternalsMessageHandlerClient* web_ui); | |
| 67 ~PopularSitesInternalsMessageHandlerImpl(); | |
| 68 | |
| 69 // Called when the WebUI page's JavaScript has loaded and it is ready to | |
| 70 // receive RegisterMessageCallback() calls. | |
| 71 void RegisterMessages(); | |
| 72 | |
| 73 private: | |
| 74 // Callbacks registered in RegisterMessages(). | |
| 75 void HandleRegisterForEvents(const base::ListValue* args); | |
| 76 void HandleUpdate(const base::ListValue* args); | |
| 77 void HandleViewJson(const base::ListValue* args); | |
| 78 | |
| 79 void SendOverrides(); | |
| 80 void SendDownloadResult(bool success); | |
| 81 void SendSites(); | |
| 82 void SendJson(const std::string& json); | |
| 83 | |
| 84 // Completion handler for popular_sites_->StartFetch(). | |
| 85 void OnPopularSitesAvailable(bool explicit_request, bool success); | |
| 86 | |
| 87 PopularSitesInternalsMessageHandlerClient* web_ui_; | |
| 88 | |
| 89 std::unique_ptr<PopularSites> popular_sites_; | |
| 90 | |
| 91 base::WeakPtrFactory<PopularSitesInternalsMessageHandlerImpl> | |
| 92 weak_ptr_factory_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandlerImpl); | |
| 95 }; | |
| 96 | |
| 97 } // namespace ntp_tiles | |
| 98 | |
| 99 #endif // COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ | |
| OLD | NEW |