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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( | 323 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( |
324 DownloadItem* item, | 324 DownloadItem* item, |
325 const base::Closure& user_complete_callback) { | 325 const base::Closure& user_complete_callback) { |
326 return IsDownloadReadyForCompletion(item, base::Bind( | 326 return IsDownloadReadyForCompletion(item, base::Bind( |
327 &ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal, this, | 327 &ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal, this, |
328 item->GetId(), user_complete_callback)); | 328 item->GetId(), user_complete_callback)); |
329 } | 329 } |
330 | 330 |
331 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 331 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
332 if (download_crx_util::IsExtensionDownload(*item)) { | 332 if (download_crx_util::IsExtensionDownload(*item)) { |
333 scoped_refptr<CrxInstaller> crx_installer = | 333 scoped_refptr<extensions::CrxInstaller> crx_installer = |
334 download_crx_util::OpenChromeExtension(profile_, *item); | 334 download_crx_util::OpenChromeExtension(profile_, *item); |
335 | 335 |
336 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 336 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
337 // will call DelayedDownloadOpened() on this item. If this DownloadItem | 337 // will call DelayedDownloadOpened() on this item. If this DownloadItem |
338 // is not around when CRX_INSTALLER_DONE fires, Complete() will not be | 338 // is not around when CRX_INSTALLER_DONE fires, Complete() will not be |
339 // called. | 339 // called. |
340 registrar_.Add(this, | 340 registrar_.Add( |
341 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 341 this, |
342 content::Source<CrxInstaller>(crx_installer.get())); | 342 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 343 content::Source<extensions::CrxInstaller>(crx_installer.get())); |
343 | 344 |
344 crx_installers_[crx_installer.get()] = item->GetId(); | 345 crx_installers_[crx_installer.get()] = item->GetId(); |
345 // The status text and percent complete indicator will change now | 346 // The status text and percent complete indicator will change now |
346 // that we are installing a CRX. Update observers so that they pick | 347 // that we are installing a CRX. Update observers so that they pick |
347 // up the change. | 348 // up the change. |
348 item->UpdateObservers(); | 349 item->UpdateObservers(); |
349 return false; | 350 return false; |
350 } | 351 } |
351 | 352 |
352 if (ShouldOpenWithWebIntents(item)) { | 353 if (ShouldOpenWithWebIntents(item)) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 void ChromeDownloadManagerDelegate::Observe( | 615 void ChromeDownloadManagerDelegate::Observe( |
615 int type, | 616 int type, |
616 const content::NotificationSource& source, | 617 const content::NotificationSource& source, |
617 const content::NotificationDetails& details) { | 618 const content::NotificationDetails& details) { |
618 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); | 619 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); |
619 | 620 |
620 registrar_.Remove(this, | 621 registrar_.Remove(this, |
621 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 622 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
622 source); | 623 source); |
623 | 624 |
624 scoped_refptr<CrxInstaller> installer = | 625 scoped_refptr<extensions::CrxInstaller> installer = |
625 content::Source<CrxInstaller>(source).ptr(); | 626 content::Source<extensions::CrxInstaller>(source).ptr(); |
626 int download_id = crx_installers_[installer]; | 627 int download_id = crx_installers_[installer]; |
627 crx_installers_.erase(installer.get()); | 628 crx_installers_.erase(installer.get()); |
628 | 629 |
629 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 630 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
630 if (item) | 631 if (item) |
631 item->DelayedDownloadOpened(installer->did_handle_successfully()); | 632 item->DelayedDownloadOpened(installer->did_handle_successfully()); |
632 } | 633 } |
633 | 634 |
634 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 635 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
635 int32 download_id, | 636 int32 download_id, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 int32 download_id, int64 db_handle) { | 776 int32 download_id, int64 db_handle) { |
776 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 777 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
777 // call this function with an invalid |db_handle|. For instance, this can | 778 // call this function with an invalid |db_handle|. For instance, this can |
778 // happen when the history database is offline. We cannot have multiple | 779 // happen when the history database is offline. We cannot have multiple |
779 // DownloadItems with the same invalid db_handle, so we need to assign a | 780 // DownloadItems with the same invalid db_handle, so we need to assign a |
780 // unique |db_handle| here. | 781 // unique |db_handle| here. |
781 if (db_handle == DownloadItem::kUninitializedHandle) | 782 if (db_handle == DownloadItem::kUninitializedHandle) |
782 db_handle = download_history_->GetNextFakeDbHandle(); | 783 db_handle = download_history_->GetNextFakeDbHandle(); |
783 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 784 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
784 } | 785 } |
OLD | NEW |