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

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: Fixing build errors. 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..c203fd9eee1bf0cc53401da183297477706eecf0
--- /dev/null
+++ b/components/offline_pages/client_policy_controller.cc
@@ -0,0 +1,54 @@
+// 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 {
+ OfflinePageClientPolicy TranslateToPolicy(
fgorski 2016/04/30 17:42:25 fix indentation. (git cl format should align this
fgorski 2016/04/30 17:42:25 MakePolicy is a better name Also you could make i
romax 2016/05/02 20:33:44 Done.
+ std::string name_space,
fgorski 2016/04/30 17:42:24 const ref
romax 2016/05/02 20:33:44 Done.
+ LifetimeType lifetime_type,
+ base::TimeDelta expire_period,
fgorski 2016/04/30 17:42:25 const ref
romax 2016/05/02 20:33:44 Done.
+ int64_t page_limit) {
+ return {name_space, {lifetime_type, expire_period, page_limit}};
+ }
+}
+
+ClientPolicyController& ClientPolicyController::GetInstance() {
+ static ClientPolicyController instance;
+ return instance;
+}
+
+OfflinePageClientPolicy ClientPolicyController::GetPolicy(
+ std::string name_space) {
+ const auto& iter = policies_.find(name_space);
+ if (iter != policies_.end()) {
fgorski 2016/04/30 17:42:25 braces not needed.
romax 2016/05/02 20:33:44 Done.
+ return iter->second;
+ }
+ // Fallback when the namespace isn't defined.
+ return kDefaultClientPolicy;
+}
+
+ClientPolicyController::ClientPolicyController() {
+ policies_.clear();
+ // TODO(romax) Make here somehow more clever.
+ policies_.insert(std::make_pair("bookmark",
fgorski 2016/04/30 17:42:25 you should be referring to a const here. and below
romax 2016/05/02 20:33:44 Acknowledged.
+ TranslateToPolicy("bookmark", LifetimeType::TEMPORARY,
+ base::TimeDelta::FromDays(7), kUnlimitedPage)));
+ policies_.insert(std::make_pair("last_n",
+ TranslateToPolicy("last_n", LifetimeType::TEMPORARY,
+ base::TimeDelta::FromDays(2), 20)));
+}
+
+ClientPolicyController::~ClientPolicyController() {
fgorski 2016/04/30 17:42:25 Order of methods should be: ctor dtor static insta
romax 2016/05/02 20:33:44 Done.
+}
+
+} // namespace offline_pages

Powered by Google App Engine
This is Rietveld 408576698