| 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/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 16 #include "chrome/browser/download/download_crx_util.h" | 17 #include "chrome/browser/download/download_crx_util.h" |
| 17 #include "chrome/browser/download/download_history.h" | 18 #include "chrome/browser/download/download_history.h" |
| 18 #include "chrome/browser/download/download_service.h" | 19 #include "chrome/browser/download/download_service.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 37 using content::DownloadItem; | 38 using content::DownloadItem; |
| 38 using safe_browsing::DownloadFileType; | 39 using safe_browsing::DownloadFileType; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // Per DownloadItem data used by DownloadItemModel. The model doesn't keep any | 43 // Per DownloadItem data used by DownloadItemModel. The model doesn't keep any |
| 43 // state since there could be multiple models associated with a single | 44 // state since there could be multiple models associated with a single |
| 44 // DownloadItem, and the lifetime of the model is shorter than the DownloadItem. | 45 // DownloadItem, and the lifetime of the model is shorter than the DownloadItem. |
| 45 class DownloadItemModelData : public base::SupportsUserData::Data { | 46 class DownloadItemModelData : public base::SupportsUserData::Data { |
| 46 public: | 47 public: |
| 48 ~DownloadItemModelData() override {} |
| 49 |
| 47 // Get the DownloadItemModelData object for |download|. Returns NULL if | 50 // Get the DownloadItemModelData object for |download|. Returns NULL if |
| 48 // there's no model data. | 51 // there's no model data. |
| 49 static const DownloadItemModelData* Get(const DownloadItem* download); | 52 static const DownloadItemModelData* Get(const DownloadItem* download); |
| 50 | 53 |
| 51 // Get the DownloadItemModelData object for |download|. Creates a model data | 54 // Get the DownloadItemModelData object for |download|. Creates a model data |
| 52 // object if not found. Always returns a non-NULL pointer, unless OOM. | 55 // object if not found. Always returns a non-NULL pointer, unless OOM. |
| 53 static DownloadItemModelData* GetOrCreate(DownloadItem* download); | 56 static DownloadItemModelData* GetOrCreate(DownloadItem* download); |
| 54 | 57 |
| 55 // Whether the download should be displayed in the download shelf. True by | 58 // Whether the download should be displayed in the download shelf. True by |
| 56 // default. | 59 // default. |
| 57 bool should_show_in_shelf_; | 60 bool should_show_in_shelf_; |
| 58 | 61 |
| 59 // Whether the UI has been notified about this download. | 62 // Whether the UI has been notified about this download. |
| 60 bool was_ui_notified_; | 63 bool was_ui_notified_; |
| 61 | 64 |
| 62 // Whether the download should be opened in the browser vs. the system handler | 65 // Whether the download should be opened in the browser vs. the system handler |
| 63 // for the file type. | 66 // for the file type. |
| 64 bool should_prefer_opening_in_browser_; | 67 bool should_prefer_opening_in_browser_; |
| 65 | 68 |
| 66 // Danger level of the file determined based on the file type and whether | 69 // Danger level of the file determined based on the file type and whether |
| 67 // there was a user action associated with the download. | 70 // there was a user action associated with the download. |
| 68 DownloadFileType::DangerLevel danger_level_; | 71 DownloadFileType::DangerLevel danger_level_; |
| 69 | 72 |
| 70 // Whether the download is currently being revived. | 73 // Whether the download is currently being revived. |
| 71 bool is_being_revived_; | 74 bool is_being_revived_; |
| 72 | 75 |
| 73 private: | 76 private: |
| 74 DownloadItemModelData(); | 77 DownloadItemModelData(); |
| 75 ~DownloadItemModelData() override {} | |
| 76 | 78 |
| 77 static const char kKey[]; | 79 static const char kKey[]; |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 // static | 82 // static |
| 81 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key"; | 83 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key"; |
| 82 | 84 |
| 83 // static | 85 // static |
| 84 const DownloadItemModelData* DownloadItemModelData::Get( | 86 const DownloadItemModelData* DownloadItemModelData::Get( |
| 85 const DownloadItem* download) { | 87 const DownloadItem* download) { |
| 86 return static_cast<const DownloadItemModelData*>(download->GetUserData(kKey)); | 88 return static_cast<const DownloadItemModelData*>(download->GetUserData(kKey)); |
| 87 } | 89 } |
| 88 | 90 |
| 89 // static | 91 // static |
| 90 DownloadItemModelData* DownloadItemModelData::GetOrCreate( | 92 DownloadItemModelData* DownloadItemModelData::GetOrCreate( |
| 91 DownloadItem* download) { | 93 DownloadItem* download) { |
| 92 DownloadItemModelData* data = | 94 DownloadItemModelData* data = |
| 93 static_cast<DownloadItemModelData*>(download->GetUserData(kKey)); | 95 static_cast<DownloadItemModelData*>(download->GetUserData(kKey)); |
| 94 if (data == NULL) { | 96 if (data == NULL) { |
| 95 data = new DownloadItemModelData(); | 97 data = new DownloadItemModelData(); |
| 96 data->should_show_in_shelf_ = !download->IsTransient(); | 98 data->should_show_in_shelf_ = !download->IsTransient(); |
| 97 download->SetUserData(kKey, data); | 99 download->SetUserData(kKey, base::WrapUnique(data)); |
| 98 } | 100 } |
| 99 return data; | 101 return data; |
| 100 } | 102 } |
| 101 | 103 |
| 102 DownloadItemModelData::DownloadItemModelData() | 104 DownloadItemModelData::DownloadItemModelData() |
| 103 : should_show_in_shelf_(true), | 105 : should_show_in_shelf_(true), |
| 104 was_ui_notified_(false), | 106 was_ui_notified_(false), |
| 105 should_prefer_opening_in_browser_(false), | 107 should_prefer_opening_in_browser_(false), |
| 106 danger_level_(DownloadFileType::NOT_DANGEROUS), | 108 danger_level_(DownloadFileType::NOT_DANGEROUS), |
| 107 is_being_revived_(false) {} | 109 is_being_revived_(false) {} |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 if (!download_service) | 760 if (!download_service) |
| 759 return; | 761 return; |
| 760 | 762 |
| 761 ChromeDownloadManagerDelegate* delegate = | 763 ChromeDownloadManagerDelegate* delegate = |
| 762 download_service->GetDownloadManagerDelegate(); | 764 download_service->GetDownloadManagerDelegate(); |
| 763 if (!delegate) | 765 if (!delegate) |
| 764 return; | 766 return; |
| 765 delegate->OpenDownloadUsingPlatformHandler(download_); | 767 delegate->OpenDownloadUsingPlatformHandler(download_); |
| 766 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); | 768 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); |
| 767 } | 769 } |
| OLD | NEW |