Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Side by Side Diff: chrome/browser/content_settings/content_settings_origin_identifier_value_map.cc

Issue 7049007: Origin Identifier Value Map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "chrome/browser/content_settings/content_settings_origin_identifier_val ue_map.h"
6
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "googleurl/src/gurl.h"
10
11 namespace content_settings {
12
13 OriginIdentifierValueMap::OriginIdentifierValueMap() {}
14
15 OriginIdentifierValueMap::~OriginIdentifierValueMap() {
16 Clear();
17 }
18
19 bool operator>(const OriginIdentifierValueMap::Entry& first,
20 const OriginIdentifierValueMap::Entry& second) {
21 // Compare item patterns.
22 if (first.item_pattern > second.item_pattern)
23 return true;
24 if (first.item_pattern < second.item_pattern)
25 return false;
26
27 // Compare top_level_frame patterns.
28 if (first.top_level_frame_pattern > second.top_level_frame_pattern)
29 return true;
30 return false;
31 }
32
33 Value* OriginIdentifierValueMap::GetValue(
34 const GURL& item_url,
35 const GURL& top_level_frame_url,
36 ContentSettingsType content_type,
37 const ResourceIdentifier& resource_identifier) const {
38 // Find best matching list entry.
39 OriginIdentifierValueMap::const_iterator best_match = entries_.end();
40 for (OriginIdentifierValueMap::const_iterator entry = entries_.begin();
41 entry != entries_.end();
42 ++entry) {
43 if (entry->item_pattern.Matches(item_url) &&
44 entry->top_level_frame_pattern.Matches(top_level_frame_url) &&
45 entry->content_type == content_type &&
46 entry->identifier == resource_identifier) {
47 if (best_match == entries_.end() || *entry > *best_match) {
48 best_match = entry;
49 }
50 }
51 }
52 if (best_match != entries_.end())
53 return best_match->value;
54 return NULL;
55 }
56
57 void OriginIdentifierValueMap::SetValue(
58 const ContentSettingsPattern& item_pattern,
59 const ContentSettingsPattern& top_level_frame_pattern,
60 ContentSettingsType content_type,
61 const ResourceIdentifier& resource_identifier,
62 Value* value) {
63 OriginIdentifierValueMap::iterator list_entry =
64 FindEntry(item_pattern,
65 top_level_frame_pattern,
66 content_type,
67 resource_identifier);
68 if (list_entry == entries_.end()) {
69 // No matching list entry found. Add a new entry to the list.
70 entries_.insert(list_entry, Entry(item_pattern,
71 top_level_frame_pattern,
72 content_type,
73 resource_identifier,
74 value));
75 } else {
76 // Update the list entry.
77 list_entry->value = value;
78 }
79 }
80
81 void OriginIdentifierValueMap::DeleteValue(
82 const ContentSettingsPattern& item_pattern,
83 const ContentSettingsPattern& top_level_frame_pattern,
84 ContentSettingsType content_type,
85 const ResourceIdentifier& resource_identifier) {
86 OriginIdentifierValueMap::iterator entry_to_delete =
87 FindEntry(item_pattern,
88 top_level_frame_pattern,
89 content_type,
90 resource_identifier);
91 if (entry_to_delete != entries_.end()) {
92 delete entry_to_delete->value;
93 entries_.erase(entry_to_delete);
94 }
95 }
96
97 void OriginIdentifierValueMap::Clear() {
98 // Delete all owned value objects.
99 for (OriginIdentifierValueMap::iterator entry = entries_.begin();
100 entry != entries_.end();
101 ++entry) {
102 delete entry->value;
103 }
104 entries_.clear();
105 }
106
107 OriginIdentifierValueMap::iterator OriginIdentifierValueMap::DeleteValue(
108 OriginIdentifierValueMap::iterator entry) {
109 return entries_.erase(entry);
Bernhard Bauer 2011/05/31 14:55:12 Does this leak the value? If it's not supposed to
markusheintz_ 2011/06/01 20:08:22 I knew this would bit me in the ... .Thanks for ca
110 }
111
112 OriginIdentifierValueMap::iterator OriginIdentifierValueMap::FindEntry(
113 const ContentSettingsPattern& item_pattern,
114 const ContentSettingsPattern& top_level_frame_pattern,
115 ContentSettingsType content_type,
116 const ResourceIdentifier& resource_identifier) {
117 for (OriginIdentifierValueMap::iterator entry = entries_.begin();
118 entry != entries_.end();
119 ++entry) {
120 if (item_pattern == entry->item_pattern &&
121 top_level_frame_pattern == entry->top_level_frame_pattern &&
122 content_type == entry->content_type &&
123 resource_identifier == entry->identifier) {
124 return entry;
125 }
126 }
127 return entries_.end();
128 }
129
130 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698