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

Side by Side Diff: components/search_provider_logos/logo_tracker.h

Issue 1066923002: [LogoTracker] Correct fingerprint append in async parameter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests and comment nits Created 5 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ 5 #ifndef COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_
6 #define COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ 6 #define COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 }; 65 };
66 66
67 // Parses the response from the server and returns it as an EncodedLogo. Returns 67 // Parses the response from the server and returns it as an EncodedLogo. Returns
68 // NULL if the response is invalid. 68 // NULL if the response is invalid.
69 typedef base::Callback< 69 typedef base::Callback<
70 scoped_ptr<EncodedLogo>(const scoped_ptr<std::string>& response, 70 scoped_ptr<EncodedLogo>(const scoped_ptr<std::string>& response,
71 base::Time response_time)> ParseLogoResponse; 71 base::Time response_time)> ParseLogoResponse;
72 72
73 // Encodes the fingerprint of the cached logo in the logo URL. This enables the 73 // Encodes the fingerprint of the cached logo in the logo URL. This enables the
74 // server to verify whether the cached logo is up-to-date. 74 // server to verify whether the cached logo is up-to-date.
75 typedef base::Callback< 75 typedef base::Callback<GURL(const GURL& logo_url,
76 GURL(const GURL& logo_url, const std::string& fingerprint)> 76 const std::string& fingerprint,
77 AppendFingerprintToLogoURL; 77 bool wants_cta)> AppendQueryparamsToLogoURL;
78 78
79 // This class provides the logo for a search provider. Logos are downloaded from 79 // This class provides the logo for a search provider. Logos are downloaded from
80 // the search provider's logo URL and cached on disk. 80 // the search provider's logo URL and cached on disk.
81 // 81 //
82 // Call SetServerAPI() at least once to specify how to get the logo from the 82 // Call SetServerAPI() at least once to specify how to get the logo from the
83 // server. Then call GetLogo() to trigger retrieval of the logo and receive 83 // server. Then call GetLogo() to trigger retrieval of the logo and receive
84 // updates once the cached and/or fresh logos are available. 84 // updates once the cached and/or fresh logos are available.
85 class LogoTracker : public net::URLFetcherDelegate { 85 class LogoTracker : public net::URLFetcherDelegate {
86 public: 86 public:
87 // Constructs a LogoTracker with the given LogoDelegate. Takes ownership of 87 // Constructs a LogoTracker with the given LogoDelegate. Takes ownership of
(...skipping 20 matching lines...) Expand all
108 ~LogoTracker() override; 108 ~LogoTracker() override;
109 109
110 // Defines the server API for downloading and parsing the logo. This must be 110 // Defines the server API for downloading and parsing the logo. This must be
111 // called at least once before calling GetLogo(). 111 // called at least once before calling GetLogo().
112 // 112 //
113 // |logo_url| is the URL from which the logo will be downloaded. If |logo_url| 113 // |logo_url| is the URL from which the logo will be downloaded. If |logo_url|
114 // is different than the current logo URL, any pending LogoObservers will be 114 // is different than the current logo URL, any pending LogoObservers will be
115 // canceled. 115 // canceled.
116 // 116 //
117 // |parse_logo_response_func| is a callback that will be used to parse the 117 // |parse_logo_response_func| is a callback that will be used to parse the
118 // server's response into a EncodedLogo object. |append_fingerprint_func| is a 118 // server's response into a EncodedLogo object. |append_queryparams_func| is a
119 // callback that will return the URL from which to download the logo if a 119 // callback that will return the URL from which to download the logo.
120 // cached logo with a fingerprint is already available. Note: 120 // |wants_cta| determines if the url should return a call to action image.
121 // |parse_logo_response_func| and |append_fingerprint_func| must be suitable 121 // Note: |parse_logo_response_func| and |append_queryparams_func| must be
122 // for running multiple times, concurrently, and on multiple threads. 122 // suitable for running multiple times, concurrently, and on multiple threads.
123 void SetServerAPI(const GURL& logo_url, 123 void SetServerAPI(const GURL& logo_url,
124 const ParseLogoResponse& parse_logo_response_func, 124 const ParseLogoResponse& parse_logo_response_func,
125 const AppendFingerprintToLogoURL& append_fingerprint_func); 125 const AppendQueryparamsToLogoURL& append_queryparams_func,
126 bool wants_cta);
126 127
127 // Retrieves the current search provider's logo from the local cache and/or 128 // Retrieves the current search provider's logo from the local cache and/or
128 // over the network, and registers |observer| to be called when the cached 129 // over the network, and registers |observer| to be called when the cached
129 // and/or fresh logos are available. 130 // and/or fresh logos are available.
130 void GetLogo(LogoObserver* observer); 131 void GetLogo(LogoObserver* observer);
131 132
132 // Prevents |observer| from receiving future updates. This is safe to call 133 // Prevents |observer| from receiving future updates. This is safe to call
133 // even when the observer is being notified of an update. 134 // even when the observer is being notified of an update.
134 void RemoveObserver(LogoObserver* observer); 135 void RemoveObserver(LogoObserver* observer);
135 136
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void OnURLFetchDownloadProgress(const net::URLFetcher* source, 177 void OnURLFetchDownloadProgress(const net::URLFetcher* source,
177 int64 current, 178 int64 current,
178 int64 total) override; 179 int64 total) override;
179 180
180 // The URL from which the logo is fetched. 181 // The URL from which the logo is fetched.
181 GURL logo_url_; 182 GURL logo_url_;
182 183
183 // The function used to parse the logo response from the server. 184 // The function used to parse the logo response from the server.
184 ParseLogoResponse parse_logo_response_func_; 185 ParseLogoResponse parse_logo_response_func_;
185 186
186 // The function used to include the cached logo's fingerprint in the logo URL. 187 // The function used to include the cached logo's fingerprint and call to
187 AppendFingerprintToLogoURL append_fingerprint_func_; 188 // action request in the logo URL.
189 AppendQueryparamsToLogoURL append_queryparams_func_;
190
191 // If |true| request call to action in server API.
192 bool wants_cta_;
188 193
189 // False if an asynchronous task is currently running. 194 // False if an asynchronous task is currently running.
190 bool is_idle_; 195 bool is_idle_;
191 196
192 // The logo that's been read from the cache, or NULL if the cache is empty. 197 // The logo that's been read from the cache, or NULL if the cache is empty.
193 // Meaningful only if is_cached_logo_valid_ is true; NULL otherwise. 198 // Meaningful only if is_cached_logo_valid_ is true; NULL otherwise.
194 scoped_ptr<Logo> cached_logo_; 199 scoped_ptr<Logo> cached_logo_;
195 200
196 // Whether the value of |cached_logo_| reflects the actual cached logo. 201 // Whether the value of |cached_logo_| reflects the actual cached logo.
197 // This will be false if the logo hasn't been read from the cache yet. 202 // This will be false if the logo hasn't been read from the cache yet.
(...skipping 26 matching lines...) Expand all
224 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 229 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
225 230
226 base::WeakPtrFactory<LogoTracker> weak_ptr_factory_; 231 base::WeakPtrFactory<LogoTracker> weak_ptr_factory_;
227 232
228 DISALLOW_COPY_AND_ASSIGN(LogoTracker); 233 DISALLOW_COPY_AND_ASSIGN(LogoTracker);
229 }; 234 };
230 235
231 } // namespace search_provider_logos 236 } // namespace search_provider_logos
232 237
233 #endif // COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ 238 #endif // COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_
OLDNEW
« no previous file with comments | « components/search_provider_logos/google_logo_api.cc ('k') | components/search_provider_logos/logo_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698