| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 31 #include "chrome/browser/history/download_history_info.h" | 31 #include "chrome/browser/history/download_history_info.h" |
| 32 #include "chrome/browser/platform_util.h" | 32 #include "chrome/browser/platform_util.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/tab_contents/tab_util.h" | 34 #include "chrome/browser/tab_contents/tab_util.h" |
| 35 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_list.h" | 36 #include "chrome/browser/ui/browser_list.h" |
| 37 #include "chrome/browser/ui/download/download_tab_helper.h" | 37 #include "chrome/browser/ui/download/download_tab_helper.h" |
| 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 38 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 39 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
| 40 #include "chrome/common/pref_names.h" |
| 40 #include "content/browser/browser_thread.h" | 41 #include "content/browser/browser_thread.h" |
| 41 #include "content/browser/renderer_host/render_process_host.h" | 42 #include "content/browser/renderer_host/render_process_host.h" |
| 42 #include "content/browser/renderer_host/render_view_host.h" | 43 #include "content/browser/renderer_host/render_view_host.h" |
| 43 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 44 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 44 #include "content/browser/tab_contents/tab_contents.h" | 45 #include "content/browser/tab_contents/tab_contents.h" |
| 45 #include "content/common/notification_type.h" | 46 #include "content/common/notification_type.h" |
| 46 #include "googleurl/src/gurl.h" | 47 #include "googleurl/src/gurl.h" |
| 47 #include "grit/generated_resources.h" | 48 #include "grit/generated_resources.h" |
| 48 #include "grit/theme_resources.h" | 49 #include "grit/theme_resources.h" |
| 49 #include "net/base/mime_util.h" | 50 #include "net/base/mime_util.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 void DownloadManager::StartDownload(int32 download_id) { | 263 void DownloadManager::StartDownload(int32 download_id) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 | 265 |
| 265 DownloadItem* download = GetActiveDownloadItem(download_id); | 266 DownloadItem* download = GetActiveDownloadItem(download_id); |
| 266 if (!download) | 267 if (!download) |
| 267 return; | 268 return; |
| 268 | 269 |
| 269 // Create a client to verify download URL with safebrowsing. | 270 // Create a client to verify download URL with safebrowsing. |
| 270 // It deletes itself after the callback. | 271 // It deletes itself after the callback. |
| 271 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( | 272 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( |
| 272 download_id, download->url_chain(), download->referrer_url()); | 273 download_id, download->url_chain(), download->referrer_url(), |
| 274 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)); |
| 273 sb_client->CheckDownloadUrl( | 275 sb_client->CheckDownloadUrl( |
| 274 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); | 276 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
| 275 } | 277 } |
| 276 | 278 |
| 277 void DownloadManager::CheckForHistoryFilesRemoval() { | 279 void DownloadManager::CheckForHistoryFilesRemoval() { |
| 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 279 for (DownloadMap::iterator it = history_downloads_.begin(); | 281 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 280 it != history_downloads_.end(); ++it) { | 282 it != history_downloads_.end(); ++it) { |
| 281 CheckForFileRemoval(it->second); | 283 CheckForFileRemoval(it->second); |
| 282 } | 284 } |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 DownloadItem* download = active_downloads_[download_id]; | 661 DownloadItem* download = active_downloads_[download_id]; |
| 660 download->OnAllDataSaved(size); | 662 download->OnAllDataSaved(size); |
| 661 | 663 |
| 662 // When hash is not available, it means either it is not calculated | 664 // When hash is not available, it means either it is not calculated |
| 663 // or there is error while it is calculated. We will skip the download hash | 665 // or there is error while it is calculated. We will skip the download hash |
| 664 // check in that case. | 666 // check in that case. |
| 665 if (!hash.empty()) { | 667 if (!hash.empty()) { |
| 666 scoped_refptr<DownloadSBClient> sb_client = | 668 scoped_refptr<DownloadSBClient> sb_client = |
| 667 new DownloadSBClient(download_id, | 669 new DownloadSBClient(download_id, |
| 668 download->url_chain(), | 670 download->url_chain(), |
| 669 download->referrer_url()); | 671 download->referrer_url(), |
| 672 profile_->GetPrefs()->GetBoolean( |
| 673 prefs::kSafeBrowsingEnabled)); |
| 670 sb_client->CheckDownloadHash( | 674 sb_client->CheckDownloadHash( |
| 671 hash, NewCallback(this, &DownloadManager::CheckDownloadHashDone)); | 675 hash, NewCallback(this, &DownloadManager::CheckDownloadHashDone)); |
| 672 } | 676 } |
| 673 MaybeCompleteDownload(download); | 677 MaybeCompleteDownload(download); |
| 674 } | 678 } |
| 675 | 679 |
| 676 // TODO(lzheng): This function currently works as a callback place holder. | 680 // TODO(lzheng): This function currently works as a callback place holder. |
| 677 // Once we decide the hash check is reliable, we could move the | 681 // Once we decide the hash check is reliable, we could move the |
| 678 // MaybeCompleteDownload in OnAllDataSaved to this function. | 682 // MaybeCompleteDownload in OnAllDataSaved to this function. |
| 679 void DownloadManager::CheckDownloadHashDone(int32 download_id, | 683 void DownloadManager::CheckDownloadHashDone(int32 download_id, |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 observed_download_manager_->RemoveObserver(this); | 1338 observed_download_manager_->RemoveObserver(this); |
| 1335 } | 1339 } |
| 1336 | 1340 |
| 1337 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1341 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
| 1338 observing_download_manager_->NotifyModelChanged(); | 1342 observing_download_manager_->NotifyModelChanged(); |
| 1339 } | 1343 } |
| 1340 | 1344 |
| 1341 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1345 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
| 1342 observed_download_manager_ = NULL; | 1346 observed_download_manager_ = NULL; |
| 1343 } | 1347 } |
| OLD | NEW |