OLD | NEW |
(Empty) | |
| 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 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_ORIGIN_IDENTIFIER_VALUE
_MAP_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_ORIGIN_IDENTIFIER_VALUE
_MAP_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <string> |
| 10 |
| 11 #include "base/tuple.h" |
| 12 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 13 #include "chrome/common/content_settings_types.h" |
| 14 |
| 15 class GURL; |
| 16 class Value; |
| 17 |
| 18 namespace content_settings { |
| 19 |
| 20 class OriginIdentifierValueMap { |
| 21 public: |
| 22 typedef std::string ResourceIdentifier; |
| 23 |
| 24 struct Entry { |
| 25 Entry(ContentSettingsPattern item_pattern, |
| 26 ContentSettingsPattern top_level_frame_pattern, |
| 27 ContentSettingsType content_type, |
| 28 ResourceIdentifier identifier, |
| 29 Value* value) |
| 30 : item_pattern(item_pattern), |
| 31 top_level_frame_pattern(top_level_frame_pattern), |
| 32 content_type(content_type), |
| 33 identifier(identifier), |
| 34 value(value) { |
| 35 } |
| 36 |
| 37 ContentSettingsPattern item_pattern; |
| 38 ContentSettingsPattern top_level_frame_pattern; |
| 39 ContentSettingsType content_type; |
| 40 ResourceIdentifier identifier; |
| 41 Value* value; |
| 42 }; |
| 43 |
| 44 typedef std::list<Entry> EntryList; |
| 45 |
| 46 typedef EntryList::const_iterator const_iterator; |
| 47 |
| 48 typedef EntryList::iterator iterator; |
| 49 |
| 50 EntryList::iterator begin() { |
| 51 return entries_.begin(); |
| 52 } |
| 53 |
| 54 EntryList::iterator end() { |
| 55 return entries_.end(); |
| 56 } |
| 57 |
| 58 EntryList::const_iterator begin() const { |
| 59 return entries_.begin(); |
| 60 } |
| 61 |
| 62 EntryList::const_iterator end() const { |
| 63 return entries_.end(); |
| 64 } |
| 65 |
| 66 size_t size() const { |
| 67 return entries_.size(); |
| 68 } |
| 69 |
| 70 OriginIdentifierValueMap(); |
| 71 ~OriginIdentifierValueMap(); |
| 72 |
| 73 // Returns a weak pointer to the value for the given |item_pattern|, |
| 74 // |top_level_frame_pattern|, |content_type|, |resource_identifier| tuple. If |
| 75 // no value is stored for the passed parameter |NULL| is returned. |
| 76 Value* GetValue( |
| 77 const GURL& item_url, |
| 78 const GURL& top_level_frame_url, |
| 79 ContentSettingsType content_type, |
| 80 const ResourceIdentifier& resource_identifier) const; |
| 81 |
| 82 // Sets the |value| for the given |item_pattern|, |top_level_frame_pattern|, |
| 83 // |content_type|, |resource_identifier| tuple. The method takes the ownership |
| 84 // of the passed |value|. |
| 85 void SetValue( |
| 86 const ContentSettingsPattern& item_pattern, |
| 87 const ContentSettingsPattern& top_level_frame_pattern, |
| 88 ContentSettingsType content_type, |
| 89 const ResourceIdentifier& resource_identifier, |
| 90 Value* value); |
| 91 |
| 92 // Deletes the map entry for the given |item_pattern|, |
| 93 // |top_level_frame_pattern|, |content_type|, |resource_identifier| tuple. |
| 94 void DeleteValue( |
| 95 const ContentSettingsPattern& item_pattern, |
| 96 const ContentSettingsPattern& top_level_frame_pattern, |
| 97 ContentSettingsType content_type, |
| 98 const ResourceIdentifier& resource_identifier); |
| 99 |
| 100 // Deletes the map entry at the passed position. The method returns the |
| 101 // position of the next entry in the map. |
| 102 EntryList::iterator DeleteValue(EntryList::iterator entry); |
| 103 |
| 104 // Clears all map entries. |
| 105 void Clear(); |
| 106 |
| 107 private: |
| 108 // Finds the list entry for the given |item_pattern|, |
| 109 // |top_level_frame_pattern|, |content_type|, |resource_identifier| tuple and |
| 110 // returns the iterator of the list entry. If no entry is found for the passed |
| 111 // parameters then the end of list iterator is returned. |
| 112 EntryList::iterator FindEntry( |
| 113 const ContentSettingsPattern& item_pattern, |
| 114 const ContentSettingsPattern& top_level_frame_pattern, |
| 115 ContentSettingsType content_type, |
| 116 const ResourceIdentifier& resource_identifier); |
| 117 |
| 118 EntryList entries_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(OriginIdentifierValueMap); |
| 121 }; |
| 122 |
| 123 // Compares two origin value map entries and tests if the item, top-level-frame |
| 124 // pattern pair of the first entry has a higher precedences then the pattern |
| 125 // pair of the second entry. |
| 126 bool operator>(const OriginIdentifierValueMap::Entry& first, |
| 127 const OriginIdentifierValueMap::Entry& second); |
| 128 |
| 129 } // namespace content_settings |
| 130 |
| 131 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_ORIGIN_IDENTIFIER_VA
LUE_MAP_H_ |
OLD | NEW |