| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 FilePath::StringType extension = path.Extension(); | 140 FilePath::StringType extension = path.Extension(); |
| 141 if (extension.empty()) | 141 if (extension.empty()) |
| 142 return false; | 142 return false; |
| 143 if (Extension::IsExtension(path)) | 143 if (Extension::IsExtension(path)) |
| 144 return false; | 144 return false; |
| 145 DCHECK(extension[0] == FilePath::kExtensionSeparator); | 145 DCHECK(extension[0] == FilePath::kExtensionSeparator); |
| 146 extension.erase(0, 1); | 146 extension.erase(0, 1); |
| 147 return download_prefs_->IsAutoOpenEnabledForExtension(extension); | 147 return download_prefs_->IsAutoOpenEnabledForExtension(extension); |
| 148 } | 148 } |
| 149 | 149 |
| 150 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| 151 return true; |
| 152 } |
| 153 |
| 150 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 154 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
| 151 if (!IsExtensionDownload(item)) | 155 if (!IsExtensionDownload(item)) |
| 152 return true; | 156 return true; |
| 153 | 157 |
| 154 download_crx_util::OpenChromeExtension(profile_, *item); | |
| 155 return false; | |
| 156 } | |
| 157 | |
| 158 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { | |
| 159 if (!IsExtensionDownload(item)) | |
| 160 return true; | |
| 161 | |
| 162 scoped_refptr<CrxInstaller> crx_installer = | 158 scoped_refptr<CrxInstaller> crx_installer = |
| 163 download_crx_util::OpenChromeExtension(profile_, *item); | 159 download_crx_util::OpenChromeExtension(profile_, *item); |
| 164 | 160 |
| 165 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 161 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
| 166 // will call CompleteDelayedDownload() on this item. If this DownloadItem is | 162 // will call DelayedDownloadOpened() on this item. If this DownloadItem is |
| 167 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. | 163 // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. |
| 168 registrar_.Add(this, | 164 registrar_.Add(this, |
| 169 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 165 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 170 content::Source<CrxInstaller>(crx_installer.get())); | 166 content::Source<CrxInstaller>(crx_installer.get())); |
| 171 | 167 |
| 172 crx_installers_[crx_installer.get()] = item->id(); | 168 crx_installers_[crx_installer.get()] = item->id(); |
| 173 // The status text and percent complete indicator will change now | 169 // The status text and percent complete indicator will change now |
| 174 // that we are installing a CRX. Update observers so that they pick | 170 // that we are installing a CRX. Update observers so that they pick |
| 175 // up the change. | 171 // up the change. |
| 176 item->UpdateObservers(); | 172 item->UpdateObservers(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 registrar_.Remove(this, | 311 registrar_.Remove(this, |
| 316 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 312 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 317 source); | 313 source); |
| 318 | 314 |
| 319 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr(); | 315 CrxInstaller* installer = content::Source<CrxInstaller>(source).ptr(); |
| 320 int download_id = crx_installers_[installer]; | 316 int download_id = crx_installers_[installer]; |
| 321 crx_installers_.erase(installer); | 317 crx_installers_.erase(installer); |
| 322 | 318 |
| 323 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 319 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
| 324 if (item) | 320 if (item) |
| 325 item->CompleteDelayedDownload(); | 321 item->DelayedDownloadOpened(); |
| 326 } | 322 } |
| 327 | 323 |
| 328 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 324 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
| 329 int32 download_id, | 325 int32 download_id, |
| 330 bool visited_referrer_before) { | 326 bool visited_referrer_before) { |
| 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 332 | 328 |
| 333 DownloadItem* download = | 329 DownloadItem* download = |
| 334 download_manager_->GetActiveDownloadItem(download_id); | 330 download_manager_->GetActiveDownloadItem(download_id); |
| 335 if (!download) | 331 if (!download) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // TODO(noelutz): This function currently works as a callback place holder. | 536 // TODO(noelutz): This function currently works as a callback place holder. |
| 541 // Once we decide the hash check is reliable, we could move the | 537 // Once we decide the hash check is reliable, we could move the |
| 542 // MaybeCompleteDownload in OnAllDataSaved to this function. | 538 // MaybeCompleteDownload in OnAllDataSaved to this function. |
| 543 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( | 539 void ChromeDownloadManagerDelegate::CheckDownloadHashDone( |
| 544 int32 download_id, | 540 int32 download_id, |
| 545 bool is_dangerous_hash) { | 541 bool is_dangerous_hash) { |
| 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 547 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id | 543 DVLOG(1) << "CheckDownloadHashDone, download_id: " << download_id |
| 548 << " is dangerous_hash: " << is_dangerous_hash; | 544 << " is dangerous_hash: " << is_dangerous_hash; |
| 549 } | 545 } |
| OLD | NEW |