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

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..a5255a7eeff4437228996bcd5f9051100d2e65e6
--- /dev/null
+++ b/components/offline_pages/client_policy_controller.cc
@@ -0,0 +1,62 @@
+// 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/logging.h"
+#include "base/time/time.h"
+
+using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
+
+namespace offline_pages {
+
+ClientPolicyController* ClientPolicyController::controller_ = nullptr;
+
+ClientPolicyController::ClientPolicyController() {
+ policies_.clear();
+// TODO(romax) Make here somehow more clever.
fgorski 2016/05/02 23:10:31 Don't! Make it as clear as you can.
romax 2016/05/03 00:29:24 Done.
+// Using macros to insert predefined client policies in client_policies.h.
fgorski 2016/05/02 23:10:31 Don't. Code it by hand, it will be replaced by exp
romax 2016/05/03 00:29:24 Done.
+#undef POLICY
+#define POLICY(name_space, type, expire, limit) \
+ policies_.insert(std::make_pair( \
+ #name_space, MakePolicy(#name_space, LifetimeType::type, \
+ base::TimeDelta::FromDays(expire), limit)));
+
+#include "components/offline_pages/client_policies.h"
+ CLIENT_POLICIES
+#undef POLICY
+#undef CLIENT_POLICIES
+}
+
+ClientPolicyController::~ClientPolicyController() {}
+
+// static
+ClientPolicyController* ClientPolicyController::GetInstance() {
+ return controller_ ? controller_
+ : base::Singleton<ClientPolicyController>::get();
+}
+
+// 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 auto& iter = policies_.find(name_space);
+ if (iter != policies_.end())
+ return iter->second;
+ // Fallback when the namespace isn't defined.
+ return policies_.at(kDefaultPolicy);
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698