| 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/customization_wallpaper_download
er.h" | 5 #include "chrome/browser/chromeos/customization/customization_wallpaper_download
er.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 VLOG(1) << "Schedule Customized Wallpaper download in " << delay.InSecondsF() | 115 VLOG(1) << "Schedule Customized Wallpaper download in " << delay.InSecondsF() |
| 116 << " seconds (retry = " << retries_ << ")."; | 116 << " seconds (retry = " << retries_ << ")."; |
| 117 retry_current_delay_ = delay; | 117 retry_current_delay_ = delay; |
| 118 request_scheduled_.Start( | 118 request_scheduled_.Start( |
| 119 FROM_HERE, delay, this, &CustomizationWallpaperDownloader::StartRequest); | 119 FROM_HERE, delay, this, &CustomizationWallpaperDownloader::StartRequest); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void CustomizationWallpaperDownloader::Start() { | 122 void CustomizationWallpaperDownloader::Start() { |
| 123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 124 scoped_ptr<bool> success(new bool(false)); | 124 std::unique_ptr<bool> success(new bool(false)); |
| 125 | 125 |
| 126 base::Closure mkdir_closure = base::Bind(&CreateWallpaperDirectory, | 126 base::Closure mkdir_closure = base::Bind(&CreateWallpaperDirectory, |
| 127 wallpaper_dir_, | 127 wallpaper_dir_, |
| 128 base::Unretained(success.get())); | 128 base::Unretained(success.get())); |
| 129 base::Closure on_created_closure = | 129 base::Closure on_created_closure = |
| 130 base::Bind(&CustomizationWallpaperDownloader::OnWallpaperDirectoryCreated, | 130 base::Bind(&CustomizationWallpaperDownloader::OnWallpaperDirectoryCreated, |
| 131 weak_factory_.GetWeakPtr(), base::Passed(std::move(success))); | 131 weak_factory_.GetWeakPtr(), base::Passed(std::move(success))); |
| 132 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | 132 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 133 FROM_HERE, mkdir_closure, on_created_closure)) { | 133 FROM_HERE, mkdir_closure, on_created_closure)) { |
| 134 LOG(WARNING) << "Failed to start Customized Wallpaper download."; | 134 LOG(WARNING) << "Failed to start Customized Wallpaper download."; |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 void CustomizationWallpaperDownloader::OnWallpaperDirectoryCreated( | 138 void CustomizationWallpaperDownloader::OnWallpaperDirectoryCreated( |
| 139 scoped_ptr<bool> success) { | 139 std::unique_ptr<bool> success) { |
| 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 141 if (*success) | 141 if (*success) |
| 142 StartRequest(); | 142 StartRequest(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void CustomizationWallpaperDownloader::OnURLFetchComplete( | 145 void CustomizationWallpaperDownloader::OnURLFetchComplete( |
| 146 const net::URLFetcher* source) { | 146 const net::URLFetcher* source) { |
| 147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 148 DCHECK_EQ(url_fetcher_.get(), source); | 148 DCHECK_EQ(url_fetcher_.get(), source); |
| 149 | 149 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 161 if (server_error) { | 161 if (server_error) { |
| 162 url_fetcher_.reset(); | 162 url_fetcher_.reset(); |
| 163 Retry(); | 163 Retry(); |
| 164 return; | 164 return; |
| 165 } | 165 } |
| 166 | 166 |
| 167 base::FilePath response_path; | 167 base::FilePath response_path; |
| 168 url_fetcher_->GetResponseAsFilePath(true, &response_path); | 168 url_fetcher_->GetResponseAsFilePath(true, &response_path); |
| 169 url_fetcher_.reset(); | 169 url_fetcher_.reset(); |
| 170 | 170 |
| 171 scoped_ptr<bool> success(new bool(false)); | 171 std::unique_ptr<bool> success(new bool(false)); |
| 172 | 172 |
| 173 base::Closure rename_closure = base::Bind(&RenameTemporaryFile, | 173 base::Closure rename_closure = base::Bind(&RenameTemporaryFile, |
| 174 response_path, | 174 response_path, |
| 175 wallpaper_downloaded_file_, | 175 wallpaper_downloaded_file_, |
| 176 base::Unretained(success.get())); | 176 base::Unretained(success.get())); |
| 177 base::Closure on_rename_closure = | 177 base::Closure on_rename_closure = |
| 178 base::Bind(&CustomizationWallpaperDownloader::OnTemporaryFileRenamed, | 178 base::Bind(&CustomizationWallpaperDownloader::OnTemporaryFileRenamed, |
| 179 weak_factory_.GetWeakPtr(), base::Passed(std::move(success))); | 179 weak_factory_.GetWeakPtr(), base::Passed(std::move(success))); |
| 180 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | 180 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 181 FROM_HERE, rename_closure, on_rename_closure)) { | 181 FROM_HERE, rename_closure, on_rename_closure)) { |
| 182 LOG(WARNING) | 182 LOG(WARNING) |
| 183 << "Failed to start Customized Wallpaper Rename DownloadedFile."; | 183 << "Failed to start Customized Wallpaper Rename DownloadedFile."; |
| 184 on_wallpaper_fetch_completed_.Run(false, wallpaper_url_); | 184 on_wallpaper_fetch_completed_.Run(false, wallpaper_url_); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 void CustomizationWallpaperDownloader::OnTemporaryFileRenamed( | 188 void CustomizationWallpaperDownloader::OnTemporaryFileRenamed( |
| 189 scoped_ptr<bool> success) { | 189 std::unique_ptr<bool> success) { |
| 190 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 190 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 191 on_wallpaper_fetch_completed_.Run(*success, wallpaper_url_); | 191 on_wallpaper_fetch_completed_.Run(*success, wallpaper_url_); |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace chromeos | 194 } // namespace chromeos |
| OLD | NEW |