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_
11 #include "base/memory/linked_ptr.h"
12 #include "chrome/common/content_settings_pattern.h"
13 #include "chrome/common/content_settings_types.h"
22 namespace content_settings
{
26 class OriginIdentifierValueMap
{
28 typedef std::string ResourceIdentifier
;
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;
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();
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
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|.
96 const ContentSettingsPattern
& primary_pattern
,
97 const ContentSettingsPattern
& secondary_pattern
,
98 ContentSettingsType content_type
,
99 const ResourceIdentifier
& resource_identifier
,
102 // Deletes the map entry for the given |primary_pattern|,
103 // |secondary_pattern|, |content_type|, |resource_identifier| tuple.
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|.
113 ContentSettingsType content_type
,
114 const ResourceIdentifier
& resource_identifier
);
116 // Clears all map entries.
122 DISALLOW_COPY_AND_ASSIGN(OriginIdentifierValueMap
);
125 } // namespace content_settings
127 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_ORIGIN_IDENTIFIER_VALUE_MAP_H_