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

Side by Side Diff: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc

Issue 2342443006: [Offline pages] Use the new policy bits (Closed)
Patch Set: code review update Created 4 years, 3 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 "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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/ntp_snippets/pref_names.h" 16 #include "components/ntp_snippets/pref_names.h"
17 #include "components/offline_pages/client_namespace_constants.h" 17 #include "components/offline_pages/client_namespace_constants.h"
18 #include "components/offline_pages/client_policy_controller.h"
18 #include "components/prefs/pref_registry_simple.h" 19 #include "components/prefs/pref_registry_simple.h"
19 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
20 #include "grit/components_strings.h" 21 #include "grit/components_strings.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
23 24
24 using offline_pages::MultipleOfflinePageItemResult; 25 using offline_pages::MultipleOfflinePageItemResult;
25 using offline_pages::OfflinePageModel; 26 using offline_pages::OfflinePageModel;
26 using offline_pages::OfflinePageItem; 27 using offline_pages::OfflinePageItem;
27 28
28 namespace ntp_snippets { 29 namespace ntp_snippets {
29 30
30 namespace { 31 namespace {
31 32
32 const int kMaxSuggestionsCount = 5; 33 const int kMaxSuggestionsCount = 5;
33 34
34 struct OrderByMostRecentlyVisited { 35 struct OrderByMostRecentlyVisited {
35 bool operator()(const OfflinePageItem* left, 36 bool operator()(const OfflinePageItem* left,
36 const OfflinePageItem* right) const { 37 const OfflinePageItem* right) const {
37 return left->last_access_time > right->last_access_time; 38 return left->last_access_time > right->last_access_time;
38 } 39 }
39 }; 40 };
40 41
41 bool IsRecentTab(const offline_pages::ClientId& client_id) { 42 bool IsRecentTab(const offline_pages::ClientId& client_id) {
42 return client_id.name_space == offline_pages::kLastNNamespace; 43 return client_id.name_space == offline_pages::kLastNNamespace;
43 } 44 }
44 45
45 bool IsDownload(const offline_pages::ClientId& client_id) { 46 bool IsDownload(const offline_pages::ClientId& client_id) {
46 // TODO(pke): Use kDownloadNamespace once the OfflinePageModel uses that. 47 return offline_pages::ClientPolicyController().IsSupportedByDownload(
Dmitry Titov 2016/09/20 18:51:55 This is unorthodox way to use a constructor. A bet
47 // The current logic is taken from DownloadUIAdapter::IsVisibleInUI. 48 client_id.name_space) &&
48 return client_id.name_space == offline_pages::kAsyncNamespace &&
49 base::IsValidGUID(client_id.id); 49 base::IsValidGUID(client_id.id);
50 } 50 }
51 51
52 } // namespace 52 } // namespace
53 53
54 OfflinePageSuggestionsProvider::OfflinePageSuggestionsProvider( 54 OfflinePageSuggestionsProvider::OfflinePageSuggestionsProvider(
55 bool recent_tabs_enabled, 55 bool recent_tabs_enabled,
56 bool downloads_enabled, 56 bool downloads_enabled,
57 bool download_manager_ui_enabled, 57 bool download_manager_ui_enabled,
58 ContentSuggestionsProvider::Observer* observer, 58 ContentSuggestionsProvider::Observer* observer,
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( 385 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs(
386 Category category, 386 Category category,
387 const std::set<std::string>& dismissed_ids) { 387 const std::set<std::string>& dismissed_ids) {
388 base::ListValue list; 388 base::ListValue list;
389 for (const std::string& dismissed_id : dismissed_ids) 389 for (const std::string& dismissed_id : dismissed_ids)
390 list.AppendString(dismissed_id); 390 list.AppendString(dismissed_id);
391 pref_service_->Set(GetDismissedPref(category), list); 391 pref_service_->Set(GetDismissedPref(category), list);
392 } 392 }
393 393
394 } // namespace ntp_snippets 394 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698