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

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

Issue 2725143003: [Doodle] Pull time_to_live out of DoodleConfig (Closed)
Patch Set: mastiz review Created 3 years, 9 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/doodle_fetcher.h ('k') | components/doodle/doodle_fetcher_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_ 5 #ifndef COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_
6 #define COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_ 6 #define COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/optional.h" 17 #include "base/optional.h"
18 #include "components/doodle/doodle_fetcher.h" 18 #include "components/doodle/doodle_fetcher.h"
19 #include "components/doodle/doodle_types.h" 19 #include "components/doodle/doodle_types.h"
20 #include "net/url_request/url_fetcher_delegate.h" 20 #include "net/url_request/url_fetcher_delegate.h"
21 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 class GoogleURLTracker; 24 class GoogleURLTracker;
25 25
26 namespace base { 26 namespace base {
27 class DictionaryValue; 27 class DictionaryValue;
28 class TimeDelta;
28 class Value; 29 class Value;
29 } 30 }
30 31
31 namespace doodle { 32 namespace doodle {
32 33
33 // This class provides information about any recent doodle. 34 // This class provides information about any recent doodle.
34 // It works asynchronously and calls a callback when finished fetching the 35 // It works asynchronously and calls a callback when finished fetching the
35 // information from the remote enpoint. 36 // information from the remote enpoint.
36 class DoodleFetcherImpl : public DoodleFetcher, public net::URLFetcherDelegate { 37 class DoodleFetcherImpl : public DoodleFetcher, public net::URLFetcherDelegate {
37 public: 38 public:
(...skipping 17 matching lines...) Expand all
55 56
56 private: 57 private:
57 // net::URLFetcherDelegate implementation. 58 // net::URLFetcherDelegate implementation.
58 void OnURLFetchComplete(const net::URLFetcher* source) override; 59 void OnURLFetchComplete(const net::URLFetcher* source) override;
59 60
60 // ParseJSONCallback Success callback 61 // ParseJSONCallback Success callback
61 void OnJsonParsed(std::unique_ptr<base::Value> json); 62 void OnJsonParsed(std::unique_ptr<base::Value> json);
62 // ParseJSONCallback Failure callback 63 // ParseJSONCallback Failure callback
63 void OnJsonParseFailed(const std::string& error_message); 64 void OnJsonParseFailed(const std::string& error_message);
64 65
65 base::Optional<DoodleConfig> ParseDoodle( 66 base::Optional<DoodleConfig> ParseDoodleConfigAndTimeToLive(
66 const base::DictionaryValue& ddljson) const; 67 const base::DictionaryValue& ddljson,
68 base::TimeDelta* time_to_live) const;
69
67 bool ParseImage(const base::DictionaryValue& image_dict, 70 bool ParseImage(const base::DictionaryValue& image_dict,
68 const std::string& image_name, 71 const std::string& image_name,
69 DoodleImage* image) const; 72 DoodleImage* image) const;
70 void ParseBaseInformation(const base::DictionaryValue& ddljson, 73 void ParseBaseInformation(const base::DictionaryValue& ddljson,
71 DoodleConfig* config) const; 74 DoodleConfig* config,
75 base::TimeDelta* time_to_live) const;
72 GURL ParseRelativeUrl(const base::DictionaryValue& dict_value, 76 GURL ParseRelativeUrl(const base::DictionaryValue& dict_value,
73 const std::string& key) const; 77 const std::string& key) const;
74 78
75 void RespondToAllCallbacks(DoodleState state, 79 void RespondToAllCallbacks(DoodleState state,
80 base::TimeDelta time_to_live,
76 const base::Optional<DoodleConfig>& config); 81 const base::Optional<DoodleConfig>& config);
82
77 GURL GetGoogleBaseUrl() const; 83 GURL GetGoogleBaseUrl() const;
78 84
79 // Returns whether a fetch is still in progress. A fetch begins when a 85 // Returns whether a fetch is still in progress. A fetch begins when a
80 // callback is added and ends when the last callback was called. 86 // callback is added and ends when the last callback was called.
81 bool IsFetchInProgress() const { return !callbacks_.empty(); } 87 bool IsFetchInProgress() const { return !callbacks_.empty(); }
82 88
83 // Parameters set from constructor. 89 // Parameters set from constructor.
84 scoped_refptr<net::URLRequestContextGetter> const download_context_; 90 scoped_refptr<net::URLRequestContextGetter> const download_context_;
85 ParseJSONCallback json_parsing_callback_; 91 ParseJSONCallback json_parsing_callback_;
86 GoogleURLTracker* google_url_tracker_; 92 GoogleURLTracker* google_url_tracker_;
87 93
88 std::vector<FinishedCallback> callbacks_; 94 std::vector<FinishedCallback> callbacks_;
89 std::unique_ptr<net::URLFetcher> fetcher_; 95 std::unique_ptr<net::URLFetcher> fetcher_;
90 96
91 base::WeakPtrFactory<DoodleFetcherImpl> weak_ptr_factory_; 97 base::WeakPtrFactory<DoodleFetcherImpl> weak_ptr_factory_;
92 98
93 DISALLOW_COPY_AND_ASSIGN(DoodleFetcherImpl); 99 DISALLOW_COPY_AND_ASSIGN(DoodleFetcherImpl);
94 }; 100 };
95 101
96 } // namespace doodle 102 } // namespace doodle
97 103
98 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_ 104 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_
OLDNEW
« no previous file with comments | « components/doodle/doodle_fetcher.h ('k') | components/doodle/doodle_fetcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698