| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp_snippets/download_suggestions_provider.h" | 5 #include "chrome/browser/ntp_snippets/download_suggestions_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "chrome/common/chrome_features.h" | 20 #include "chrome/common/chrome_features.h" |
| 21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/ntp_snippets/features.h" | 22 #include "components/ntp_snippets/features.h" |
| 23 #include "components/ntp_snippets/pref_names.h" | 23 #include "components/ntp_snippets/pref_names.h" |
| 24 #include "components/ntp_snippets/pref_util.h" | 24 #include "components/ntp_snippets/pref_util.h" |
| 25 #include "components/offline_pages/offline_page_model_query.h" | 25 #include "components/offline_pages/offline_page_model_query.h" |
| 26 #include "components/prefs/pref_registry_simple.h" | 26 #include "components/prefs/pref_registry_simple.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "components/variations/variations_associated_data.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
| 30 | 31 |
| 31 using content::DownloadItem; | 32 using content::DownloadItem; |
| 32 using content::DownloadManager; | 33 using content::DownloadManager; |
| 33 using ntp_snippets::Category; | 34 using ntp_snippets::Category; |
| 34 using ntp_snippets::CategoryInfo; | 35 using ntp_snippets::CategoryInfo; |
| 35 using ntp_snippets::CategoryStatus; | 36 using ntp_snippets::CategoryStatus; |
| 36 using ntp_snippets::ContentSuggestion; | 37 using ntp_snippets::ContentSuggestion; |
| 37 using ntp_snippets::prefs::kDismissedAssetDownloadSuggestions; | 38 using ntp_snippets::prefs::kDismissedAssetDownloadSuggestions; |
| 38 using ntp_snippets::prefs::kDismissedOfflinePageDownloadSuggestions; | 39 using ntp_snippets::prefs::kDismissedOfflinePageDownloadSuggestions; |
| 39 using offline_pages::OfflinePageItem; | 40 using offline_pages::OfflinePageItem; |
| 40 using offline_pages::OfflinePageModelQuery; | 41 using offline_pages::OfflinePageModelQuery; |
| 41 using offline_pages::OfflinePageModelQueryBuilder; | 42 using offline_pages::OfflinePageModelQueryBuilder; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 const int kDefaultMaxSuggestionsCount = 5; | 46 const int kDefaultMaxSuggestionsCount = 5; |
| 46 const char kAssetDownloadsPrefix = 'D'; | 47 const char kAssetDownloadsPrefix = 'D'; |
| 47 const char kOfflinePageDownloadsPrefix = 'O'; | 48 const char kOfflinePageDownloadsPrefix = 'O'; |
| 48 | 49 |
| 49 const char* kMaxSuggestionsCountParamName = "downloads_max_count"; | 50 const char* kMaxSuggestionsCountParamName = "downloads_max_count"; |
| 50 | 51 |
| 51 int GetMaxSuggestionsCount() { | 52 int GetMaxSuggestionsCount() { |
| 52 bool assets_enabled = | 53 bool assets_enabled = |
| 53 base::FeatureList::IsEnabled(features::kAssetDownloadSuggestionsFeature); | 54 base::FeatureList::IsEnabled(features::kAssetDownloadSuggestionsFeature); |
| 54 return ntp_snippets::GetParamAsInt( | 55 return variations::GetVariationParamByFeatureAsInt( |
| 55 assets_enabled ? features::kAssetDownloadSuggestionsFeature | 56 assets_enabled ? features::kAssetDownloadSuggestionsFeature |
| 56 : features::kOfflinePageDownloadSuggestionsFeature, | 57 : features::kOfflinePageDownloadSuggestionsFeature, |
| 57 kMaxSuggestionsCountParamName, kDefaultMaxSuggestionsCount); | 58 kMaxSuggestionsCountParamName, kDefaultMaxSuggestionsCount); |
| 58 } | 59 } |
| 59 | 60 |
| 60 std::string GetOfflinePagePerCategoryID(int64_t raw_offline_page_id) { | 61 std::string GetOfflinePagePerCategoryID(int64_t raw_offline_page_id) { |
| 61 // Raw ID is prefixed in order to avoid conflicts with asset downloads. | 62 // Raw ID is prefixed in order to avoid conflicts with asset downloads. |
| 62 return std::string(1, kOfflinePageDownloadsPrefix) + | 63 return std::string(1, kOfflinePageDownloadsPrefix) + |
| 63 base::IntToString(raw_offline_page_id); | 64 base::IntToString(raw_offline_page_id); |
| 64 } | 65 } |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { | 746 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { |
| 746 DCHECK_NE(download_manager_, nullptr); | 747 DCHECK_NE(download_manager_, nullptr); |
| 747 | 748 |
| 748 std::vector<DownloadItem*> all_downloads; | 749 std::vector<DownloadItem*> all_downloads; |
| 749 download_manager_->GetAllDownloads(&all_downloads); | 750 download_manager_->GetAllDownloads(&all_downloads); |
| 750 | 751 |
| 751 for (DownloadItem* item : all_downloads) { | 752 for (DownloadItem* item : all_downloads) { |
| 752 item->RemoveObserver(this); | 753 item->RemoveObserver(this); |
| 753 } | 754 } |
| 754 } | 755 } |
| OLD | NEW |