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