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 3 // found in the LICENSE file. 4 5 #include "base/logging.h" 6 #include "chrome/browser/content_settings/content_settings_rule.h" 7 8 namespace content_settings { 9 10 Rule::Rule() {} 11 12 Rule::Rule( 13 const ContentSettingsPattern& primary_pattern, 14 const ContentSettingsPattern& secondary_pattern, 15 base::Value* value) 16 : primary_pattern(primary_pattern), 17 secondary_pattern(secondary_pattern), 18 value(value) { 19 DCHECK(value); 20 } 21 22 Rule::~Rule() {} 23 24 RuleIterator::~RuleIterator() {} 25 26 EmptyRuleIterator::~EmptyRuleIterator() {} 27 28 bool EmptyRuleIterator::HasNext() const { 29 return false; 30 } 31 32 Rule EmptyRuleIterator::Next() { 33 NOTREACHED(); 34 return Rule(); 35 } 36 37 ConcatenationIterator::ConcatenationIterator( 38 ScopedVector<RuleIterator>* iterators, 39 base::AutoLock* auto_lock) 40 : auto_lock_(auto_lock) { 41 iterators_.swap(*iterators); 42 43 ScopedVector<RuleIterator>::iterator it = iterators_.begin(); 44 while (it != iterators_.end()) { 45 if (!(*it)->HasNext()) 46 it = iterators_.erase(it); 47 else 48 ++it; 49 } 50 } 51 52 ConcatenationIterator::~ConcatenationIterator() {} 53 54 bool ConcatenationIterator::HasNext() const { 55 return (!iterators_.empty()); 56 } 57 58 Rule ConcatenationIterator::Next() { 59 ScopedVector<RuleIterator>::iterator current_iterator = 60 iterators_.begin(); 61 DCHECK(current_iterator != iterators_.end()); 62 DCHECK((*current_iterator)->HasNext()); 63 const Rule& to_return = (*current_iterator)->Next(); 64 if (!(*current_iterator)->HasNext()) 65 iterators_.erase(current_iterator); 66 return to_return; 67 } 68 69 } // namespace content_settings 70