Chromium Code Reviews| 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..7d643c274e14da571a40c331ce16393ae3d7a430 |
| --- /dev/null |
| +++ b/components/offline_pages/client_policy_controller.cc |
| @@ -0,0 +1,60 @@ |
| +// 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" |
|
fgorski
2016/05/03 04:43:07
nit: do you need this?
romax
2016/05/03 17:42:21
Done.
|
| +#include "base/time/time.h" |
| + |
| +using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; |
| + |
| +namespace offline_pages { |
| + |
| +namespace { |
| +const char kBookmarkNamespace[] = "bookmark"; |
| +const char kLastNNamespace[] = "last_n"; |
| +} // namespace |
| + |
| +ClientPolicyController::ClientPolicyController() { |
| + policies_.clear(); |
| + // Manually defining client policies for bookmark and last_n. |
| + policies_.insert(std::make_pair( |
| + kBookmarkNamespace, |
| + MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY, |
| + base::TimeDelta::FromDays(7), kUnlimitedPages))); |
| + policies_.insert(std::make_pair( |
| + kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY, |
| + base::TimeDelta::FromDays(2), 20))); |
| + // Fallback policy. |
| + policies_.insert(std::make_pair( |
| + kDefaultNamespace, |
| + MakePolicy(kDefaultNamespace, LifetimeType::TEMPORARY, |
| + 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.
|
| +} |
| + |
| +ClientPolicyController::~ClientPolicyController() {} |
| + |
| +// 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 { |
| + const auto& iter = policies_.find(name_space); |
| + if (iter != policies_.end()) |
| + return iter->second; |
| + // Fallback when the namespace isn't defined. |
| + return policies_.at(kDefaultNamespace); |
| +} |
| + |
| +} // namespace offline_pages |