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

Side by Side 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, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/offline_pages/client_policy_controller.h"
6
7 #include <utility>
8
9 #include "base/logging.h"
10 #include "base/time/time.h"
11
12 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType;
13
14 namespace offline_pages {
15
16 ClientPolicyController* ClientPolicyController::controller_ = nullptr;
17
18 ClientPolicyController::ClientPolicyController() {
19 policies_.clear();
20 // 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.
21 // 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.
22 #undef POLICY
23 #define POLICY(name_space, type, expire, limit) \
24 policies_.insert(std::make_pair( \
25 #name_space, MakePolicy(#name_space, LifetimeType::type, \
26 base::TimeDelta::FromDays(expire), limit)));
27
28 #include "components/offline_pages/client_policies.h"
29 CLIENT_POLICIES
30 #undef POLICY
31 #undef CLIENT_POLICIES
32 }
33
34 ClientPolicyController::~ClientPolicyController() {}
35
36 // static
37 ClientPolicyController* ClientPolicyController::GetInstance() {
38 return controller_ ? controller_
39 : base::Singleton<ClientPolicyController>::get();
40 }
41
42 // static
43 const OfflinePageClientPolicy ClientPolicyController::MakePolicy(
44 const std::string& name_space,
45 LifetimeType lifetime_type,
46 const base::TimeDelta& expire_period,
47 int page_limit) {
48 OfflinePageClientPolicy policy(
49 {name_space, {lifetime_type, expire_period, page_limit}});
50 return policy;
51 }
52
53 const OfflinePageClientPolicy& ClientPolicyController::GetPolicy(
54 const std::string& name_space) {
55 const auto& iter = policies_.find(name_space);
56 if (iter != policies_.end())
57 return iter->second;
58 // Fallback when the namespace isn't defined.
59 return policies_.at(kDefaultPolicy);
60 }
61
62 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698