Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "components/ntp_snippets/pref_names.h" | 17 #include "components/ntp_snippets/pref_names.h" |
| 18 #include "components/ntp_snippets/pref_util.h" | 18 #include "components/ntp_snippets/pref_util.h" |
| 19 #include "components/offline_pages/client_namespace_constants.h" | 19 #include "components/offline_pages/client_namespace_constants.h" |
| 20 #include "components/offline_pages/client_policy_controller.h" | |
| 20 #include "components/prefs/pref_registry_simple.h" | 21 #include "components/prefs/pref_registry_simple.h" |
| 21 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 22 #include "grit/components_strings.h" | 23 #include "grit/components_strings.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 25 | 26 |
| 26 using offline_pages::MultipleOfflinePageItemResult; | 27 using offline_pages::MultipleOfflinePageItemResult; |
| 27 using offline_pages::OfflinePageModel; | 28 using offline_pages::OfflinePageModel; |
| 28 using offline_pages::OfflinePageItem; | 29 using offline_pages::OfflinePageItem; |
| 29 | 30 |
| 30 namespace ntp_snippets { | 31 namespace ntp_snippets { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 const int kMaxSuggestionsCount = 5; | 35 const int kMaxSuggestionsCount = 5; |
| 35 | 36 |
| 36 struct OrderByMostRecentlyVisited { | 37 struct OrderByMostRecentlyVisited { |
| 37 bool operator()(const OfflinePageItem* left, | 38 bool operator()(const OfflinePageItem* left, |
| 38 const OfflinePageItem* right) const { | 39 const OfflinePageItem* right) const { |
| 39 return left->last_access_time > right->last_access_time; | 40 return left->last_access_time > right->last_access_time; |
| 40 } | 41 } |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 bool IsRecentTab(const offline_pages::ClientId& client_id) { | 44 } // namespace |
| 45 | |
| 46 bool OfflinePageSuggestionsProvider::IsRecentTab( | |
| 47 const offline_pages::ClientId& client_id) { | |
| 44 return client_id.name_space == offline_pages::kLastNNamespace; | 48 return client_id.name_space == offline_pages::kLastNNamespace; |
| 45 } | 49 } |
| 46 | 50 |
| 47 bool IsDownload(const offline_pages::ClientId& client_id) { | 51 bool OfflinePageSuggestionsProvider::IsDownload( |
| 48 // TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that. | 52 const offline_pages::ClientId& client_id) { |
| 49 // The current logic is taken from DownloadUIAdapter::IsVisibleInUI. | 53 return offline_page_model_->GetPolicyController()->IsSupportedByDownload( |
|
romax
2016/10/04 17:50:34
sorry i remembered we had a discussion on this but
chili
2016/10/04 18:08:53
If it's static, we'd either
--- Get the OfflinePag
| |
| 50 return client_id.name_space == offline_pages::kAsyncNamespace && | 54 client_id.name_space) && |
| 51 base::IsValidGUID(client_id.id); | 55 base::IsValidGUID(client_id.id); |
| 52 } | 56 } |
| 53 | 57 |
| 54 } // namespace | |
| 55 | |
| 56 OfflinePageSuggestionsProvider::OfflinePageSuggestionsProvider( | 58 OfflinePageSuggestionsProvider::OfflinePageSuggestionsProvider( |
| 57 bool recent_tabs_enabled, | 59 bool recent_tabs_enabled, |
| 58 bool downloads_enabled, | 60 bool downloads_enabled, |
| 59 bool download_manager_ui_enabled, | 61 bool download_manager_ui_enabled, |
| 60 ContentSuggestionsProvider::Observer* observer, | 62 ContentSuggestionsProvider::Observer* observer, |
| 61 CategoryFactory* category_factory, | 63 CategoryFactory* category_factory, |
| 62 OfflinePageModel* offline_page_model, | 64 OfflinePageModel* offline_page_model, |
| 63 PrefService* pref_service) | 65 PrefService* pref_service) |
| 64 : ContentSuggestionsProvider(observer, category_factory), | 66 : ContentSuggestionsProvider(observer, category_factory), |
| 65 recent_tabs_status_(recent_tabs_enabled | 67 recent_tabs_status_(recent_tabs_enabled |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 } | 379 } |
| 378 | 380 |
| 379 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( | 381 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( |
| 380 Category category, | 382 Category category, |
| 381 const std::set<std::string>& dismissed_ids) { | 383 const std::set<std::string>& dismissed_ids) { |
| 382 prefs::StoreDismissedIDsToPrefs(pref_service_, GetDismissedPref(category), | 384 prefs::StoreDismissedIDsToPrefs(pref_service_, GetDismissedPref(category), |
| 383 dismissed_ids); | 385 dismissed_ids); |
| 384 } | 386 } |
| 385 | 387 |
| 386 } // namespace ntp_snippets | 388 } // namespace ntp_snippets |
| OLD | NEW |