| 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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
| 14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 15 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 17 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 18 | 18 |
| 19 namespace search_provider_logos { | 19 namespace search_provider_logos { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const int64 kMaxDownloadBytes = 1024 * 1024; | 23 const int64_t kMaxDownloadBytes = 1024 * 1024; |
| 24 | 24 |
| 25 //const int kDecodeLogoTimeoutSeconds = 30; | 25 //const int kDecodeLogoTimeoutSeconds = 30; |
| 26 | 26 |
| 27 // Returns whether the metadata for the cached logo indicates that the logo is | 27 // Returns whether the metadata for the cached logo indicates that the logo is |
| 28 // OK to show, i.e. it's not expired or it's allowed to be shown temporarily | 28 // OK to show, i.e. it's not expired or it's allowed to be shown temporarily |
| 29 // after expiration. | 29 // after expiration. |
| 30 bool IsLogoOkToShow(const LogoMetadata& metadata, base::Time now) { | 30 bool IsLogoOkToShow(const LogoMetadata& metadata, base::Time now) { |
| 31 base::TimeDelta offset = | 31 base::TimeDelta offset = |
| 32 base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS * 3 / 2); | 32 base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS * 3 / 2); |
| 33 base::Time distant_past = now - offset; | 33 base::Time distant_past = now - offset; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 bool* parsing_failed = new bool(false); | 313 bool* parsing_failed = new bool(false); |
| 314 base::PostTaskAndReplyWithResult( | 314 base::PostTaskAndReplyWithResult( |
| 315 background_task_runner_.get(), FROM_HERE, | 315 background_task_runner_.get(), FROM_HERE, |
| 316 base::Bind(parse_logo_response_func_, base::Passed(&response), | 316 base::Bind(parse_logo_response_func_, base::Passed(&response), |
| 317 response_time, parsing_failed), | 317 response_time, parsing_failed), |
| 318 base::Bind(&LogoTracker::OnFreshLogoParsed, | 318 base::Bind(&LogoTracker::OnFreshLogoParsed, |
| 319 weak_ptr_factory_.GetWeakPtr(), base::Owned(parsing_failed))); | 319 weak_ptr_factory_.GetWeakPtr(), base::Owned(parsing_failed))); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void LogoTracker::OnURLFetchDownloadProgress(const net::URLFetcher* source, | 322 void LogoTracker::OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 323 int64 current, | 323 int64_t current, |
| 324 int64 total) { | 324 int64_t total) { |
| 325 if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { | 325 if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { |
| 326 LOG(WARNING) << "Search provider logo exceeded download size limit"; | 326 LOG(WARNING) << "Search provider logo exceeded download size limit"; |
| 327 ReturnToIdle(DOWNLOAD_OUTCOME_DOWNLOAD_FAILED); | 327 ReturnToIdle(DOWNLOAD_OUTCOME_DOWNLOAD_FAILED); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 | 330 |
| 331 } // namespace search_provider_logos | 331 } // namespace search_provider_logos |
| OLD | NEW |