Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/offline_pages/client_policy_controller.h" | 5 #include "components/offline_pages/client_policy_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "components/offline_pages/client_namespace_constants.h" | 10 #include "components/offline_pages/client_namespace_constants.h" |
| 11 | 11 |
| 12 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; | 12 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; |
| 13 | 13 |
| 14 namespace offline_pages { | 14 namespace offline_pages { |
| 15 | 15 |
| 16 ClientPolicyController::ClientPolicyController() { | 16 ClientPolicyController::ClientPolicyController() { |
| 17 policies_.clear(); | 17 policies_.clear(); |
| 18 // Manually defining client policies for bookmark and last_n. | 18 // Manually defining client policies for bookmark and last_n. |
| 19 policies_.insert(std::make_pair( | 19 policies_.insert(std::make_pair( |
| 20 kBookmarkNamespace, | 20 kBookmarkNamespace, |
|
fgorski
2016/09/07 03:25:04
should be removed on cache reset.
chili
2016/09/12 17:39:00
Changed so that the policy defaults to delete on c
| |
| 21 MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY, | 21 MakePolicy(kBookmarkNamespace, LifetimeType::TEMPORARY, |
| 22 base::TimeDelta::FromDays(7), kUnlimitedPages, 1))); | 22 base::TimeDelta::FromDays(7), kUnlimitedPages, 1))); |
| 23 policies_.insert(std::make_pair( | 23 policies_.insert(std::make_pair( |
| 24 kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY, | 24 kLastNNamespace, MakePolicy(kLastNNamespace, LifetimeType::TEMPORARY, |
|
fgorski
2016/09/07 03:25:04
should be removed on cache reset.
chili
2016/09/12 17:39:00
Done.
| |
| 25 base::TimeDelta::FromDays(2), kUnlimitedPages, | 25 base::TimeDelta::FromDays(2), kUnlimitedPages, |
| 26 kUnlimitedPages))); | 26 kUnlimitedPages))); |
| 27 policies_.insert(std::make_pair( | 27 policies_.insert(std::make_pair( |
| 28 kAsyncNamespace, MakePolicy(kAsyncNamespace, LifetimeType::PERSISTENT, | 28 kAsyncNamespace, |
| 29 base::TimeDelta::FromDays(2), kUnlimitedPages, | 29 OfflinePageClientPolicyBuilder( |
| 30 kUnlimitedPages))); | 30 kAsyncNamespace, LifetimeType::PERSISTENT, |
| 31 kUnlimitedPages, kUnlimitedPages) | |
| 32 .SetIsSupportedByDownload(true) | |
| 33 .SetIsRemovedOnCacheReset(true) | |
|
fgorski
2016/09/07 03:25:04
[This comment was added first, before I marked oth
chili
2016/09/12 17:39:00
Done.
| |
| 34 .Build())); | |
| 31 policies_.insert(std::make_pair( | 35 policies_.insert(std::make_pair( |
| 32 kCCTNamespace, | 36 kCCTNamespace, |
|
fgorski
2016/09/07 03:25:04
discuss with dewittj@, but should probably not be
chili
2016/09/12 17:39:00
Acknowledged. Will talk with dewittj@ when he get
| |
| 33 MakePolicy(kCCTNamespace, LifetimeType::TEMPORARY, | 37 MakePolicy(kCCTNamespace, LifetimeType::TEMPORARY, |
| 34 base::TimeDelta::FromDays(2), kUnlimitedPages, 1))); | 38 base::TimeDelta::FromDays(2), kUnlimitedPages, 1))); |
| 35 | |
| 36 policies_.insert(std::make_pair( | 39 policies_.insert(std::make_pair( |
| 37 kDownloadNamespace, MakePolicy(kDownloadNamespace, | 40 kDownloadNamespace, |
| 41 OfflinePageClientPolicyBuilder( | |
| 42 kDownloadNamespace, | |
| 43 LifetimeType::PERSISTENT, | |
| 44 kUnlimitedPages, | |
| 45 kUnlimitedPages) | |
| 46 .SetIsRemovedOnCacheReset(true) | |
| 47 .SetIsSupportedByDownload(true) | |
|
fgorski
2016/09/07 03:25:05
should not be removed on cache reset.
chili
2016/09/12 17:39:00
Done.
| |
| 48 .Build())); | |
| 49 policies_.insert(std::make_pair( | |
| 50 kNTPSuggestionsNamespace, | |
| 51 OfflinePageClientPolicyBuilder(kNTPSuggestionsNamespace, | |
| 38 LifetimeType::PERSISTENT, | 52 LifetimeType::PERSISTENT, |
| 39 base::TimeDelta::FromDays(0), | |
| 40 kUnlimitedPages, | 53 kUnlimitedPages, |
| 41 kUnlimitedPages))); | 54 kUnlimitedPages).Build())); |
| 42 policies_.insert(std::make_pair( | |
| 43 kNTPSuggestionsNamespace, MakePolicy(kNTPSuggestionsNamespace, | |
| 44 LifetimeType::PERSISTENT, | |
| 45 base::TimeDelta::FromDays(0), | |
| 46 kUnlimitedPages, | |
| 47 kUnlimitedPages))); | |
| 48 | 55 |
| 49 // Fallback policy. | 56 // Fallback policy. |
| 50 policies_.insert(std::make_pair( | 57 policies_.insert(std::make_pair( |
| 51 kDefaultNamespace, MakePolicy(kDefaultNamespace, LifetimeType::TEMPORARY, | 58 kDefaultNamespace, MakePolicy(kDefaultNamespace, LifetimeType::TEMPORARY, |
|
fgorski
2016/09/07 03:25:04
should be removed on cache reset.
chili
2016/09/12 17:39:00
Done.
| |
| 52 base::TimeDelta::FromDays(1), 10, 1))); | 59 base::TimeDelta::FromDays(1), 10, 1))); |
| 53 } | 60 } |
| 54 | 61 |
| 55 ClientPolicyController::~ClientPolicyController() {} | 62 ClientPolicyController::~ClientPolicyController() {} |
| 56 | 63 |
| 57 // static | 64 // static |
| 58 const OfflinePageClientPolicy ClientPolicyController::MakePolicy( | 65 const OfflinePageClientPolicy ClientPolicyController::MakePolicy( |
| 59 const std::string& name_space, | 66 const std::string& name_space, |
| 60 LifetimeType lifetime_type, | 67 LifetimeType lifetime_type, |
| 61 const base::TimeDelta& expire_period, | 68 const base::TimeDelta& expire_period, |
| 62 size_t page_limit, | 69 size_t page_limit, |
| 63 size_t pages_allowed_per_url) { | 70 size_t pages_allowed_per_url) { |
| 64 OfflinePageClientPolicy policy({name_space, | 71 return OfflinePageClientPolicyBuilder( |
| 65 {lifetime_type, expire_period, page_limit}, | 72 name_space, lifetime_type, page_limit, pages_allowed_per_url) |
| 66 pages_allowed_per_url}); | 73 .SetExpirePeriod(expire_period) |
| 67 return policy; | 74 .Build(); |
| 68 } | 75 } |
| 69 | 76 |
| 70 const OfflinePageClientPolicy& ClientPolicyController::GetPolicy( | 77 const OfflinePageClientPolicy& ClientPolicyController::GetPolicy( |
| 71 const std::string& name_space) const { | 78 const std::string& name_space) const { |
| 72 const auto& iter = policies_.find(name_space); | 79 const auto& iter = policies_.find(name_space); |
| 73 if (iter != policies_.end()) | 80 if (iter != policies_.end()) |
| 74 return iter->second; | 81 return iter->second; |
| 75 // Fallback when the namespace isn't defined. | 82 // Fallback when the namespace isn't defined. |
| 76 return policies_.at(kDefaultNamespace); | 83 return policies_.at(kDefaultNamespace); |
| 77 } | 84 } |
| 78 | 85 |
| 86 bool ClientPolicyController::IsRemovedOnCacheReset( | |
| 87 const std::string& name_space) const { | |
| 88 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset; | |
| 89 } | |
| 90 | |
| 91 bool ClientPolicyController::IsSupportedByDownload( | |
| 92 const std::string& name_space) const { | |
| 93 return GetPolicy(name_space).feature_policy.is_supported_by_download; | |
| 94 } | |
| 95 | |
|
fgorski
2016/09/07 03:25:04
nit: remove extra empty line.
chili
2016/09/12 17:39:00
Done.
| |
| 96 | |
| 79 } // namespace offline_pages | 97 } // namespace offline_pages |
| OLD | NEW |