| 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 |
| 160 return true; | 178 return true; |
| 179 } |
| 161 | 180 |
| 162 scoped_refptr<CrxInstaller> crx_installer = | 181 scoped_refptr<CrxInstaller> crx_installer = |
| 163 download_crx_util::OpenChromeExtension(profile_, *item); | 182 download_crx_util::OpenChromeExtension(profile_, *item); |
| 164 | 183 |
| 165 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 184 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
| 166 // will call CompleteDelayedDownload() on this item. If this DownloadItem is | 185 // will call CompleteDelayedDownload() on this item. If this DownloadItem is |
| 167 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. | 186 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. |
| 168 registrar_.Add(this, | 187 registrar_.Add(this, |
| 169 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 188 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 170 content::Source<CrxInstaller>(crx_installer.get())); | 189 content::Source<CrxInstaller>(crx_installer.get())); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 DownloadItem* item) { | 239 DownloadItem* item) { |
| 221 download_history_->UpdateEntry(item); | 240 download_history_->UpdateEntry(item); |
| 222 } | 241 } |
| 223 | 242 |
| 224 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( | 243 void ChromeDownloadManagerDelegate::UpdatePathForItemInPersistentStore( |
| 225 DownloadItem* item, | 244 DownloadItem* item, |
| 226 const FilePath& new_path) { | 245 const FilePath& new_path) { |
| 227 download_history_->UpdateDownloadPath(item, new_path); | 246 download_history_->UpdateDownloadPath(item, new_path); |
| 228 } | 247 } |
| 229 | 248 |
| 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 |
| 230 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( | 255 void ChromeDownloadManagerDelegate::RemoveItemFromPersistentStore( |
| 231 DownloadItem* item) { | 256 DownloadItem* item) { |
| 232 download_history_->RemoveEntry(item); | 257 download_history_->RemoveEntry(item); |
| 233 } | 258 } |
| 234 | 259 |
| 235 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( | 260 void ChromeDownloadManagerDelegate::RemoveItemsFromPersistentStoreBetween( |
| 236 const base::Time remove_begin, | 261 const base::Time remove_begin, |
| 237 const base::Time remove_end) { | 262 const base::Time remove_end) { |
| 238 download_history_->RemoveEntriesBetween(remove_begin, remove_end); | 263 download_history_->RemoveEntriesBetween(remove_begin, remove_end); |
| 239 } | 264 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // TODO(noelutz): This function currently works as a callback place holder. | 565 // TODO(noelutz): This function currently works as a callback place holder. |
| 541 // Once we decide the hash check is reliable, we could move the | 566 // Once we decide the hash check is reliable, we could move the |
| 542 // MaybeCompleteDownload in OnAllDataSaved to this function. | 567 // MaybeCompleteDownload in OnAllDataSaved to this function. |
| 543 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( | 568 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( |
| 544 int32 download_id, | 569 int32 download_id, |
| 545 bool is_dangerous_hash) { | 570 bool is_dangerous_hash) { |
| 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 547 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id | 572 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id |
| 548 << " is dangerous_hash: " << is_dangerous_hash; | 573 << " is dangerous_hash: " << is_dangerous_hash; |
| 549 } | 574 } |
| OLD | NEW |