| 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 <set> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 11 #include "components/offline_pages/client_namespace_constants.h" | 12 #include "components/offline_pages/client_namespace_constants.h" |
| 12 | 13 |
| 13 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; | 14 using LifetimeType = offline_pages::LifetimePolicy::LifetimeType; |
| 14 | 15 |
| 15 namespace offline_pages { | 16 namespace offline_pages { |
| 16 | 17 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 78 |
| 78 const OfflinePageClientPolicy& ClientPolicyController::GetPolicy( | 79 const OfflinePageClientPolicy& ClientPolicyController::GetPolicy( |
| 79 const std::string& name_space) const { | 80 const std::string& name_space) const { |
| 80 const auto& iter = policies_.find(name_space); | 81 const auto& iter = policies_.find(name_space); |
| 81 if (iter != policies_.end()) | 82 if (iter != policies_.end()) |
| 82 return iter->second; | 83 return iter->second; |
| 83 // Fallback when the namespace isn't defined. | 84 // Fallback when the namespace isn't defined. |
| 84 return policies_.at(kDefaultNamespace); | 85 return policies_.at(kDefaultNamespace); |
| 85 } | 86 } |
| 86 | 87 |
| 88 std::vector<std::string> ClientPolicyController::GetAllNamespacesExcept( |
| 89 const std::vector<std::string>& exceptions) const { |
| 90 std::set<std::string> exception_set(exceptions.begin(), exceptions.end()); |
| 91 std::vector<std::string> result; |
| 92 for (const auto& policy_item : policies_) { |
| 93 if (exception_set.count(policy_item.first) == 0) |
| 94 result.emplace_back(policy_item.first); |
| 95 } |
| 96 |
| 97 return result; |
| 98 } |
| 99 |
| 87 bool ClientPolicyController::IsRemovedOnCacheReset( | 100 bool ClientPolicyController::IsRemovedOnCacheReset( |
| 88 const std::string& name_space) const { | 101 const std::string& name_space) const { |
| 89 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset; | 102 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset; |
| 90 } | 103 } |
| 91 | 104 |
| 92 bool ClientPolicyController::IsSupportedByDownload( | 105 bool ClientPolicyController::IsSupportedByDownload( |
| 93 const std::string& name_space) const { | 106 const std::string& name_space) const { |
| 94 return GetPolicy(name_space).feature_policy.is_supported_by_download; | 107 return GetPolicy(name_space).feature_policy.is_supported_by_download; |
| 95 } | 108 } |
| 96 | 109 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 show_in_original_tab_cache_ = base::MakeUnique<std::vector<std::string>>(); | 152 show_in_original_tab_cache_ = base::MakeUnique<std::vector<std::string>>(); |
| 140 for (const auto& policy_item : policies_) { | 153 for (const auto& policy_item : policies_) { |
| 141 if (policy_item.second.feature_policy.only_shown_in_original_tab) | 154 if (policy_item.second.feature_policy.only_shown_in_original_tab) |
| 142 show_in_original_tab_cache_->emplace_back(policy_item.first); | 155 show_in_original_tab_cache_->emplace_back(policy_item.first); |
| 143 } | 156 } |
| 144 | 157 |
| 145 return *show_in_original_tab_cache_; | 158 return *show_in_original_tab_cache_; |
| 146 } | 159 } |
| 147 | 160 |
| 148 } // namespace offline_pages | 161 } // namespace offline_pages |
| OLD | NEW |