Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); | 147 CheckDownloadUrlDone(download_id, DownloadProtectionService::SAFE); |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 void ChromeDownloadManagerDelegate::ChooseDownloadPath( | 151 void ChromeDownloadManagerDelegate::ChooseDownloadPath( |
| 152 WebContents* web_contents, | 152 WebContents* web_contents, |
| 153 const FilePath& suggested_path, | 153 const FilePath& suggested_path, |
| 154 int32 download_id) { | 154 int32 download_id) { |
| 155 // Deletes itself. | 155 // Deletes itself. |
| 156 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
| 157 new DownloadFilePickerChromeOS( | 157 new DownloadFilePickerChromeOS |
| 158 #else | 158 #else |
| 159 new DownloadFilePicker( | 159 new DownloadFilePicker |
| 160 #endif | 160 #endif |
| 161 download_manager_, web_contents, suggested_path, download_id); | 161 (download_manager_, web_contents, suggested_path, download_id); |
| 162 } | 162 } |
| 163 | 163 |
| 164 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath( | 164 FilePath ChromeDownloadManagerDelegate::GetIntermediatePath( |
| 165 const FilePath& suggested_path) { | 165 const FilePath& suggested_path) { |
| 166 return download_util::GetCrDownloadPath(suggested_path); | 166 return download_util::GetCrDownloadPath(suggested_path); |
| 167 } | 167 } |
| 168 | 168 |
| 169 WebContents* ChromeDownloadManagerDelegate:: | 169 WebContents* ChromeDownloadManagerDelegate:: |
| 170 GetAlternativeWebContentsToNotifyForDownload() { | 170 GetAlternativeWebContentsToNotifyForDownload() { |
| 171 #if defined(OS_ANDROID) | 171 #if defined(OS_ANDROID) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 186 FilePath::StringType extension = path.Extension(); | 186 FilePath::StringType extension = path.Extension(); |
| 187 if (extension.empty()) | 187 if (extension.empty()) |
| 188 return false; | 188 return false; |
| 189 if (Extension::IsExtension(path)) | 189 if (Extension::IsExtension(path)) |
| 190 return false; | 190 return false; |
| 191 DCHECK(extension[0] == FilePath::kExtensionSeparator); | 191 DCHECK(extension[0] == FilePath::kExtensionSeparator); |
| 192 extension.erase(0, 1); | 192 extension.erase(0, 1); |
| 193 return download_prefs_->IsAutoOpenEnabledForExtension(extension); | 193 return download_prefs_->IsAutoOpenEnabledForExtension(extension); |
| 194 } | 194 } |
| 195 | 195 |
| 196 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { | 196 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( |
| 197 DownloadItem* item, | |
| 198 const base::Closure& maybe_complete_download) { | |
| 197 #if defined(ENABLE_SAFE_BROWSING) | 199 #if defined(ENABLE_SAFE_BROWSING) |
| 198 // See if there is already a pending SafeBrowsing check for that download. | 200 // See if there is already a pending SafeBrowsing check for that download. |
| 199 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 201 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| 200 item->GetExternalData(&safe_browsing_id)); | 202 item->GetExternalData(&safe_browsing_id)); |
| 201 if (state) | 203 if (state) |
| 202 // Don't complete the download until we have an answer. | 204 // Don't complete the download until we have an answer. |
| 203 return !state->pending; | 205 return !state->pending; |
| 204 | 206 |
| 205 // Begin the safe browsing download protection check. | 207 // Begin the safe browsing download protection check. |
| 206 DownloadProtectionService* service = GetDownloadProtectionService(); | 208 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 207 if (service) { | 209 if (service) { |
| 208 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " | 210 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " |
| 209 << item->DebugString(false); | 211 << item->DebugString(false); |
| 210 state = new SafeBrowsingState(); | 212 state = new SafeBrowsingState(); |
| 211 state->pending = true; | 213 state->pending = true; |
| 212 state->verdict = DownloadProtectionService::SAFE; | 214 state->verdict = DownloadProtectionService::SAFE; |
|
asanka
2012/05/01 15:54:10
Also store the Closure in |state| and invoke it fr
benjhayden
2012/05/01 18:02:52
Done.
| |
| 213 item->SetExternalData(&safe_browsing_id, state); | 215 item->SetExternalData(&safe_browsing_id, state); |
| 214 service->CheckClientDownload( | 216 service->CheckClientDownload( |
| 215 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), | 217 DownloadProtectionService::DownloadInfo::FromDownloadItem(*item), |
| 216 base::Bind( | 218 base::Bind( |
| 217 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 219 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| 218 this, | 220 this, |
| 219 item->GetId())); | 221 item->GetId())); |
| 220 return false; | 222 return false; |
| 221 } | 223 } |
| 222 #endif | 224 #endif |
| 223 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
| 224 // If there's a GData upload associated with this download, we wait until that | 226 // If there's a GData upload associated with this download, we wait until that |
| 225 // is complete before allowing the download item to complete. | 227 // is complete before allowing the download item to complete. |
| 226 if (!gdata::GDataDownloadObserver::IsReadyToComplete(item)) | 228 if (!gdata::GDataDownloadObserver::IsReadyToComplete( |
| 229 item, maybe_complete_download)) | |
| 227 return false; | 230 return false; |
| 228 #endif | 231 #endif |
| 229 return true; | 232 return true; |
| 230 } | 233 } |
| 231 | 234 |
| 232 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 235 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
| 233 if (IsExtensionDownload(item)) { | 236 if (IsExtensionDownload(item)) { |
| 234 scoped_refptr<CrxInstaller> crx_installer = | 237 scoped_refptr<CrxInstaller> crx_installer = |
| 235 download_crx_util::OpenChromeExtension(profile_, *item); | 238 download_crx_util::OpenChromeExtension(profile_, *item); |
| 236 | 239 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 int32 download_id, int64 db_handle) { | 703 int32 download_id, int64 db_handle) { |
| 701 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 704 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
| 702 // call this function with an invalid |db_handle|. For instance, this can | 705 // call this function with an invalid |db_handle|. For instance, this can |
| 703 // happen when the history database is offline. We cannot have multiple | 706 // happen when the history database is offline. We cannot have multiple |
| 704 // DownloadItems with the same invalid db_handle, so we need to assign a | 707 // DownloadItems with the same invalid db_handle, so we need to assign a |
| 705 // unique |db_handle| here. | 708 // unique |db_handle| here. |
| 706 if (db_handle == DownloadItem::kUninitializedHandle) | 709 if (db_handle == DownloadItem::kUninitializedHandle) |
| 707 db_handle = download_history_->GetNextFakeDbHandle(); | 710 db_handle = download_history_->GetNextFakeDbHandle(); |
| 708 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 711 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
| 709 } | 712 } |
| OLD | NEW |