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

Unified Diff: components/offline_pages/client_policy_controller.cc

Issue 2364253002: [Offline Pages] Adds new policy bits and reverse lookup. (Closed)
Patch Set: Rename. 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/client_policy_controller.cc
diff --git a/components/offline_pages/client_policy_controller.cc b/components/offline_pages/client_policy_controller.cc
index d66193350808e2f1baa03d228115013afa20eb3b..23772308ec9f5490ddc75e9ed79469a727f75a0c 100644
--- a/components/offline_pages/client_policy_controller.cc
+++ b/components/offline_pages/client_policy_controller.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "components/offline_pages/client_namespace_constants.h"
@@ -21,9 +22,13 @@ ClientPolicyController::ClientPolicyController() {
MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY,
base::TimeDelta::FromDays(7), kUnlimitedPages, 1)));
policies_.insert(std::make_pair(
- kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY,
- base::TimeDelta::FromDays(2), kUnlimitedPages,
- kUnlimitedPages)));
+ kLastNNamespace,
+ OfflinePageClientPolicyBuilder(kLastNNamespace, LifetimeType::TEMPORARY,
+ kUnlimitedPages, kUnlimitedPages)
+ .SetExpirePeriod(base::TimeDelta::FromDays(2))
+ .SetIsSupportedByRecentTabs(true)
+ .SetIsOnlyShownInOriginalTab(true)
+ .Build()));
policies_.insert(std::make_pair(
kAsyncNamespace,
OfflinePageClientPolicyBuilder(kAsyncNamespace, LifetimeType::PERSISTENT,
@@ -89,4 +94,55 @@ bool ClientPolicyController::IsSupportedByDownload(
return GetPolicy(name_space).feature_policy.is_supported_by_download;
}
+const std::vector<std::string>&
+ClientPolicyController::GetNamespacesSupportedByDownload() const {
+ if (download_namespace_cache_)
+ return *download_namespace_cache_;
+
+ download_namespace_cache_ = base::MakeUnique<std::vector<std::string>>();
+ for (const auto& policy_item : policies_) {
+ if (policy_item.second.feature_policy.is_supported_by_download)
+ download_namespace_cache_->emplace_back(policy_item.first);
+ }
+ return *download_namespace_cache_;
+}
+
+bool ClientPolicyController::IsShownAsRecentlyVisitedSite(
+ const std::string& name_space) const {
+ return GetPolicy(name_space).feature_policy.is_supported_by_recent_tabs;
+}
+
+const std::vector<std::string>&
+ClientPolicyController::GetNamespacesShownAsRecentlyVisitedSite() const {
+ if (recent_tab_namespace_cache_)
+ return *recent_tab_namespace_cache_;
+
+ recent_tab_namespace_cache_ = base::MakeUnique<std::vector<std::string>>();
+ for (const auto& policy_item : policies_) {
+ if (policy_item.second.feature_policy.is_supported_by_recent_tabs)
+ recent_tab_namespace_cache_->emplace_back(policy_item.first);
+ }
+
+ return *recent_tab_namespace_cache_;
+}
+
+bool ClientPolicyController::IsRestrictedToOriginalTab(
+ const std::string& name_space) const {
+ return GetPolicy(name_space).feature_policy.only_shown_in_original_tab;
+}
+
+const std::vector<std::string>&
+ClientPolicyController::GetNamespacesRestrictedToOriginalTab() const {
+ if (show_in_original_tab_cache_)
+ return *show_in_original_tab_cache_;
+
+ show_in_original_tab_cache_ = base::MakeUnique<std::vector<std::string>>();
+ for (const auto& policy_item : policies_) {
+ if (policy_item.second.feature_policy.only_shown_in_original_tab)
+ show_in_original_tab_cache_->emplace_back(policy_item.first);
+ }
+
+ return *show_in_original_tab_cache_;
+}
+
} // namespace offline_pages
« no previous file with comments | « components/offline_pages/client_policy_controller.h ('k') | components/offline_pages/client_policy_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698