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

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

Issue 2725143003: [Doodle] Pull time_to_live out of DoodleConfig (Closed)
Patch Set: 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
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> ParseDoodle(const base::DictionaryValue& ddljson,
66 const base::DictionaryValue& ddljson) const; 67 base::TimeDelta* time_to_live) const;
mastiz 2017/03/02 19:55:42 Optional: wouldn't it be cleaner to return a Optio
Marc Treib 2017/03/03 09:35:26 Renamed. I don't like std::pair much - IMO it oft
67 bool ParseImage(const base::DictionaryValue& image_dict, 68 bool ParseImage(const base::DictionaryValue& image_dict,
68 const std::string& image_name, 69 const std::string& image_name,
69 DoodleImage* image) const; 70 DoodleImage* image) const;
70 void ParseBaseInformation(const base::DictionaryValue& ddljson, 71 void ParseBaseInformation(const base::DictionaryValue& ddljson,
71 DoodleConfig* config) const; 72 DoodleConfig* config,
73 base::TimeDelta* time_to_live) const;
72 GURL ParseRelativeUrl(const base::DictionaryValue& dict_value, 74 GURL ParseRelativeUrl(const base::DictionaryValue& dict_value,
73 const std::string& key) const; 75 const std::string& key) const;
74 76
75 void RespondToAllCallbacks(DoodleState state, 77 void RespondToAllCallbacks(DoodleState state,
78 base::TimeDelta time_to_live,
76 const base::Optional<DoodleConfig>& config); 79 const base::Optional<DoodleConfig>& config);
mastiz 2017/03/02 19:55:42 Ditto: perhaps a typedef or struct could also help
Marc Treib 2017/03/03 09:35:26 Same: Unless you feel strongly, I don't think it's
mastiz 2017/03/03 11:17:44 I was certainly not feeling strongly, so it's fine
77 GURL GetGoogleBaseUrl() const; 80 GURL GetGoogleBaseUrl() const;
78 81
79 // Returns whether a fetch is still in progress. A fetch begins when a 82 // 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. 83 // callback is added and ends when the last callback was called.
81 bool IsFetchInProgress() const { return !callbacks_.empty(); } 84 bool IsFetchInProgress() const { return !callbacks_.empty(); }
82 85
83 // Parameters set from constructor. 86 // Parameters set from constructor.
84 scoped_refptr<net::URLRequestContextGetter> const download_context_; 87 scoped_refptr<net::URLRequestContextGetter> const download_context_;
85 ParseJSONCallback json_parsing_callback_; 88 ParseJSONCallback json_parsing_callback_;
86 GoogleURLTracker* google_url_tracker_; 89 GoogleURLTracker* google_url_tracker_;
87 90
88 std::vector<FinishedCallback> callbacks_; 91 std::vector<FinishedCallback> callbacks_;
89 std::unique_ptr<net::URLFetcher> fetcher_; 92 std::unique_ptr<net::URLFetcher> fetcher_;
90 93
91 base::WeakPtrFactory<DoodleFetcherImpl> weak_ptr_factory_; 94 base::WeakPtrFactory<DoodleFetcherImpl> weak_ptr_factory_;
92 95
93 DISALLOW_COPY_AND_ASSIGN(DoodleFetcherImpl); 96 DISALLOW_COPY_AND_ASSIGN(DoodleFetcherImpl);
94 }; 97 };
95 98
96 } // namespace doodle 99 } // namespace doodle
97 100
98 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_ 101 #endif // COMPONENTS_DOODLE_DOODLE_FETCHER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698