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

Unified Diff: components/offline_pages/client_policy_controller.cc

Issue 1934743003: Implementing client policy and controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 8 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
new file mode 100644
index 0000000000000000000000000000000000000000..cc3209c2988921dd7e6df321bb06c5638bda96bd
--- /dev/null
+++ b/components/offline_pages/client_policy_controller.cc
@@ -0,0 +1,58 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/offline_pages/client_policy_controller.h"
+
+#include <utility>
+
+#include "base/time/time.h"
+
+using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
+
+namespace offline_pages {
+
+namespace {
+const char kBookmarkNamespace[] = "bookmark";
+const char kLastNNamespace[] = "last_n";
+} // namespace
+
+ClientPolicyController::ClientPolicyController() {
+ policies_.clear();
+ // Manually defining client policies for bookmark and last_n.
+ policies_.insert(std::make_pair(
+ kBookmarkNamespace,
+ MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY,
+ base::TimeDelta::FromDays(7), kUnlimitedPages)));
+ policies_.insert(std::make_pair(
+ kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY,
+ base::TimeDelta::FromDays(2), 20)));
+ // Fallback policy.
+ policies_.insert(std::make_pair(
+ kDefaultNamespace, MakePolicy(kDefaultNamespace, LifetimeType::TEMPORARY,
+ base::TimeDelta::FromDays(1), 10)));
+}
+
+ClientPolicyController::~ClientPolicyController() {}
+
+// static
+const OfflinePageClientPolicy ClientPolicyController::MakePolicy(
+ const std::string& name_space,
+ LifetimeType lifetime_type,
+ const base::TimeDelta& expire_period,
+ int page_limit) {
+ OfflinePageClientPolicy policy(
+ {name_space, {lifetime_type, expire_period, page_limit}});
+ return policy;
+}
+
+const OfflinePageClientPolicy& ClientPolicyController::GetPolicy(
+ const std::string& name_space) const {
+ const auto& iter = policies_.find(name_space);
+ if (iter != policies_.end())
+ return iter->second;
+ // Fallback when the namespace isn't defined.
+ return policies_.at(kDefaultNamespace);
+}
+
+} // 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