Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 typedef base::Callback<std::unique_ptr<EncodedLogo>( | 72 typedef base::Callback<std::unique_ptr<EncodedLogo>( |
| 73 const std::unique_ptr<std::string>& response, | 73 const std::unique_ptr<std::string>& response, |
| 74 base::Time response_time, | 74 base::Time response_time, |
| 75 bool* parsing_failed)> | 75 bool* parsing_failed)> |
| 76 ParseLogoResponse; | 76 ParseLogoResponse; |
| 77 | 77 |
| 78 // Encodes the fingerprint of the cached logo in the logo URL. This enables the | 78 // Encodes the fingerprint of the cached logo in the logo URL. This enables the |
| 79 // server to verify whether the cached logo is up-to-date. | 79 // server to verify whether the cached logo is up-to-date. |
| 80 typedef base::Callback<GURL(const GURL& logo_url, | 80 typedef base::Callback<GURL(const GURL& logo_url, |
| 81 const std::string& fingerprint, | 81 const std::string& fingerprint, |
| 82 bool wants_cta)> AppendQueryparamsToLogoURL; | 82 bool wants_cta, |
| 83 bool transparent)> AppendQueryparamsToLogoURL; | |
| 83 | 84 |
| 84 // This class provides the logo for a search provider. Logos are downloaded from | 85 // This class provides the logo for a search provider. Logos are downloaded from |
| 85 // the search provider's logo URL and cached on disk. | 86 // the search provider's logo URL and cached on disk. |
| 86 // | 87 // |
| 87 // Call SetServerAPI() at least once to specify how to get the logo from the | 88 // Call SetServerAPI() at least once to specify how to get the logo from the |
| 88 // server. Then call GetLogo() to trigger retrieval of the logo and receive | 89 // server. Then call GetLogo() to trigger retrieval of the logo and receive |
| 89 // updates once the cached and/or fresh logos are available. | 90 // updates once the cached and/or fresh logos are available. |
| 90 class LogoTracker : public net::URLFetcherDelegate { | 91 class LogoTracker : public net::URLFetcherDelegate { |
| 91 public: | 92 public: |
| 92 // Constructs a LogoTracker with the given LogoDelegate. Takes ownership of | 93 // Constructs a LogoTracker with the given LogoDelegate. Takes ownership of |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 116 // called at least once before calling GetLogo(). | 117 // called at least once before calling GetLogo(). |
| 117 // | 118 // |
| 118 // |logo_url| is the URL from which the logo will be downloaded. If |logo_url| | 119 // |logo_url| is the URL from which the logo will be downloaded. If |logo_url| |
| 119 // is different than the current logo URL, any pending LogoObservers will be | 120 // is different than the current logo URL, any pending LogoObservers will be |
| 120 // canceled. | 121 // canceled. |
| 121 // | 122 // |
| 122 // |parse_logo_response_func| is a callback that will be used to parse the | 123 // |parse_logo_response_func| is a callback that will be used to parse the |
| 123 // server's response into a EncodedLogo object. |append_queryparams_func| is a | 124 // server's response into a EncodedLogo object. |append_queryparams_func| is a |
| 124 // callback that will return the URL from which to download the logo. | 125 // callback that will return the URL from which to download the logo. |
| 125 // |wants_cta| determines if the url should return a call to action image. | 126 // |wants_cta| determines if the url should return a call to action image. |
| 127 // |transparent| determines whether to request a transparent logo | |
|
Marc Treib
2016/05/09 16:58:21
nit: Period at the end of the line please
atanasova
2016/05/10 08:32:17
Done.
| |
| 126 // Note: |parse_logo_response_func| and |append_queryparams_func| must be | 128 // Note: |parse_logo_response_func| and |append_queryparams_func| must be |
| 127 // suitable for running multiple times, concurrently, and on multiple threads. | 129 // suitable for running multiple times, concurrently, and on multiple threads. |
| 128 // TODO(ianwen): remove wants_cta from parameter. | 130 // TODO(ianwen): remove wants_cta from parameter. |
| 129 void SetServerAPI(const GURL& logo_url, | 131 void SetServerAPI(const GURL& logo_url, |
| 130 const ParseLogoResponse& parse_logo_response_func, | 132 const ParseLogoResponse& parse_logo_response_func, |
| 131 const AppendQueryparamsToLogoURL& append_queryparams_func, | 133 const AppendQueryparamsToLogoURL& append_queryparams_func, |
| 132 bool wants_cta); | 134 bool wants_cta, |
| 135 bool transparent = false); | |
|
Marc Treib
2016/05/09 16:58:21
Also here: No default values :(
atanasova
2016/05/10 08:32:17
Done.
| |
| 133 | 136 |
| 134 // Retrieves the current search provider's logo from the local cache and/or | 137 // Retrieves the current search provider's logo from the local cache and/or |
| 135 // over the network, and registers |observer| to be called when the cached | 138 // over the network, and registers |observer| to be called when the cached |
| 136 // and/or fresh logos are available. | 139 // and/or fresh logos are available. |
| 137 void GetLogo(LogoObserver* observer); | 140 void GetLogo(LogoObserver* observer); |
| 138 | 141 |
| 139 // Prevents |observer| from receiving future updates. This is safe to call | 142 // Prevents |observer| from receiving future updates. This is safe to call |
| 140 // even when the observer is being notified of an update. | 143 // even when the observer is being notified of an update. |
| 141 void RemoveObserver(LogoObserver* observer); | 144 void RemoveObserver(LogoObserver* observer); |
| 142 | 145 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // The function used to parse the logo response from the server. | 212 // The function used to parse the logo response from the server. |
| 210 ParseLogoResponse parse_logo_response_func_; | 213 ParseLogoResponse parse_logo_response_func_; |
| 211 | 214 |
| 212 // The function used to include the cached logo's fingerprint and call to | 215 // The function used to include the cached logo's fingerprint and call to |
| 213 // action request in the logo URL. | 216 // action request in the logo URL. |
| 214 AppendQueryparamsToLogoURL append_queryparams_func_; | 217 AppendQueryparamsToLogoURL append_queryparams_func_; |
| 215 | 218 |
| 216 // If |true| request call to action in server API. | 219 // If |true| request call to action in server API. |
| 217 bool wants_cta_; | 220 bool wants_cta_; |
| 218 | 221 |
| 222 // If |true| request transparent doodle. | |
| 223 bool transparent_; | |
| 224 | |
| 219 // False if an asynchronous task is currently running. | 225 // False if an asynchronous task is currently running. |
| 220 bool is_idle_; | 226 bool is_idle_; |
| 221 | 227 |
| 222 // The logo that's been read from the cache, or NULL if the cache is empty. | 228 // The logo that's been read from the cache, or NULL if the cache is empty. |
| 223 // Meaningful only if is_cached_logo_valid_ is true; NULL otherwise. | 229 // Meaningful only if is_cached_logo_valid_ is true; NULL otherwise. |
| 224 std::unique_ptr<Logo> cached_logo_; | 230 std::unique_ptr<Logo> cached_logo_; |
| 225 | 231 |
| 226 // Whether the value of |cached_logo_| reflects the actual cached logo. | 232 // Whether the value of |cached_logo_| reflects the actual cached logo. |
| 227 // This will be false if the logo hasn't been read from the cache yet. | 233 // This will be false if the logo hasn't been read from the cache yet. |
| 228 // |cached_logo_| may be NULL even if |is_cached_logo_valid_| is true, if no | 234 // |cached_logo_| may be NULL even if |is_cached_logo_valid_| is true, if no |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 257 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 263 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 258 | 264 |
| 259 base::WeakPtrFactory<LogoTracker> weak_ptr_factory_; | 265 base::WeakPtrFactory<LogoTracker> weak_ptr_factory_; |
| 260 | 266 |
| 261 DISALLOW_COPY_AND_ASSIGN(LogoTracker); | 267 DISALLOW_COPY_AND_ASSIGN(LogoTracker); |
| 262 }; | 268 }; |
| 263 | 269 |
| 264 } // namespace search_provider_logos | 270 } // namespace search_provider_logos |
| 265 | 271 |
| 266 #endif // COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ | 272 #endif // COMPONENTS_SEARCH_PROVIDER_LOGOS_LOGO_TRACKER_H_ |
| OLD | NEW |