| 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 "chrome/browser/chromeos/customization_wallpaper_downloader.h" | 5 #include "chrome/browser/chromeos/customization_wallpaper_downloader.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const base::FilePath& wallpaper_downloaded_file, | 65 const base::FilePath& wallpaper_downloaded_file, |
| 66 base::Callback<void(bool success, const GURL&)> | 66 base::Callback<void(bool success, const GURL&)> |
| 67 on_wallpaper_fetch_completed) | 67 on_wallpaper_fetch_completed) |
| 68 : url_context_getter_(url_context_getter), | 68 : url_context_getter_(url_context_getter), |
| 69 wallpaper_url_(wallpaper_url), | 69 wallpaper_url_(wallpaper_url), |
| 70 wallpaper_dir_(wallpaper_dir), | 70 wallpaper_dir_(wallpaper_dir), |
| 71 wallpaper_downloaded_file_(wallpaper_downloaded_file), | 71 wallpaper_downloaded_file_(wallpaper_downloaded_file), |
| 72 wallpaper_temporary_file_(wallpaper_downloaded_file.value() + | 72 wallpaper_temporary_file_(wallpaper_downloaded_file.value() + |
| 73 kTemporarySuffix), | 73 kTemporarySuffix), |
| 74 retries_(0), | 74 retries_(0), |
| 75 retry_delay_seconds_(kRetrySleepSeconds), |
| 75 on_wallpaper_fetch_completed_(on_wallpaper_fetch_completed), | 76 on_wallpaper_fetch_completed_(on_wallpaper_fetch_completed), |
| 76 weak_factory_(this) { | 77 weak_factory_(this) { |
| 77 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 CustomizationWallpaperDownloader::~CustomizationWallpaperDownloader() { | 81 CustomizationWallpaperDownloader::~CustomizationWallpaperDownloader() { |
| 81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void CustomizationWallpaperDownloader::StartRequest() { | 85 void CustomizationWallpaperDownloader::StartRequest() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 100 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken())); | 101 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken())); |
| 101 url_fetcher_->Start(); | 102 url_fetcher_->Start(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void CustomizationWallpaperDownloader::Retry() { | 105 void CustomizationWallpaperDownloader::Retry() { |
| 105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 106 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 106 ++retries_; | 107 ++retries_; |
| 107 | 108 |
| 108 const double delay_seconds = | 109 const double delay_seconds = |
| 109 std::min(kMaxRetrySleepSeconds, | 110 std::min(kMaxRetrySleepSeconds, |
| 110 static_cast<double>(retries_) * retries_ * kRetrySleepSeconds); | 111 static_cast<double>(retries_) * retries_ * retry_delay_seconds_); |
| 111 const base::TimeDelta delay = | 112 const base::TimeDelta delay = |
| 112 base::TimeDelta::FromSeconds(lround(delay_seconds)); | 113 base::TimeDelta::FromSeconds(lround(delay_seconds)); |
| 113 | 114 |
| 114 VLOG(1) << "Schedule Customized Wallpaper download in " << delay.InSecondsF() | 115 VLOG(1) << "Schedule Customized Wallpaper download in " << delay.InSecondsF() |
| 115 << " seconds (retry = " << retries_ << ")."; | 116 << " seconds (retry = " << retries_ << ")."; |
| 116 request_scheduled_.Start( | 117 request_scheduled_.Start( |
| 117 FROM_HERE, delay, this, &CustomizationWallpaperDownloader::StartRequest); | 118 FROM_HERE, delay, this, &CustomizationWallpaperDownloader::StartRequest); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void CustomizationWallpaperDownloader::Start() { | 121 void CustomizationWallpaperDownloader::Start() { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 void CustomizationWallpaperDownloader::OnTemporaryFileRenamed( | 189 void CustomizationWallpaperDownloader::OnTemporaryFileRenamed( |
| 189 scoped_ptr<bool> success) { | 190 scoped_ptr<bool> success) { |
| 190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 191 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 191 on_wallpaper_fetch_completed_.Run(*success, wallpaper_url_); | 192 on_wallpaper_fetch_completed_.Run(*success, wallpaper_url_); |
| 192 } | 193 } |
| 193 | 194 |
| 194 } // namespace chromeos | 195 } // namespace chromeos |
| OLD | NEW |