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 #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_(base::TimeDelta::FromSeconds(kRetrySleepSeconds)), | |
| 76 retry_current_delay_(base::TimeDelta::FromSeconds(0)), | |
|
Daniel Erat
2014/05/07 00:10:33
don't need to initialize this; a 0-second delay is
Alexander Alekseev
2014/05/07 00:26:08
Done.
| |
| 75 on_wallpaper_fetch_completed_(on_wallpaper_fetch_completed), | 77 on_wallpaper_fetch_completed_(on_wallpaper_fetch_completed), |
| 76 weak_factory_(this) { | 78 weak_factory_(this) { |
| 77 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 79 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 78 } | 80 } |
| 79 | 81 |
| 80 CustomizationWallpaperDownloader::~CustomizationWallpaperDownloader() { | 82 CustomizationWallpaperDownloader::~CustomizationWallpaperDownloader() { |
| 81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 82 } | 84 } |
| 83 | 85 |
| 84 void CustomizationWallpaperDownloader::StartRequest() { | 86 void CustomizationWallpaperDownloader::StartRequest() { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 98 url_fetcher_->SaveResponseToFileAtPath( | 100 url_fetcher_->SaveResponseToFileAtPath( |
| 99 wallpaper_temporary_file_, | 101 wallpaper_temporary_file_, |
| 100 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken())); | 102 blocking_pool->GetSequencedTaskRunner(blocking_pool->GetSequenceToken())); |
| 101 url_fetcher_->Start(); | 103 url_fetcher_->Start(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void CustomizationWallpaperDownloader::Retry() { | 106 void CustomizationWallpaperDownloader::Retry() { |
| 105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 107 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 106 ++retries_; | 108 ++retries_; |
| 107 | 109 |
| 108 const double delay_seconds = | 110 const double delay_seconds = std::min( |
| 109 std::min(kMaxRetrySleepSeconds, | 111 kMaxRetrySleepSeconds, |
| 110 static_cast<double>(retries_) * retries_ * kRetrySleepSeconds); | 112 static_cast<double>(retries_) * retries_ * retry_delay_.InSecondsF()); |
| 111 const base::TimeDelta delay = | 113 const base::TimeDelta delay = base::TimeDelta::FromSecondsD(delay_seconds); |
| 112 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_ << ")."; |
| 117 retry_current_delay_ = delay; | |
| 116 request_scheduled_.Start( | 118 request_scheduled_.Start( |
| 117 FROM_HERE, delay, this, &CustomizationWallpaperDownloader::StartRequest); | 119 FROM_HERE, delay, this, &CustomizationWallpaperDownloader::StartRequest); |
| 118 } | 120 } |
| 119 | 121 |
| 120 void CustomizationWallpaperDownloader::Start() { | 122 void CustomizationWallpaperDownloader::Start() { |
| 121 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 122 scoped_ptr<bool> success(new bool(false)); | 124 scoped_ptr<bool> success(new bool(false)); |
| 123 | 125 |
| 124 base::Closure mkdir_closure = base::Bind(&CreateWallpaperDirectory, | 126 base::Closure mkdir_closure = base::Bind(&CreateWallpaperDirectory, |
| 125 wallpaper_dir_, | 127 wallpaper_dir_, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 } | 187 } |
| 186 } | 188 } |
| 187 | 189 |
| 188 void CustomizationWallpaperDownloader::OnTemporaryFileRenamed( | 190 void CustomizationWallpaperDownloader::OnTemporaryFileRenamed( |
| 189 scoped_ptr<bool> success) { | 191 scoped_ptr<bool> success) { |
| 190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 192 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 191 on_wallpaper_fetch_completed_.Run(*success, wallpaper_url_); | 193 on_wallpaper_fetch_completed_.Run(*success, wallpaper_url_); |
| 192 } | 194 } |
| 193 | 195 |
| 194 } // namespace chromeos | 196 } // namespace chromeos |
| OLD | NEW |