| 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/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 150 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
| 151 if (!IsExtensionDownload(item)) | 151 if (!IsExtensionDownload(item)) |
| 152 return true; | 152 return true; |
| 153 | 153 |
| 154 download_crx_util::OpenChromeExtension(profile_, *item); | 154 download_crx_util::OpenChromeExtension(profile_, *item); |
| 155 return false; | 155 return false; |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { | 158 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| 159 if (!IsExtensionDownload(item)) { | 159 if (!IsExtensionDownload(item)) |
| 160 #if defined(ENABLE_SAFE_BROWSING) | |
| 161 // Begin the safe browsing download protection check. | |
| 162 SafeBrowsingService* sb_service = | |
| 163 g_browser_process->safe_browsing_service(); | |
| 164 if (sb_service && sb_service->download_protection_service() && | |
| 165 profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | |
| 166 using safe_browsing::DownloadProtectionService; | |
| 167 sb_service->download_protection_service()->CheckClientDownload( | |
| 168 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), | |
| 169 base::Bind( | |
| 170 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, | |
| 171 this, item->id())); | |
| 172 // For now, we won't delay the download for this. | |
| 173 } | |
| 174 #else | |
| 175 // Assume safe. | |
| 176 #endif | |
| 177 | |
| 178 return true; | 160 return true; |
| 179 } | |
| 180 | 161 |
| 181 scoped_refptr<CrxInstaller> crx_installer = | 162 scoped_refptr<CrxInstaller> crx_installer = |
| 182 download_crx_util::OpenChromeExtension(profile_, *item); | 163 download_crx_util::OpenChromeExtension(profile_, *item); |
| 183 | 164 |
| 184 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 165 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
| 185 // will call CompleteDelayedDownload() on this item. If this DownloadItem is | 166 // will call CompleteDelayedDownload() on this item. If this DownloadItem is |
| 186 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. | 167 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. |
| 187 registrar_.Add(this, | 168 registrar_.Add(this, |
| 188 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 169 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 189 content::Source<CrxInstaller>(crx_installer.get())); | 170 content::Source<CrxInstaller>(crx_installer.get())); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 DownloadItem* item) { | 220 DownloadItem* item) { |
| 240 download_history_->UpdateEntry(item); | 221 download_history_->UpdateEntry(item); |
| 241 } | 222 } |
| 242 | 223 |
| 243 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( | 224 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( |
| 244 DownloadItem* item, | 225 DownloadItem* item, |
| 245 const FilePath& new_path) { | 226 const FilePath& new_path) { |
| 246 download_history_->UpdateDownloadPath(item, new_path); | 227 download_history_->UpdateDownloadPath(item, new_path); |
| 247 } | 228 } |
| 248 | 229 |
| 249 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | |
| 250 int32 download_id, | |
| 251 safe_browsing::DownloadProtectionService::DownloadCheckResult result) { | |
| 252 // TODO(bryner): notify the user based on this result | |
| 253 } | |
| 254 | |
| 255 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( | 230 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( |
| 256 DownloadItem* item) { | 231 DownloadItem* item) { |
| 257 download_history_->RemoveEntry(item); | 232 download_history_->RemoveEntry(item); |
| 258 } | 233 } |
| 259 | 234 |
| 260 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( | 235 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( |
| 261 const base::Time remove_begin, | 236 const base::Time remove_begin, |
| 262 const base::Time remove_end) { | 237 const base::Time remove_end) { |
| 263 download_history_->RemoveEntriesBetween(remove_begin, remove_end); | 238 download_history_->RemoveEntriesBetween(remove_begin, remove_end); |
| 264 } | 239 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 // TODO(noelutz): This function currently works as a callback place holder. | 540 // TODO(noelutz): This function currently works as a callback place holder. |
| 566 // Once we decide the hash check is reliable, we could move the | 541 // Once we decide the hash check is reliable, we could move the |
| 567 // MaybeCompleteDownload in OnAllDataSaved to this function. | 542 // MaybeCompleteDownload in OnAllDataSaved to this function. |
| 568 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( | 543 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( |
| 569 int32 download_id, | 544 int32 download_id, |
| 570 bool is_dangerous_hash) { | 545 bool is_dangerous_hash) { |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 572 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id | 547 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id |
| 573 << " is dangerous_hash: " << is_dangerous_hash; | 548 << " is dangerous_hash: " << is_dangerous_hash; |
| 574 } | 549 } |
| OLD | NEW |