Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_origin_identifier_value_map.h
blob2e3d3cdb73079687338f98c06e39e0f2a0ed1684
1 // Copyright (c) 2012 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.
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_
8 #include <map>
9 #include <string>
11 #include "base/memory/linked_ptr.h"
12 #include "chrome/common/content_settings_pattern.h"
13 #include "components/content_settings/core/common/content_settings_types.h"
15 class GURL;
17 namespace base {
18 class Lock;
19 class Value;
22 namespace content_settings {
24 class RuleIterator;
26 class OriginIdentifierValueMap {
27 public:
28 typedef std::string ResourceIdentifier;
29 struct EntryMapKey {
30 ContentSettingsType content_type;
31 ResourceIdentifier resource_identifier;
32 EntryMapKey(ContentSettingsType content_type,
33 const ResourceIdentifier& resource_identifier);
34 bool operator<(const OriginIdentifierValueMap::EntryMapKey& other) const;
37 struct PatternPair {
38 ContentSettingsPattern primary_pattern;
39 ContentSettingsPattern secondary_pattern;
40 PatternPair(const ContentSettingsPattern& primary_pattern,
41 const ContentSettingsPattern& secondary_pattern);
42 bool operator<(const OriginIdentifierValueMap::PatternPair& other) const;
45 typedef std::map<PatternPair, linked_ptr<base::Value> > Rules;
46 typedef std::map<EntryMapKey, Rules> EntryMap;
48 EntryMap::iterator begin() {
49 return entries_.begin();
52 EntryMap::iterator end() {
53 return entries_.end();
56 EntryMap::const_iterator begin() const {
57 return entries_.begin();
60 EntryMap::const_iterator end() const {
61 return entries_.end();
64 bool empty() const {
65 return size() == 0u;
68 size_t size() const;
70 // Returns an iterator for reading the rules for |content_type| and
71 // |resource_identifier|. The caller takes the ownership of the iterator. It
72 // is not allowed to call functions of |OriginIdentifierValueMap| (also
73 // |GetRuleIterator|) before the iterator has been destroyed. If |lock| is
74 // non-NULL, the returned |RuleIterator| locks it and releases it when it is
75 // destroyed.
76 RuleIterator* GetRuleIterator(ContentSettingsType content_type,
77 const ResourceIdentifier& resource_identifier,
78 base::Lock* lock) const;
80 OriginIdentifierValueMap();
81 ~OriginIdentifierValueMap();
83 // Returns a weak pointer to the value for the given |primary_pattern|,
84 // |secondary_pattern|, |content_type|, |resource_identifier| tuple. If
85 // no value is stored for the passed parameter |NULL| is returned.
86 base::Value* GetValue(
87 const GURL& primary_url,
88 const GURL& secondary_url,
89 ContentSettingsType content_type,
90 const ResourceIdentifier& resource_identifier) const;
92 // Sets the |value| for the given |primary_pattern|, |secondary_pattern|,
93 // |content_type|, |resource_identifier| tuple. The method takes the ownership
94 // of the passed |value|.
95 void SetValue(
96 const ContentSettingsPattern& primary_pattern,
97 const ContentSettingsPattern& secondary_pattern,
98 ContentSettingsType content_type,
99 const ResourceIdentifier& resource_identifier,
100 base::Value* value);
102 // Deletes the map entry for the given |primary_pattern|,
103 // |secondary_pattern|, |content_type|, |resource_identifier| tuple.
104 void DeleteValue(
105 const ContentSettingsPattern& primary_pattern,
106 const ContentSettingsPattern& secondary_pattern,
107 ContentSettingsType content_type,
108 const ResourceIdentifier& resource_identifier);
110 // Deletes all map entries for the given |content_type| and
111 // |resource_identifier|.
112 void DeleteValues(
113 ContentSettingsType content_type,
114 const ResourceIdentifier& resource_identifier);
116 // Clears all map entries.
117 void clear();
119 private:
120 EntryMap entries_;
122 DISALLOW_COPY_AND_ASSIGN(OriginIdentifierValueMap);
125 } // namespace content_settings
127 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_ORIGIN_IDENTIFIER_VALUE_MAP_H_