OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/content_settings/core/browser/content_settings_rule.h" |
| 6 |
| 7 #include <utility> |
| 8 |
5 #include "base/logging.h" | 9 #include "base/logging.h" |
6 #include "components/content_settings/core/browser/content_settings_rule.h" | |
7 | 10 |
8 namespace content_settings { | 11 namespace content_settings { |
9 | 12 |
10 Rule::Rule() {} | 13 Rule::Rule() {} |
11 | 14 |
12 Rule::Rule( | 15 Rule::Rule( |
13 const ContentSettingsPattern& primary_pattern, | 16 const ContentSettingsPattern& primary_pattern, |
14 const ContentSettingsPattern& secondary_pattern, | 17 const ContentSettingsPattern& secondary_pattern, |
15 base::Value* value) | 18 base::Value* value) |
16 : primary_pattern(primary_pattern), | 19 : primary_pattern(primary_pattern), |
17 secondary_pattern(secondary_pattern), | 20 secondary_pattern(secondary_pattern), |
18 value(value) { | 21 value(value) { |
19 DCHECK(value); | 22 DCHECK(value); |
20 } | 23 } |
21 | 24 |
22 Rule::Rule(const Rule& other) = default; | 25 Rule::Rule(const Rule& other) = default; |
23 | 26 |
24 Rule::~Rule() {} | 27 Rule::~Rule() {} |
25 | 28 |
26 RuleIterator::~RuleIterator() {} | 29 RuleIterator::~RuleIterator() {} |
27 | 30 |
28 EmptyRuleIterator::~EmptyRuleIterator() {} | |
29 | |
30 bool EmptyRuleIterator::HasNext() const { | |
31 return false; | |
32 } | |
33 | |
34 Rule EmptyRuleIterator::Next() { | |
35 NOTREACHED(); | |
36 return Rule(); | |
37 } | |
38 | |
39 ConcatenationIterator::ConcatenationIterator( | 31 ConcatenationIterator::ConcatenationIterator( |
40 std::vector<std::unique_ptr<RuleIterator>> iterators, | 32 std::vector<std::unique_ptr<RuleIterator>> iterators, |
41 base::AutoLock* auto_lock) | 33 base::AutoLock* auto_lock) |
42 : iterators_(std::move(iterators)), auto_lock_(auto_lock) { | 34 : iterators_(std::move(iterators)), auto_lock_(auto_lock) { |
43 auto it = iterators_.begin(); | 35 auto it = iterators_.begin(); |
44 while (it != iterators_.end()) { | 36 while (it != iterators_.end()) { |
45 if (!(*it)->HasNext()) | 37 if (!(*it)->HasNext()) |
46 it = iterators_.erase(it); | 38 it = iterators_.erase(it); |
47 else | 39 else |
48 ++it; | 40 ++it; |
49 } | 41 } |
50 } | 42 } |
51 | 43 |
52 ConcatenationIterator::~ConcatenationIterator() {} | 44 ConcatenationIterator::~ConcatenationIterator() {} |
53 | 45 |
54 bool ConcatenationIterator::HasNext() const { | 46 bool ConcatenationIterator::HasNext() const { |
55 return (!iterators_.empty()); | 47 return !iterators_.empty(); |
56 } | 48 } |
57 | 49 |
58 Rule ConcatenationIterator::Next() { | 50 Rule ConcatenationIterator::Next() { |
59 auto current_iterator = iterators_.begin(); | 51 auto current_iterator = iterators_.begin(); |
60 DCHECK(current_iterator != iterators_.end()); | 52 DCHECK(current_iterator != iterators_.end()); |
61 DCHECK((*current_iterator)->HasNext()); | 53 DCHECK((*current_iterator)->HasNext()); |
62 const Rule& to_return = (*current_iterator)->Next(); | 54 const Rule& to_return = (*current_iterator)->Next(); |
63 if (!(*current_iterator)->HasNext()) | 55 if (!(*current_iterator)->HasNext()) |
64 iterators_.erase(current_iterator); | 56 iterators_.erase(current_iterator); |
65 return to_return; | 57 return to_return; |
66 } | 58 } |
67 | 59 |
68 } // namespace content_settings | 60 } // namespace content_settings |
OLD | NEW |