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 "components/ntp_snippets/offline_pages/offline_page_suggestions_provide
r.h" | 5 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide
r.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 downloads_status_(downloads_enabled ? CategoryStatus::AVAILABLE_LOADING | 55 downloads_status_(downloads_enabled ? CategoryStatus::AVAILABLE_LOADING |
56 : CategoryStatus::NOT_PROVIDED), | 56 : CategoryStatus::NOT_PROVIDED), |
57 offline_page_model_(offline_page_model), | 57 offline_page_model_(offline_page_model), |
58 recent_tabs_category_( | 58 recent_tabs_category_( |
59 category_factory->FromKnownCategory(KnownCategories::RECENT_TABS)), | 59 category_factory->FromKnownCategory(KnownCategories::RECENT_TABS)), |
60 downloads_category_( | 60 downloads_category_( |
61 category_factory->FromKnownCategory(KnownCategories::DOWNLOADS)), | 61 category_factory->FromKnownCategory(KnownCategories::DOWNLOADS)), |
62 pref_service_(pref_service), | 62 pref_service_(pref_service), |
63 download_manager_ui_enabled_(download_manager_ui_enabled) { | 63 download_manager_ui_enabled_(download_manager_ui_enabled) { |
64 DCHECK(recent_tabs_enabled || downloads_enabled); | 64 DCHECK(recent_tabs_enabled || downloads_enabled); |
| 65 if (recent_tabs_enabled) { |
| 66 observer->OnCategoryStatusChanged(this, recent_tabs_category_, |
| 67 recent_tabs_status_); |
| 68 } |
| 69 if (downloads_enabled) { |
| 70 observer->OnCategoryStatusChanged(this, downloads_category_, |
| 71 downloads_status_); |
| 72 } |
65 offline_page_model_->AddObserver(this); | 73 offline_page_model_->AddObserver(this); |
66 FetchOfflinePages(); | 74 FetchOfflinePages(); |
67 } | 75 } |
68 | 76 |
69 OfflinePageSuggestionsProvider::~OfflinePageSuggestionsProvider() { | 77 OfflinePageSuggestionsProvider::~OfflinePageSuggestionsProvider() { |
70 offline_page_model_->RemoveObserver(this); | 78 offline_page_model_->RemoveObserver(this); |
71 } | 79 } |
72 | 80 |
73 // static | 81 // static |
74 void OfflinePageSuggestionsProvider::RegisterProfilePrefs( | 82 void OfflinePageSuggestionsProvider::RegisterProfilePrefs( |
75 PrefRegistrySimple* registry) { | 83 PrefRegistrySimple* registry) { |
76 registry->RegisterListPref(prefs::kDismissedRecentOfflineTabSuggestions); | 84 registry->RegisterListPref(prefs::kDismissedRecentOfflineTabSuggestions); |
77 registry->RegisterListPref(prefs::kDismissedDownloadSuggestions); | 85 registry->RegisterListPref(prefs::kDismissedDownloadSuggestions); |
78 } | 86 } |
79 | 87 |
80 //////////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////////// |
81 // Private methods | 89 // Private methods |
82 | 90 |
83 std::vector<Category> OfflinePageSuggestionsProvider::GetProvidedCategories() { | |
84 std::vector<Category> provided_categories; | |
85 if (recent_tabs_status_ != CategoryStatus::NOT_PROVIDED) | |
86 provided_categories.push_back(recent_tabs_category_); | |
87 if (downloads_status_ != CategoryStatus::NOT_PROVIDED) | |
88 provided_categories.push_back(downloads_category_); | |
89 return provided_categories; | |
90 } | |
91 | |
92 CategoryStatus OfflinePageSuggestionsProvider::GetCategoryStatus( | 91 CategoryStatus OfflinePageSuggestionsProvider::GetCategoryStatus( |
93 Category category) { | 92 Category category) { |
94 if (category == recent_tabs_category_) | 93 if (category == recent_tabs_category_) |
95 return recent_tabs_status_; | 94 return recent_tabs_status_; |
96 if (category == downloads_category_) | 95 if (category == downloads_category_) |
97 return downloads_status_; | 96 return downloads_status_; |
98 NOTREACHED() << "Unknown category " << category.id(); | 97 NOTREACHED() << "Unknown category " << category.id(); |
99 return CategoryStatus::NOT_PROVIDED; | 98 return CategoryStatus::NOT_PROVIDED; |
100 } | 99 } |
101 | 100 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( | 363 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( |
365 Category category, | 364 Category category, |
366 const std::set<std::string>& dismissed_ids) { | 365 const std::set<std::string>& dismissed_ids) { |
367 base::ListValue list; | 366 base::ListValue list; |
368 for (const std::string& dismissed_id : dismissed_ids) | 367 for (const std::string& dismissed_id : dismissed_ids) |
369 list.AppendString(dismissed_id); | 368 list.AppendString(dismissed_id); |
370 pref_service_->Set(GetDismissedPref(category), list); | 369 pref_service_->Set(GetDismissedPref(category), list); |
371 } | 370 } |
372 | 371 |
373 } // namespace ntp_snippets | 372 } // namespace ntp_snippets |
OLD | NEW |