| 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 #include "components/search_provider_logos/logo_tracker.h" | 5 #include "components/search_provider_logos/logo_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 LogoTracker::~LogoTracker() { | 82 LogoTracker::~LogoTracker() { |
| 83 ReturnToIdle(); | 83 ReturnToIdle(); |
| 84 file_task_runner_->PostTask( | 84 file_task_runner_->PostTask( |
| 85 FROM_HERE, base::Bind(&DeleteLogoCacheOnFileThread, logo_cache_)); | 85 FROM_HERE, base::Bind(&DeleteLogoCacheOnFileThread, logo_cache_)); |
| 86 logo_cache_ = NULL; | 86 logo_cache_ = NULL; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void LogoTracker::SetServerAPI( | 89 void LogoTracker::SetServerAPI( |
| 90 const GURL& logo_url, | 90 const GURL& logo_url, |
| 91 const ParseLogoResponse& parse_logo_response_func, | 91 const ParseLogoResponse& parse_logo_response_func, |
| 92 const AppendFingerprintToLogoURL& append_fingerprint_func) { | 92 const AppendQueryparamsToLogoURL& append_queryparams_func, |
| 93 bool wants_cta) { |
| 93 if (logo_url == logo_url_) | 94 if (logo_url == logo_url_) |
| 94 return; | 95 return; |
| 95 | 96 |
| 96 ReturnToIdle(); | 97 ReturnToIdle(); |
| 97 | 98 |
| 98 logo_url_ = logo_url; | 99 logo_url_ = logo_url; |
| 99 parse_logo_response_func_ = parse_logo_response_func; | 100 parse_logo_response_func_ = parse_logo_response_func; |
| 100 append_fingerprint_func_ = append_fingerprint_func; | 101 append_queryparams_func_ = append_queryparams_func; |
| 102 wants_cta_ = wants_cta; |
| 101 } | 103 } |
| 102 | 104 |
| 103 void LogoTracker::GetLogo(LogoObserver* observer) { | 105 void LogoTracker::GetLogo(LogoObserver* observer) { |
| 104 DCHECK(!logo_url_.is_empty()); | 106 DCHECK(!logo_url_.is_empty()); |
| 105 logo_observers_.AddObserver(observer); | 107 logo_observers_.AddObserver(observer); |
| 106 | 108 |
| 107 if (is_idle_) { | 109 if (is_idle_) { |
| 108 is_idle_ = false; | 110 is_idle_ = false; |
| 109 base::PostTaskAndReplyWithResult( | 111 base::PostTaskAndReplyWithResult( |
| 110 file_task_runner_.get(), | 112 file_task_runner_.get(), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 base::Bind(&LogoCache::UpdateCachedLogoMetadata, | 194 base::Bind(&LogoCache::UpdateCachedLogoMetadata, |
| 193 base::Unretained(logo_cache_), | 195 base::Unretained(logo_cache_), |
| 194 metadata)); | 196 metadata)); |
| 195 } | 197 } |
| 196 | 198 |
| 197 void LogoTracker::FetchLogo() { | 199 void LogoTracker::FetchLogo() { |
| 198 DCHECK(!fetcher_); | 200 DCHECK(!fetcher_); |
| 199 DCHECK(!is_idle_); | 201 DCHECK(!is_idle_); |
| 200 | 202 |
| 201 GURL url; | 203 GURL url; |
| 204 std::string fingerprint; |
| 202 if (cached_logo_ && !cached_logo_->metadata.fingerprint.empty() && | 205 if (cached_logo_ && !cached_logo_->metadata.fingerprint.empty() && |
| 203 cached_logo_->metadata.expiration_time >= clock_->Now()) { | 206 cached_logo_->metadata.expiration_time >= clock_->Now()) { |
| 204 url = append_fingerprint_func_.Run(logo_url_, | 207 fingerprint = cached_logo_->metadata.fingerprint; |
| 205 cached_logo_->metadata.fingerprint); | |
| 206 } else { | |
| 207 url = logo_url_; | |
| 208 } | 208 } |
| 209 url = append_queryparams_func_.Run(logo_url_, fingerprint, wants_cta_); |
| 209 | 210 |
| 210 fetcher_.reset(net::URLFetcher::Create(url, net::URLFetcher::GET, this)); | 211 fetcher_.reset(net::URLFetcher::Create(url, net::URLFetcher::GET, this)); |
| 211 fetcher_->SetRequestContext(request_context_getter_.get()); | 212 fetcher_->SetRequestContext(request_context_getter_.get()); |
| 212 fetcher_->Start(); | 213 fetcher_->Start(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void LogoTracker::OnFreshLogoParsed(scoped_ptr<EncodedLogo> logo) { | 216 void LogoTracker::OnFreshLogoParsed(scoped_ptr<EncodedLogo> logo) { |
| 216 DCHECK(!is_idle_); | 217 DCHECK(!is_idle_); |
| 217 | 218 |
| 218 if (logo) | 219 if (logo) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 void LogoTracker::OnURLFetchDownloadProgress(const net::URLFetcher* source, | 294 void LogoTracker::OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 294 int64 current, | 295 int64 current, |
| 295 int64 total) { | 296 int64 total) { |
| 296 if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { | 297 if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { |
| 297 LOG(WARNING) << "Search provider logo exceeded download size limit"; | 298 LOG(WARNING) << "Search provider logo exceeded download size limit"; |
| 298 ReturnToIdle(); | 299 ReturnToIdle(); |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 } // namespace search_provider_logos | 303 } // namespace search_provider_logos |
| OLD | NEW |