Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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_DOODLE_DOODLE_FETCHER_H_ | |
| 6 #define COMPONENTS_DOODLE_DOODLE_FETCHER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "net/url_request/url_fetcher_delegate.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 class Value; | |
| 20 } | |
| 21 | |
| 22 namespace net { | |
| 23 class URLRequestContextGetter; | |
| 24 } | |
| 25 | |
| 26 namespace doodle { | |
| 27 | |
| 28 enum class DoodleState { | |
| 29 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.
| |
| 30 AVAILABLE, | |
| 31 NO_DOODLE, | |
| 32 DOWNLOAD_ERROR, | |
| 33 PARSING_ERROR | |
| 34 }; | |
| 35 | |
| 36 struct DoodleImage { | |
| 37 GURL url; | |
| 38 int height; | |
| 39 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.
| |
| 40 std::string background_color; | |
| 41 }; | |
| 42 | |
| 43 struct DoodleConfig { | |
| 44 DoodleConfig(); | |
| 45 ~DoodleConfig(); | |
| 46 explicit DoodleConfig(DoodleState doodle_state); | |
| 47 DoodleConfig(const DoodleConfig& config); | |
| 48 | |
| 49 DoodleState state; | |
| 50 | |
| 51 GURL search_url; | |
| 52 GURL fullpage_interactive_url; | |
| 53 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.
| |
| 54 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.
| |
| 55 DoodleImage large_image; | |
| 56 }; | |
| 57 | |
| 58 class DoodleFetcher : public net::URLFetcherDelegate { | |
| 59 public: | |
| 60 using FinishedCallback = | |
| 61 base::Callback<void(const DoodleConfig& doodle_config)>; | |
| 62 | |
| 63 DoodleFetcher(net::URLRequestContextGetter* download_context, GURL base_url); | |
| 64 | |
| 65 ~DoodleFetcher() override; | |
| 66 | |
| 67 void FetchDoodle(const FinishedCallback& callback); | |
| 68 | |
| 69 private: | |
| 70 // net::URLFetcherDelegate implementation. | |
| 71 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 72 | |
| 73 void OnJsonParsed(std::unique_ptr<base::Value> json); | |
| 74 void OnJsonParseFailed(const std::string& error_message); | |
| 75 void ParseDoodle(std::unique_ptr<base::DictionaryValue> config); | |
| 76 | |
| 77 // Parameter set from constructor. | |
| 78 net::URLRequestContextGetter* const download_context_; | |
| 79 GURL base_url_; | |
| 80 | |
| 81 FinishedCallback callback_; | |
| 82 std::unique_ptr<net::URLFetcher> fetcher_; | |
| 83 | |
| 84 base::WeakPtrFactory<DoodleFetcher> weak_ptr_factory_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(DoodleFetcher); | |
| 87 }; | |
| 88 | |
| 89 extern const char kDoodleConfigUrl[]; | |
| 90 | |
| 91 } // namespace doodle | |
| 92 | |
| 93 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_H_ | |
| OLD | NEW |