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

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

Issue 2651233002: Enable download home by default (Closed)
Patch Set: rebase Created 3 years, 11 months 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
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"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return builder.Build(model->GetPolicyController()); 120 return builder.Build(model->GetPolicyController());
121 } 121 }
122 122
123 } // namespace 123 } // namespace
124 124
125 DownloadSuggestionsProvider::DownloadSuggestionsProvider( 125 DownloadSuggestionsProvider::DownloadSuggestionsProvider(
126 ContentSuggestionsProvider::Observer* observer, 126 ContentSuggestionsProvider::Observer* observer,
127 offline_pages::OfflinePageModel* offline_page_model, 127 offline_pages::OfflinePageModel* offline_page_model,
128 content::DownloadManager* download_manager, 128 content::DownloadManager* download_manager,
129 DownloadHistory* download_history, 129 DownloadHistory* download_history,
130 PrefService* pref_service, 130 PrefService* pref_service)
131 bool download_manager_ui_enabled)
132 : ContentSuggestionsProvider(observer), 131 : ContentSuggestionsProvider(observer),
133 category_status_(CategoryStatus::AVAILABLE_LOADING), 132 category_status_(CategoryStatus::AVAILABLE_LOADING),
134 provided_category_(Category::FromKnownCategory( 133 provided_category_(Category::FromKnownCategory(
135 ntp_snippets::KnownCategories::DOWNLOADS)), 134 ntp_snippets::KnownCategories::DOWNLOADS)),
136 offline_page_model_(offline_page_model), 135 offline_page_model_(offline_page_model),
137 download_manager_(download_manager), 136 download_manager_(download_manager),
138 download_history_(download_history), 137 download_history_(download_history),
139 pref_service_(pref_service), 138 pref_service_(pref_service),
140 download_manager_ui_enabled_(download_manager_ui_enabled),
141 is_asset_downloads_initialization_complete_(false), 139 is_asset_downloads_initialization_complete_(false),
142 weak_ptr_factory_(this) { 140 weak_ptr_factory_(this) {
143 observer->OnCategoryStatusChanged(this, provided_category_, category_status_); 141 observer->OnCategoryStatusChanged(this, provided_category_, category_status_);
144 142
145 DCHECK(offline_page_model_ || download_manager_); 143 DCHECK(offline_page_model_ || download_manager_);
146 if (offline_page_model_) { 144 if (offline_page_model_) {
147 offline_page_model_->AddObserver(this); 145 offline_page_model_->AddObserver(this);
148 } 146 }
149 147
150 if (download_manager_) { 148 if (download_manager_) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return category_status_; 183 return category_status_;
186 } 184 }
187 185
188 CategoryInfo DownloadSuggestionsProvider::GetCategoryInfo(Category category) { 186 CategoryInfo DownloadSuggestionsProvider::GetCategoryInfo(Category category) {
189 DCHECK_EQ(provided_category_, category); 187 DCHECK_EQ(provided_category_, category);
190 return CategoryInfo( 188 return CategoryInfo(
191 l10n_util::GetStringUTF16(IDS_NTP_DOWNLOAD_SUGGESTIONS_SECTION_HEADER), 189 l10n_util::GetStringUTF16(IDS_NTP_DOWNLOAD_SUGGESTIONS_SECTION_HEADER),
192 ntp_snippets::ContentSuggestionsCardLayout::MINIMAL_CARD, 190 ntp_snippets::ContentSuggestionsCardLayout::MINIMAL_CARD,
193 /*has_more_action=*/false, 191 /*has_more_action=*/false,
194 /*has_reload_action=*/false, 192 /*has_reload_action=*/false,
195 /*has_view_all_action=*/download_manager_ui_enabled_, 193 /*has_view_all_action=*/true,
196 /*show_if_empty=*/false, 194 /*show_if_empty=*/false,
197 l10n_util::GetStringUTF16(IDS_NTP_DOWNLOADS_SUGGESTIONS_SECTION_EMPTY)); 195 l10n_util::GetStringUTF16(IDS_NTP_DOWNLOADS_SUGGESTIONS_SECTION_EMPTY));
198 } 196 }
199 197
200 void DownloadSuggestionsProvider::DismissSuggestion( 198 void DownloadSuggestionsProvider::DismissSuggestion(
201 const ContentSuggestion::ID& suggestion_id) { 199 const ContentSuggestion::ID& suggestion_id) {
202 DCHECK_EQ(provided_category_, suggestion_id.category()); 200 DCHECK_EQ(provided_category_, suggestion_id.category());
203 std::set<std::string> dismissed_ids = 201 std::set<std::string> dismissed_ids =
204 ReadDismissedIDsFromPrefs(CorrespondsToOfflinePage(suggestion_id)); 202 ReadDismissedIDsFromPrefs(CorrespondsToOfflinePage(suggestion_id));
205 dismissed_ids.insert(suggestion_id.id_within_category()); 203 dismissed_ids.insert(suggestion_id.id_within_category());
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() { 810 void DownloadSuggestionsProvider::UnregisterDownloadItemObservers() {
813 DCHECK_NE(download_manager_, nullptr); 811 DCHECK_NE(download_manager_, nullptr);
814 812
815 std::vector<DownloadItem*> all_downloads; 813 std::vector<DownloadItem*> all_downloads;
816 download_manager_->GetAllDownloads(&all_downloads); 814 download_manager_->GetAllDownloads(&all_downloads);
817 815
818 for (DownloadItem* item : all_downloads) { 816 for (DownloadItem* item : all_downloads) {
819 item->RemoveObserver(this); 817 item->RemoveObserver(this);
820 } 818 }
821 } 819 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698