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/download_item_model.h" | 5 #include "chrome/browser/download/download_item_model.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 17 #include "chrome/browser/download/download_core_service.h" |
| 18 #include "chrome/browser/download/download_core_service_factory.h" |
17 #include "chrome/browser/download/download_crx_util.h" | 19 #include "chrome/browser/download/download_crx_util.h" |
18 #include "chrome/browser/download/download_history.h" | 20 #include "chrome/browser/download/download_history.h" |
19 #include "chrome/browser/download/download_service.h" | |
20 #include "chrome/browser/download/download_service_factory.h" | |
21 #include "chrome/browser/download/download_stats.h" | 21 #include "chrome/browser/download/download_stats.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 23 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
24 #include "chrome/common/safe_browsing/download_file_types.pb.h" | 24 #include "chrome/common/safe_browsing/download_file_types.pb.h" |
25 #include "chrome/grit/chromium_strings.h" | 25 #include "chrome/grit/chromium_strings.h" |
26 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
27 #include "components/mime_util/mime_util.h" | 27 #include "components/mime_util/mime_util.h" |
28 #include "content/public/browser/download_danger_type.h" | 28 #include "content/public/browser/download_danger_type.h" |
29 #include "content/public/browser/download_interrupt_reasons.h" | 29 #include "content/public/browser/download_interrupt_reasons.h" |
30 #include "content/public/browser/download_item.h" | 30 #include "content/public/browser/download_item.h" |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 } | 608 } |
609 | 609 |
610 void DownloadItemModel::SetShouldShowInShelf(bool should_show) { | 610 void DownloadItemModel::SetShouldShowInShelf(bool should_show) { |
611 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); | 611 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); |
612 data->should_show_in_shelf_ = should_show; | 612 data->should_show_in_shelf_ = should_show; |
613 } | 613 } |
614 | 614 |
615 bool DownloadItemModel::ShouldNotifyUI() const { | 615 bool DownloadItemModel::ShouldNotifyUI() const { |
616 Profile* profile = | 616 Profile* profile = |
617 Profile::FromBrowserContext(download_->GetBrowserContext()); | 617 Profile::FromBrowserContext(download_->GetBrowserContext()); |
618 DownloadService* download_service = | 618 DownloadCoreService* download_core_service = |
619 DownloadServiceFactory::GetForBrowserContext(profile); | 619 DownloadCoreServiceFactory::GetForBrowserContext(profile); |
620 DownloadHistory* download_history = | 620 DownloadHistory* download_history = |
621 (download_service ? download_service->GetDownloadHistory() : NULL); | 621 (download_core_service ? download_core_service->GetDownloadHistory() |
| 622 : nullptr); |
622 | 623 |
623 // The browser is only interested in new downloads. Ones that were restored | 624 // The browser is only interested in new downloads. Ones that were restored |
624 // from history are not displayed on the shelf. The downloads page | 625 // from history are not displayed on the shelf. The downloads page |
625 // independently listens for new downloads when it is active. Note that the UI | 626 // independently listens for new downloads when it is active. Note that the UI |
626 // will be notified of downloads even if they are not meant to be displayed on | 627 // will be notified of downloads even if they are not meant to be displayed on |
627 // the shelf (i.e. ShouldShowInShelf() returns false). This is because: | 628 // the shelf (i.e. ShouldShowInShelf() returns false). This is because: |
628 // * The shelf isn't the only UI. E.g. on Android, the UI is the system | 629 // * The shelf isn't the only UI. E.g. on Android, the UI is the system |
629 // DownloadManager. | 630 // DownloadManager. |
630 // * There are other UI activities that need to be performed. E.g. if the | 631 // * There are other UI activities that need to be performed. E.g. if the |
631 // download was initiated from a new tab, then that tab should be closed. | 632 // download was initiated from a new tab, then that tab should be closed. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // In progress download with no known time left and non-zero completed bytes: | 748 // In progress download with no known time left and non-zero completed bytes: |
748 // "100/120 MB" or "100 MB" | 749 // "100/120 MB" or "100 MB" |
749 if (GetCompletedBytes() > 0) | 750 if (GetCompletedBytes() > 0) |
750 return size_ratio; | 751 return size_ratio; |
751 | 752 |
752 // Instead of displaying "0 B" we say "Starting..." | 753 // Instead of displaying "0 B" we say "Starting..." |
753 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); | 754 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); |
754 } | 755 } |
755 | 756 |
756 void DownloadItemModel::OpenUsingPlatformHandler() { | 757 void DownloadItemModel::OpenUsingPlatformHandler() { |
757 DownloadService* download_service = | 758 DownloadCoreService* download_core_service = |
758 DownloadServiceFactory::GetForBrowserContext( | 759 DownloadCoreServiceFactory::GetForBrowserContext( |
759 download_->GetBrowserContext()); | 760 download_->GetBrowserContext()); |
760 if (!download_service) | 761 if (!download_core_service) |
761 return; | 762 return; |
762 | 763 |
763 ChromeDownloadManagerDelegate* delegate = | 764 ChromeDownloadManagerDelegate* delegate = |
764 download_service->GetDownloadManagerDelegate(); | 765 download_core_service->GetDownloadManagerDelegate(); |
765 if (!delegate) | 766 if (!delegate) |
766 return; | 767 return; |
767 delegate->OpenDownloadUsingPlatformHandler(download_); | 768 delegate->OpenDownloadUsingPlatformHandler(download_); |
768 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); | 769 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); |
769 } | 770 } |
OLD | NEW |