OLD | NEW |
---|---|
(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" | |
fgorski
2016/05/03 04:43:07
nit: do you need this?
romax
2016/05/03 17:42:21
Done.
| |
10 #include "base/time/time.h" | |
11 | |
12 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; | |
13 | |
14 namespace offline_pages { | |
15 | |
16 namespace { | |
17 const char kBookmarkNamespace[] = "bookmark"; | |
18 const char kLastNNamespace[] = "last_n"; | |
19 } // namespace | |
20 | |
21 ClientPolicyController::ClientPolicyController() { | |
22 policies_.clear(); | |
23 // Manually defining client policies for bookmark and last_n. | |
24 policies_.insert(std::make_pair( | |
25 kBookmarkNamespace, | |
26 MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY, | |
27 base::TimeDelta::FromDays(7), kUnlimitedPages))); | |
28 policies_.insert(std::make_pair( | |
29 kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY, | |
30 base::TimeDelta::FromDays(2), 20))); | |
31 // Fallback policy. | |
32 policies_.insert(std::make_pair( | |
33 kDefaultNamespace, | |
34 MakePolicy(kDefaultNamespace, LifetimeType::TEMPORARY, | |
35 base::TimeDelta::FromDays(1), kUnlimitedPages))); | |
fgorski
2016/05/03 04:43:07
it should definitely not be unlimited by default i
romax
2016/05/03 17:42:21
changed to 10.
| |
36 } | |
37 | |
38 ClientPolicyController::~ClientPolicyController() {} | |
39 | |
40 // static | |
41 const OfflinePageClientPolicy ClientPolicyController::MakePolicy( | |
42 const std::string& name_space, | |
43 LifetimeType lifetime_type, | |
44 const base::TimeDelta& expire_period, | |
45 int page_limit) { | |
46 OfflinePageClientPolicy policy( | |
47 {name_space, {lifetime_type, expire_period, page_limit}}); | |
48 return policy; | |
49 } | |
50 | |
51 const OfflinePageClientPolicy& ClientPolicyController::GetPolicy( | |
52 const std::string& name_space) const { | |
53 const auto& iter = policies_.find(name_space); | |
54 if (iter != policies_.end()) | |
55 return iter->second; | |
56 // Fallback when the namespace isn't defined. | |
57 return policies_.at(kDefaultNamespace); | |
58 } | |
59 | |
60 } // namespace offline_pages | |
OLD | NEW |