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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( | 304 bool ChromeDownloadManagerDelegate::ShouldCompleteDownload( |
305 DownloadItem* item, | 305 DownloadItem* item, |
306 const base::Closure& user_complete_callback) { | 306 const base::Closure& user_complete_callback) { |
307 return IsDownloadReadyForCompletion(item, base::Bind( | 307 return IsDownloadReadyForCompletion(item, base::Bind( |
308 &ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal, this, | 308 &ChromeDownloadManagerDelegate::ShouldCompleteDownloadInternal, this, |
309 item->GetId(), user_complete_callback)); | 309 item->GetId(), user_complete_callback)); |
310 } | 310 } |
311 | 311 |
312 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { | 312 bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { |
313 if (download_crx_util::IsExtensionDownload(*item)) { | 313 if (download_crx_util::IsExtensionDownload(*item)) { |
314 scoped_refptr<CrxInstaller> crx_installer = | 314 scoped_refptr<extensions::CrxInstaller> crx_installer = |
315 download_crx_util::OpenChromeExtension(profile_, *item); | 315 download_crx_util::OpenChromeExtension(profile_, *item); |
316 | 316 |
317 // CRX_INSTALLER_DONE will fire when the install completes. Observe() | 317 // CRX_INSTALLER_DONE will fire when the install completes. Observe() |
318 // will call DelayedDownloadOpened() on this item. If this DownloadItem | 318 // will call DelayedDownloadOpened() on this item. If this DownloadItem |
319 // is not around when CRX_INSTALLER_DONE fires, Complete() will not be | 319 // is not around when CRX_INSTALLER_DONE fires, Complete() will not be |
320 // called. | 320 // called. |
321 registrar_.Add(this, | 321 registrar_.Add( |
322 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 322 this, |
323 content::Source<CrxInstaller>(crx_installer.get())); | 323 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 324 content::Source<extensions::CrxInstaller>(crx_installer.get())); |
324 | 325 |
325 crx_installers_[crx_installer.get()] = item->GetId(); | 326 crx_installers_[crx_installer.get()] = item->GetId(); |
326 // The status text and percent complete indicator will change now | 327 // The status text and percent complete indicator will change now |
327 // that we are installing a CRX. Update observers so that they pick | 328 // that we are installing a CRX. Update observers so that they pick |
328 // up the change. | 329 // up the change. |
329 item->UpdateObservers(); | 330 item->UpdateObservers(); |
330 return false; | 331 return false; |
331 } | 332 } |
332 | 333 |
333 if (ShouldOpenWithWebIntents(item)) { | 334 if (ShouldOpenWithWebIntents(item)) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 void ChromeDownloadManagerDelegate::Observe( | 596 void ChromeDownloadManagerDelegate::Observe( |
596 int type, | 597 int type, |
597 const content::NotificationSource& source, | 598 const content::NotificationSource& source, |
598 const content::NotificationDetails& details) { | 599 const content::NotificationDetails& details) { |
599 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); | 600 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); |
600 | 601 |
601 registrar_.Remove(this, | 602 registrar_.Remove(this, |
602 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 603 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
603 source); | 604 source); |
604 | 605 |
605 scoped_refptr<CrxInstaller> installer = | 606 scoped_refptr<extensions::CrxInstaller> installer = |
606 content::Source<CrxInstaller>(source).ptr(); | 607 content::Source<extensions::CrxInstaller>(source).ptr(); |
607 int download_id = crx_installers_[installer]; | 608 int download_id = crx_installers_[installer]; |
608 crx_installers_.erase(installer.get()); | 609 crx_installers_.erase(installer.get()); |
609 | 610 |
610 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); | 611 DownloadItem* item = download_manager_->GetActiveDownloadItem(download_id); |
611 if (item) | 612 if (item) |
612 item->DelayedDownloadOpened(installer->did_handle_successfully()); | 613 item->DelayedDownloadOpened(installer->did_handle_successfully()); |
613 } | 614 } |
614 | 615 |
615 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( | 616 void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone( |
616 int32 download_id, | 617 int32 download_id, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 int32 download_id, int64 db_handle) { | 757 int32 download_id, int64 db_handle) { |
757 // It's not immediately obvious, but HistoryBackend::CreateDownload() can | 758 // It's not immediately obvious, but HistoryBackend::CreateDownload() can |
758 // call this function with an invalid |db_handle|. For instance, this can | 759 // call this function with an invalid |db_handle|. For instance, this can |
759 // happen when the history database is offline. We cannot have multiple | 760 // happen when the history database is offline. We cannot have multiple |
760 // DownloadItems with the same invalid db_handle, so we need to assign a | 761 // DownloadItems with the same invalid db_handle, so we need to assign a |
761 // unique |db_handle| here. | 762 // unique |db_handle| here. |
762 if (db_handle == DownloadItem::kUninitializedHandle) | 763 if (db_handle == DownloadItem::kUninitializedHandle) |
763 db_handle = download_history_->GetNextFakeDbHandle(); | 764 db_handle = download_history_->GetNextFakeDbHandle(); |
764 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); | 765 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); |
765 } | 766 } |
OLD | NEW |