OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 | 259 |
260 // Create a client to verify download URL with safebrowsing. | 260 // Create a client to verify download URL with safebrowsing. |
261 // It deletes itself after the callback. | 261 // It deletes itself after the callback. |
262 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( | 262 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( |
263 info->download_id, info->url_chain, info->referrer_url); | 263 info->download_id, info->url_chain, info->referrer_url); |
264 sb_client->CheckDownloadUrl( | 264 sb_client->CheckDownloadUrl( |
265 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); | 265 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
266 } | 266 } |
267 | 267 |
| 268 void DownloadManager::CheckExistingPaths() { |
| 269 PathVector existing_paths; |
| 270 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 271 it != history_downloads_.end(); ++it) { |
| 272 DownloadItem* download_item = it->second; |
| 273 if (download_item->IsComplete() && download_item->is_path_exists()) { |
| 274 existing_paths.push_back(std::pair<int64, FilePath>( |
| 275 it->first, download_item->GetTargetFilePath())); |
| 276 } |
| 277 } |
| 278 |
| 279 BrowserThread::PostTask( |
| 280 BrowserThread::FILE, FROM_HERE, |
| 281 NewRunnableMethod(this, |
| 282 &DownloadManager::CheckExistingPathsOnFileThread, |
| 283 existing_paths)); |
| 284 } |
| 285 |
| 286 void DownloadManager::CheckExistingPathsOnFileThread( |
| 287 PathVector existing_paths) { |
| 288 PathVector removed_paths; |
| 289 for (PathVector::iterator it = existing_paths.begin(); |
| 290 it != existing_paths.end(); ++it) { |
| 291 if (!file_util::PathExists(it->second)) { |
| 292 removed_paths.push_back(std::pair<int64, FilePath>( |
| 293 it->first, it->second)); |
| 294 } |
| 295 } |
| 296 |
| 297 BrowserThread::PostTask( |
| 298 BrowserThread::UI, FROM_HERE, |
| 299 NewRunnableMethod(this, |
| 300 &DownloadManager::OnExistingPathsAvailable, |
| 301 removed_paths)); |
| 302 } |
| 303 |
| 304 void DownloadManager::OnExistingPathsAvailable(PathVector removed_paths) { |
| 305 for (PathVector::iterator it = removed_paths.begin(); |
| 306 it != removed_paths.end(); ++it) { |
| 307 DownloadMap::iterator map_it = history_downloads_.find(it->first); |
| 308 if (map_it != history_downloads_.end()) { |
| 309 DownloadItem* download_item = map_it->second; |
| 310 download_item->set_is_path_exists(false); |
| 311 download_item->UpdateObservers(); |
| 312 } |
| 313 } |
| 314 } |
| 315 |
268 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, | 316 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, |
269 bool is_dangerous_url) { | 317 bool is_dangerous_url) { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
271 DCHECK(info); | 319 DCHECK(info); |
272 | 320 |
273 info->is_dangerous_url = is_dangerous_url; | 321 info->is_dangerous_url = is_dangerous_url; |
274 | 322 |
275 // Check whether this download is for an extension install or not. | 323 // Check whether this download is for an extension install or not. |
276 // Allow extensions to be explicitly saved. | 324 // Allow extensions to be explicitly saved. |
277 if (!info->prompt_user_for_save_location) { | 325 if (!info->prompt_user_for_save_location) { |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 observed_download_manager_->RemoveObserver(this); | 1223 observed_download_manager_->RemoveObserver(this); |
1176 } | 1224 } |
1177 | 1225 |
1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1226 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1179 observing_download_manager_->NotifyModelChanged(); | 1227 observing_download_manager_->NotifyModelChanged(); |
1180 } | 1228 } |
1181 | 1229 |
1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1230 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1183 observed_download_manager_ = NULL; | 1231 observed_download_manager_ = NULL; |
1184 } | 1232 } |
OLD | NEW |