Chromium Code Reviews| Index: components/ntp_tiles/webui/popular_sites_handler.h |
| diff --git a/components/ntp_tiles/webui/popular_sites_handler.h b/components/ntp_tiles/webui/popular_sites_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..73ef3222f2b7821acbdd6985b5b41249d25d9bb2 |
| --- /dev/null |
| +++ b/components/ntp_tiles/webui/popular_sites_handler.h |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ |
| +#define COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ |
| + |
| +#include <memory> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
|
sdefresne
2016/10/28 13:34:02
#include "base/callback_forward.h" should be enoug
sfiera
2016/10/28 14:12:43
Done.
|
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| + |
| +class PrefService; |
| + |
| +namespace base { |
| +class Value; |
| +class ListValue; |
| +class SequencedWorkerPool; |
| +} // namespace base |
| + |
| +namespace ntp_tiles { |
| + |
| +class PopularSites; |
| + |
| +class PopularSitesInternalsMessageHandlerInterface { |
|
Bernhard Bauer
2016/10/28 13:23:07
This is a bit weird:
1) Two classes defined in the
sdefresne
2016/10/28 13:34:02
Is this an interface implemented by embedder (desk
sfiera
2016/10/28 13:38:14
Basically, the problem is that the WebUI handlers
sfiera
2016/10/28 14:12:43
Renamed to Client.
|
| + public: |
|
sdefresne
2016/10/28 13:34:02
The class needs a virtual destructor.
sfiera
2016/10/28 14:12:43
Done.
|
| + virtual base::SequencedWorkerPool* GetBlockingPool() = 0; |
|
sdefresne
2016/10/28 13:34:02
Can you document this class and its methods?
sfiera
2016/10/28 14:12:42
Done.
|
| + virtual std::unique_ptr<ntp_tiles::PopularSites> MakePopularSites() = 0; |
| + virtual PrefService* GetPrefs() = 0; |
| + virtual void RegisterMessageCallback( |
| + const std::string& message, |
| + const base::Callback<void(const base::ListValue*)>& callback) = 0; |
| + virtual void CallJavascriptFunctionVector( |
| + const std::string& name, |
| + const std::vector<const base::Value*>& values) = 0; |
| + |
| + template <typename... Arg> |
| + void CallJavascriptFunction(const std::string& name, const Arg&... arg) { |
| + CallJavascriptFunctionVector(name, {&arg...}); |
| + } |
|
sdefresne
2016/10/28 13:34:03
I would recommend making the class non-copyable si
sfiera
2016/10/28 14:12:42
Done.
Bernhard Bauer
2016/10/28 16:56:38
OOC, why are virtual methods the criterium here? W
|
| +}; |
| + |
| +class PopularSitesInternalsMessageHandlerImpl { |
|
sdefresne
2016/10/28 13:34:02
Can you document this class and its methods?
sfiera
2016/10/28 14:12:42
Done. (the public ones—most of them actually no lo
|
| + public: |
| + PopularSitesInternalsMessageHandlerImpl( |
| + PopularSitesInternalsMessageHandlerInterface* web_ui); |
| + ~PopularSitesInternalsMessageHandlerImpl(); |
| + |
| + void RegisterMessages(); |
| + |
| + void HandleRegisterForEvents(const base::ListValue* args); |
| + void HandleUpdate(const base::ListValue* args); |
| + void HandleViewJson(const base::ListValue* args); |
| + |
| + void SendOverrides(); |
| + void SendDownloadResult(bool success); |
| + void SendSites(); |
| + void SendJson(const std::string& json); |
| + |
| + void OnPopularSitesAvailable(bool explicit_request, bool success); |
| + |
| + private: |
| + std::unique_ptr<PopularSites> popular_sites_; |
| + PopularSitesInternalsMessageHandlerInterface* web_ui_; |
| + base::WeakPtrFactory<PopularSitesInternalsMessageHandlerImpl> |
| + weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PopularSitesInternalsMessageHandlerImpl); |
| +}; |
| + |
| +} // namespace ntp_tiles |
| + |
| +#endif // COMPONENTS_NTP_TILES_WEBUI_POPULAR_SITES_HANDLER_H_ |