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/core/offline_page_model_query.h" | 5 #include "components/offline_pages/core/offline_page_model_query.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <unordered_set> | 8 #include <unordered_set> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 OfflinePageModelQueryBuilder& OfflinePageModelQueryBuilder::SetUrls( | 36 OfflinePageModelQueryBuilder& OfflinePageModelQueryBuilder::SetUrls( |
37 Requirement requirement, | 37 Requirement requirement, |
38 const std::vector<GURL>& urls) { | 38 const std::vector<GURL>& urls) { |
39 urls_ = std::make_pair(requirement, urls); | 39 urls_ = std::make_pair(requirement, urls); |
40 return *this; | 40 return *this; |
41 } | 41 } |
42 | 42 |
43 OfflinePageModelQueryBuilder& | 43 OfflinePageModelQueryBuilder& |
| 44 OfflinePageModelQueryBuilder::RequireRemovedOnCacheReset( |
| 45 Requirement removed_on_cache_reset) { |
| 46 removed_on_cache_reset_ = removed_on_cache_reset; |
| 47 return *this; |
| 48 } |
| 49 |
| 50 OfflinePageModelQueryBuilder& |
44 OfflinePageModelQueryBuilder::RequireSupportedByDownload( | 51 OfflinePageModelQueryBuilder::RequireSupportedByDownload( |
45 Requirement supported_by_download) { | 52 Requirement supported_by_download) { |
46 supported_by_download_ = supported_by_download; | 53 supported_by_download_ = supported_by_download; |
47 return *this; | 54 return *this; |
48 } | 55 } |
49 | 56 |
50 OfflinePageModelQueryBuilder& | 57 OfflinePageModelQueryBuilder& |
51 OfflinePageModelQueryBuilder::RequireShownAsRecentlyVisitedSite( | 58 OfflinePageModelQueryBuilder::RequireShownAsRecentlyVisitedSite( |
52 Requirement recently_visited) { | 59 Requirement recently_visited) { |
53 shown_as_recently_visited_site_ = recently_visited; | 60 shown_as_recently_visited_site_ = recently_visited; |
(...skipping 24 matching lines...) Expand all Loading... |
78 client_ids_.first, | 85 client_ids_.first, |
79 std::set<ClientId>(client_ids_.second.begin(), client_ids_.second.end())); | 86 std::set<ClientId>(client_ids_.second.begin(), client_ids_.second.end())); |
80 client_ids_ = std::make_pair(Requirement::UNSET, std::vector<ClientId>()); | 87 client_ids_ = std::make_pair(Requirement::UNSET, std::vector<ClientId>()); |
81 | 88 |
82 std::vector<std::string> allowed_namespaces; | 89 std::vector<std::string> allowed_namespaces; |
83 bool uses_namespace_restrictions = false; | 90 bool uses_namespace_restrictions = false; |
84 | 91 |
85 for (auto& name_space : controller->GetAllNamespaces()) { | 92 for (auto& name_space : controller->GetAllNamespaces()) { |
86 // If any exclusion requirements exist, and the namespace matches one of | 93 // If any exclusion requirements exist, and the namespace matches one of |
87 // those excluded by policy, skip adding it to |allowed_namespaces|. | 94 // those excluded by policy, skip adding it to |allowed_namespaces|. |
88 if ((supported_by_download_ == Requirement::EXCLUDE_MATCHING && | 95 if ((removed_on_cache_reset_ == Requirement::EXCLUDE_MATCHING && |
| 96 controller->IsRemovedOnCacheReset(name_space)) || |
| 97 (supported_by_download_ == Requirement::EXCLUDE_MATCHING && |
89 controller->IsSupportedByDownload(name_space)) || | 98 controller->IsSupportedByDownload(name_space)) || |
90 (shown_as_recently_visited_site_ == Requirement::EXCLUDE_MATCHING && | 99 (shown_as_recently_visited_site_ == Requirement::EXCLUDE_MATCHING && |
91 controller->IsShownAsRecentlyVisitedSite(name_space)) || | 100 controller->IsShownAsRecentlyVisitedSite(name_space)) || |
92 (restricted_to_original_tab_ == Requirement::EXCLUDE_MATCHING && | 101 (restricted_to_original_tab_ == Requirement::EXCLUDE_MATCHING && |
93 controller->IsRestrictedToOriginalTab(name_space))) { | 102 controller->IsRestrictedToOriginalTab(name_space))) { |
94 // Skip namespaces that meet exclusion requirements. | 103 // Skip namespaces that meet exclusion requirements. |
95 uses_namespace_restrictions = true; | 104 uses_namespace_restrictions = true; |
96 continue; | 105 continue; |
97 } | 106 } |
98 | 107 |
99 if ((supported_by_download_ == Requirement::INCLUDE_MATCHING && | 108 if ((removed_on_cache_reset_ == Requirement::INCLUDE_MATCHING && |
| 109 !controller->IsRemovedOnCacheReset(name_space)) || |
| 110 (supported_by_download_ == Requirement::INCLUDE_MATCHING && |
100 !controller->IsSupportedByDownload(name_space)) || | 111 !controller->IsSupportedByDownload(name_space)) || |
101 (shown_as_recently_visited_site_ == Requirement::INCLUDE_MATCHING && | 112 (shown_as_recently_visited_site_ == Requirement::INCLUDE_MATCHING && |
102 !controller->IsShownAsRecentlyVisitedSite(name_space)) || | 113 !controller->IsShownAsRecentlyVisitedSite(name_space)) || |
103 (restricted_to_original_tab_ == Requirement::INCLUDE_MATCHING && | 114 (restricted_to_original_tab_ == Requirement::INCLUDE_MATCHING && |
104 !controller->IsRestrictedToOriginalTab(name_space))) { | 115 !controller->IsRestrictedToOriginalTab(name_space))) { |
105 // Skip namespaces that don't meet inclusion requirement. | 116 // Skip namespaces that don't meet inclusion requirement. |
106 uses_namespace_restrictions = true; | 117 uses_namespace_restrictions = true; |
107 continue; | 118 continue; |
108 } | 119 } |
109 | 120 |
110 // Add namespace otherwise. | 121 // Add namespace otherwise. |
111 allowed_namespaces.emplace_back(name_space); | 122 allowed_namespaces.emplace_back(name_space); |
112 } | 123 } |
113 | 124 |
| 125 removed_on_cache_reset_ = Requirement::UNSET; |
114 supported_by_download_ = Requirement::UNSET; | 126 supported_by_download_ = Requirement::UNSET; |
115 shown_as_recently_visited_site_ = Requirement::UNSET; | 127 shown_as_recently_visited_site_ = Requirement::UNSET; |
116 restricted_to_original_tab_ = Requirement::UNSET; | 128 restricted_to_original_tab_ = Requirement::UNSET; |
117 | 129 |
118 if (uses_namespace_restrictions) { | 130 if (uses_namespace_restrictions) { |
119 query->restricted_to_namespaces_ = base::MakeUnique<std::set<std::string>>( | 131 query->restricted_to_namespaces_ = base::MakeUnique<std::set<std::string>>( |
120 allowed_namespaces.begin(), allowed_namespaces.end()); | 132 allowed_namespaces.begin(), allowed_namespaces.end()); |
121 } | 133 } |
122 | 134 |
123 return query; | 135 return query; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 case Requirement::EXCLUDE_MATCHING: | 213 case Requirement::EXCLUDE_MATCHING: |
202 if (client_ids_.second.count(client_id) > 0) | 214 if (client_ids_.second.count(client_id) > 0) |
203 return false; | 215 return false; |
204 break; | 216 break; |
205 } | 217 } |
206 | 218 |
207 return true; | 219 return true; |
208 } | 220 } |
209 | 221 |
210 } // namespace offline_pages | 222 } // namespace offline_pages |
OLD | NEW |