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> | |
fgorski
2016/10/26 18:05:41
remove?
dewittj
2016/10/27 22:49:17
Done.
| |
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::GetAllNamespaces() const { | |
89 std::vector<std::string> result; | |
90 for (const auto& policy_item : policies_) | |
91 result.emplace_back(policy_item.first); | |
92 | |
93 return result; | |
94 } | |
95 | |
87 bool ClientPolicyController::IsRemovedOnCacheReset( | 96 bool ClientPolicyController::IsRemovedOnCacheReset( |
88 const std::string& name_space) const { | 97 const std::string& name_space) const { |
89 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset; | 98 return GetPolicy(name_space).feature_policy.is_removed_on_cache_reset; |
90 } | 99 } |
91 | 100 |
92 bool ClientPolicyController::IsSupportedByDownload( | 101 bool ClientPolicyController::IsSupportedByDownload( |
93 const std::string& name_space) const { | 102 const std::string& name_space) const { |
94 return GetPolicy(name_space).feature_policy.is_supported_by_download; | 103 return GetPolicy(name_space).feature_policy.is_supported_by_download; |
95 } | 104 } |
96 | 105 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 147 |
139 show_in_original_tab_cache_ = base::MakeUnique<std::vector<std::string>>(); | 148 show_in_original_tab_cache_ = base::MakeUnique<std::vector<std::string>>(); |
140 for (const auto& policy_item : policies_) { | 149 for (const auto& policy_item : policies_) { |
141 if (policy_item.second.feature_policy.only_shown_in_original_tab) | 150 if (policy_item.second.feature_policy.only_shown_in_original_tab) |
142 show_in_original_tab_cache_->emplace_back(policy_item.first); | 151 show_in_original_tab_cache_->emplace_back(policy_item.first); |
143 } | 152 } |
144 | 153 |
145 return *show_in_original_tab_cache_; | 154 return *show_in_original_tab_cache_; |
146 } | 155 } |
147 | 156 |
157 void ClientPolicyController::AddPolicyForTest( | |
158 std::string name_space, | |
159 const OfflinePageClientPolicyBuilder& builder) { | |
160 policies_.insert(std::make_pair(name_space, builder.Build())); | |
161 } | |
162 | |
148 } // namespace offline_pages | 163 } // namespace offline_pages |
OLD | NEW |