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

Side by Side Diff: components/offline_pages/client_policy_controller.cc

Issue 2364253002: [Offline Pages] Adds new policy bits and reverse lookup. (Closed)
Patch Set: Construction order. Created 4 years, 2 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/offline_pages/client_policy_controller.h" 5 #include "components/offline_pages/client_policy_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 #include "components/offline_pages/client_namespace_constants.h" 11 #include "components/offline_pages/client_namespace_constants.h"
11 12
12 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; 13 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
13 14
14 namespace offline_pages { 15 namespace offline_pages {
15 16
16 ClientPolicyController::ClientPolicyController() { 17 ClientPolicyController::ClientPolicyController() {
17 policies_.clear(); 18 policies_.clear();
18 // Manually defining client policies for bookmark and last_n. 19 // Manually defining client policies for bookmark and last_n.
19 policies_.insert(std::make_pair( 20 policies_.insert(std::make_pair(
20 kBookmarkNamespace, 21 kBookmarkNamespace,
21 MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY, 22 MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY,
22 base::TimeDelta::FromDays(7), kUnlimitedPages, 1))); 23 base::TimeDelta::FromDays(7), kUnlimitedPages, 1)));
23 policies_.insert(std::make_pair( 24 policies_.insert(std::make_pair(
24 kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY, 25 kLastNNamespace,
25 base::TimeDelta::FromDays(2), kUnlimitedPages, 26 OfflinePageClientPolicyBuilder(kLastNNamespace, LifetimeType::TEMPORARY,
26 kUnlimitedPages))); 27 kUnlimitedPages, kUnlimitedPages)
28 .SetExpirePeriod(base::TimeDelta::FromDays(2))
29 .SetIsSupportedByRecentTabs(true)
Dmitry Titov 2016/09/24 00:09:29 This set of bits looks conflicting? If we only can
dewittj 2016/09/26 23:00:31 These are not strictly conflicting. Imagine if we
30 .SetIsOnlyShownInOriginalTab(true)
31 .Build()));
27 policies_.insert(std::make_pair( 32 policies_.insert(std::make_pair(
28 kAsyncNamespace, 33 kAsyncNamespace,
29 OfflinePageClientPolicyBuilder(kAsyncNamespace, LifetimeType::PERSISTENT, 34 OfflinePageClientPolicyBuilder(kAsyncNamespace, LifetimeType::PERSISTENT,
30 kUnlimitedPages, kUnlimitedPages) 35 kUnlimitedPages, kUnlimitedPages)
31 .SetIsSupportedByDownload(true) 36 .SetIsSupportedByDownload(true)
32 .SetIsRemovedOnCacheReset(false) 37 .SetIsRemovedOnCacheReset(false)
33 .Build())); 38 .Build()));
34 policies_.insert(std::make_pair( 39 policies_.insert(std::make_pair(
35 kCCTNamespace, 40 kCCTNamespace,
36 MakePolicy(kCCTNamespace, LifetimeType::TEMPORARY, 41 MakePolicy(kCCTNamespace, LifetimeType::TEMPORARY,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 bool ClientPolicyController::IsRemovedOnCacheReset( 87 bool ClientPolicyController::IsRemovedOnCacheReset(
83 const std::string& name_space) const { 88 const std::string& name_space) const {
84 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset; 89 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset;
85 } 90 }
86 91
87 bool ClientPolicyController::IsSupportedByDownload( 92 bool ClientPolicyController::IsSupportedByDownload(
88 const std::string& name_space) const { 93 const std::string& name_space) const {
89 return GetPolicy(name_space).feature_policy.is_supported_by_download; 94 return GetPolicy(name_space).feature_policy.is_supported_by_download;
90 } 95 }
91 96
97 const std::vector<std::string>&
98 ClientPolicyController::GetNamespacesWithDownloadSupport() {
99 if (download_namespace_cache_)
100 return *download_namespace_cache_;
101
102 download_namespace_cache_ = base::MakeUnique<std::vector<std::string>>();
103 for (const auto& policy_item : policies_) {
104 if (policy_item.second.feature_policy.is_supported_by_download)
105 download_namespace_cache_->emplace_back(policy_item.first);
106 }
107 return *download_namespace_cache_;
108 }
109
110 bool ClientPolicyController::IsRecentTab(const std::string& name_space) const {
111 return GetPolicy(name_space).feature_policy.is_supported_by_recent_tabs;
112 }
113
114 const std::vector<std::string>&
115 ClientPolicyController::GetNamespacesForRecentTabs() {
116 if (recent_tab_namespace_cache_)
117 return *recent_tab_namespace_cache_;
118
119 recent_tab_namespace_cache_ = base::MakeUnique<std::vector<std::string>>();
120 for (const auto& policy_item : policies_) {
121 if (policy_item.second.feature_policy.is_supported_by_recent_tabs)
122 recent_tab_namespace_cache_->emplace_back(policy_item.first);
123 }
124
125 return *recent_tab_namespace_cache_;
126 }
127
128 bool ClientPolicyController::ShouldOnlyBeShownInOriginalTab(
129 const std::string& name_space) const {
130 return GetPolicy(name_space).feature_policy.only_shown_in_original_tab;
131 }
132
133 const std::vector<std::string>&
134 ClientPolicyController::GetNamespacesToShowInOriginalTab() {
135 if (show_in_original_tab_cache_)
136 return *show_in_original_tab_cache_;
137
138 show_in_original_tab_cache_ = base::MakeUnique<std::vector<std::string>>();
139 for (const auto& policy_item : policies_) {
140 if (policy_item.second.feature_policy.only_shown_in_original_tab)
141 show_in_original_tab_cache_->emplace_back(policy_item.first);
142 }
143
144 return *show_in_original_tab_cache_;
145 }
146
92 } // namespace offline_pages 147 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698