Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: components/doodle/doodle_fetcher.h

Issue 2660883002: Introduce a Doodle Fetcher for NTP (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/doodle/OWNERS ('k') | components/doodle/doodle_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
16 namespace base {
17 class DictionaryValue;
18 class Value;
19 }
20
21 namespace net {
22 class URLRequestContextGetter;
23 }
24
25 using ParseJSONCallback = base::Callback<void(
26 const std::string& unsafe_json,
27 const base::Callback<void(std::unique_ptr<base::Value>)>& success_callback,
28 const base::Callback<void(const std::string&)>& error_callback)>;
29
30 struct DoodleImage {
31 std::string url;
32 int height;
33 int width;
34 std::string background_color;
35 };
36
37 struct DoodleConfig {
38 DoodleConfig();
39 DoodleConfig(DoodleImage large_image);
40 DoodleConfig(const DoodleConfig& config);
41 bool error_during_fetch;
42 std::string search_url;
43 std::string fullpage_interactive_url;
44 DoodleImage large_image;
45 };
46
47 class DoodleFetcher : public net::URLFetcherDelegate {
48 public:
49 using FinishedCallback = base::Callback<void(DoodleConfig doodle_config)>;
50
51 DoodleFetcher(net::URLRequestContextGetter* download_context,
52 ParseJSONCallback parse_json);
53
54 ~DoodleFetcher() override;
55
56 void FetchDoodle(const FinishedCallback& callback);
57
58 private:
59 // net::URLFetcherDelegate implementation.
60 void OnURLFetchComplete(const net::URLFetcher* source) override;
61
62 void OnJsonParsed(std::unique_ptr<base::Value> json);
63 void OnJsonParseFailed(const std::string& error_message);
64 void ParseDoodle(std::unique_ptr<base::DictionaryValue> config);
65 void OnDownloadFailed();
66
67 // Parameters set from constructor.
68 net::URLRequestContextGetter* const download_context_;
69 ParseJSONCallback parse_json_;
70
71 FinishedCallback callback_;
72
73 std::unique_ptr<net::URLFetcher> fetcher_;
74
75 base::WeakPtrFactory<DoodleFetcher> weak_ptr_factory_;
76
77 DISALLOW_COPY_AND_ASSIGN(DoodleFetcher);
78 };
79
80 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_H_
OLDNEW
« no previous file with comments | « components/doodle/OWNERS ('k') | components/doodle/doodle_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698