Chromium Code Reviews| Index: components/doodle/doodle_fetcher.h |
| diff --git a/components/doodle/doodle_fetcher.h b/components/doodle/doodle_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d874cbac7432c6778335e6471530ca60a8648c71 |
| --- /dev/null |
| +++ b/components/doodle/doodle_fetcher.h |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2017 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_DOODLE_DOODLE_FETCHER_H_ |
| +#define COMPONENTS_DOODLE_DOODLE_FETCHER_H_ |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "url/gurl.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +class Value; |
| +} |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace doodle { |
| + |
| +enum class DoodleState { |
| + UNKNOWN, |
|
Marc Treib
2017/01/31 09:46:34
Is this required? Would it ever be returned?
fhorschig
2017/01/31 13:59:18
Removed. It used to be a default value.
|
| + AVAILABLE, |
| + NO_DOODLE, |
| + DOWNLOAD_ERROR, |
| + PARSING_ERROR |
| +}; |
| + |
| +struct DoodleImage { |
| + GURL url; |
| + int height; |
| + int width; |
|
Marc Treib
2017/01/31 09:46:34
Make a ctor that initializes everything. Recent ex
fhorschig
2017/01/31 13:59:18
Done.
|
| + std::string background_color; |
| +}; |
| + |
| +struct DoodleConfig { |
| + DoodleConfig(); |
| + ~DoodleConfig(); |
| + explicit DoodleConfig(DoodleState doodle_state); |
| + DoodleConfig(const DoodleConfig& config); |
| + |
| + DoodleState state; |
| + |
| + GURL search_url; |
| + GURL fullpage_interactive_url; |
| + std::string doodle_type; |
|
Marc Treib
2017/01/31 09:46:34
What's this? Should it be an enum?
jshneier
2017/01/31 13:08:26
It's populated from this enum:
enum DoodleType {
fhorschig
2017/01/31 13:59:18
Why not.
|
| + base::Time time_to_live_ms; // The passed "int" doesn't fit int32. |
|
Marc Treib
2017/01/31 09:46:34
nit: Remove comment, it doesn't belong here.
Also,
fhorschig
2017/01/31 13:59:18
Done.
|
| + DoodleImage large_image; |
| +}; |
| + |
| +class DoodleFetcher : public net::URLFetcherDelegate { |
| + public: |
| + using FinishedCallback = |
| + base::Callback<void(const DoodleConfig& doodle_config)>; |
| + |
| + DoodleFetcher(net::URLRequestContextGetter* download_context, GURL base_url); |
| + |
| + ~DoodleFetcher() override; |
| + |
| + void FetchDoodle(const FinishedCallback& callback); |
| + |
| + private: |
| + // net::URLFetcherDelegate implementation. |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + |
| + void OnJsonParsed(std::unique_ptr<base::Value> json); |
| + void OnJsonParseFailed(const std::string& error_message); |
| + void ParseDoodle(std::unique_ptr<base::DictionaryValue> config); |
| + |
| + // Parameter set from constructor. |
| + net::URLRequestContextGetter* const download_context_; |
| + GURL base_url_; |
| + |
| + FinishedCallback callback_; |
| + std::unique_ptr<net::URLFetcher> fetcher_; |
| + |
| + base::WeakPtrFactory<DoodleFetcher> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DoodleFetcher); |
| +}; |
| + |
| +extern const char kDoodleConfigUrl[]; |
| + |
| +} // namespace doodle |
| + |
| +#endif // COMPONENTS_DOODLE_DOODLE_FETCHER_H_ |