Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: chrome/browser/ntp_snippets/download_suggestions_provider.cc

Issue 2558743003: Add generic functions for getting typed variation parameter values (Closed)
Patch Set: Alexei's comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/offline_page_model_query.h" 25 #include "components/offline_pages/core/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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { 748 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() {
748 DCHECK_NE(download_manager_, nullptr); 749 DCHECK_NE(download_manager_, nullptr);
749 750
750 std::vector<DownloadItem*> all_downloads; 751 std::vector<DownloadItem*> all_downloads;
751 download_manager_->GetAllDownloads(&all_downloads); 752 download_manager_->GetAllDownloads(&all_downloads);
752 753
753 for (DownloadItem* item : all_downloads) { 754 for (DownloadItem* item : all_downloads) {
754 item->RemoveObserver(this); 755 item->RemoveObserver(this);
755 } 756 }
756 } 757 }
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/bookmarks/bookmark_suggestions_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698