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

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, 7 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 {
12 typedef content_settings::OriginIdentifierValueMap::EntryList::const_iterator
Bernhard Bauer 2011/05/19 15:05:17 The typedef doesn't need to be in an anoymous name
markusheintz_ 2011/05/23 19:55:11 moved it back to the content_settings namespace.
13 ConstEntryIterator;
14
15 typedef content_settings::OriginIdentifierValueMap::EntryList::iterator
16 EntryIterator;
17 }
18
19 namespace content_settings {
20
21 ConstEntryIterator OriginIdentifierValueMap::HighestPrecedence(
22 ConstEntryIterator first,
23 ConstEntryIterator second) const {
24 // Compare requesting patterns
25 if (first->a.Compare(second->a) == ContentSettingsPattern::PREDECESSOR)
jochen (gone - plz use gerrit) 2011/05/19 14:37:11 comments should always end in dot
Bernhard Bauer 2011/05/19 15:05:17 Pull out the comparison result into a variable and
markusheintz_ 2011/05/23 19:55:11 Done.
markusheintz_ 2011/05/23 19:55:11 Actually I'd like to add "<" and ">" operator to t
Bernhard Bauer 2011/05/24 14:21:29 Yes, if you inline it below (so it just becomes:)
markusheintz_ 2011/05/26 13:22:13 best_match < entry requires to add a < operator fo
Bernhard Bauer 2011/05/26 23:14:42 Yes. Ideally you could use ConstEntryIterator to m
markusheintz_ 2011/05/31 11:46:41 I used Entry instead of the ConstEntryIterator (do
26 return first;
27 if (second->a.Compare(first->a) == ContentSettingsPattern::PREDECESSOR)
28 return second;
29 DCHECK(first->a == second->a);
30
31 // Compare embedding patterns
32 if (first->a.Compare(second->a) == ContentSettingsPattern::PREDECESSOR)
33 return first;
34 DCHECK(first->b.Compare(second->b) == ContentSettingsPattern::PREDECESSOR);
35 return second;
36 }
37
38 Value* OriginIdentifierValueMap::GetValue(
39 const GURL& item_url,
40 const GURL& top_level_frame_url,
41 ContentSettingsType content_type,
42 const ResourceIdentifier& resource_identifier) const {
43 // Find best matching list entry.
44 ConstEntryIterator best_match = entries_.end();
45 for (ConstEntryIterator entry = entries_.begin();
46 entry != entries_.end();
47 ++entry) {
48 if (entry->a.Matches(item_url) &&
49 entry->b.Matches(top_level_frame_url) &&
50 entry->c == content_type &&
51 entry->d == resource_identifier) {
52 if (best_match == entries_.end()) {
53 best_match = entry;
54 } else {
55 best_match = HighestPrecedence(best_match, entry);
Bernhard Bauer 2011/05/19 15:05:17 Do you have plans to use that method somewhere els
markusheintz_ 2011/05/23 19:55:11 No I don't have plans to use it anywhere else. I j
56 }
57 }
58 }
59 if (best_match != entries_.end())
60 return best_match->e->DeepCopy();
Bernhard Bauer 2011/05/19 15:05:17 As discussed offline, it's probably preferable to
markusheintz_ 2011/05/23 19:55:11 Done.
61 return Value::CreateNullValue();
Bernhard Bauer 2011/05/19 15:05:17 return an actual NULL?
markusheintz_ 2011/05/23 19:55:11 Cool I returned a NULL in first place anyway. Done
62 }
63
64 void OriginIdentifierValueMap::SetValue(
65 const ContentSettingsPattern& item_pattern,
66 const ContentSettingsPattern& top_level_frame_pattern,
67 ContentSettingsType content_type,
68 const ResourceIdentifier& resource_identifier,
69 Value* value) {
70 EntryIterator list_entry = FindEntry(item_pattern,
71 top_level_frame_pattern,
72 content_type,
73 resource_identifier);
74 if (list_entry == entries_.end()) {
75 // No matching list entry found. Add a new entry to the list.
76 list_entry = entries_.insert(list_entry, MakeTuple(item_pattern,
77 top_level_frame_pattern,
78 content_type,
79 resource_identifier,
80 value));
81 }
82
83 // Update or entry
Bernhard Bauer 2011/05/19 15:05:17 Nit: "our" entry? Also, you can move this into the
markusheintz_ 2011/05/23 19:55:11 Done. Done.
84 list_entry->e = value;
85 }
86
87 void OriginIdentifierValueMap::DeleteValue(
88 const ContentSettingsPattern& item_pattern,
89 const ContentSettingsPattern& top_level_frame_pattern,
90 ContentSettingsType content_type,
91 const ResourceIdentifier& resource_identifier) {
92 EntryIterator entry_to_delete = FindEntry(item_pattern,
93 top_level_frame_pattern,
94 content_type,
95 resource_identifier);
96 if (entry_to_delete != entries_.end()) {
97 delete entry_to_delete->e;
98 entries_.erase(entry_to_delete);
99 }
100 }
101
102 EntryIterator OriginIdentifierValueMap::FindEntry(
103 const ContentSettingsPattern& item_pattern,
104 const ContentSettingsPattern& top_level_frame_pattern,
105 ContentSettingsType content_type,
106 const ResourceIdentifier& resource_identifier) {
107 EntryIterator list_entry(entries_.end());
108 for (EntryList::iterator entry = entries_.begin();
109 entry != entries_.end();
110 ++entry) {
111 if (item_pattern == entry->a &&
112 top_level_frame_pattern == entry->b &&
113 content_type == entry->c &&
114 resource_identifier == entry->d) {
115 list_entry = entry;
Bernhard Bauer 2011/05/19 15:05:17 Directly |return entry|?
markusheintz_ 2011/05/23 19:55:11 Done.
116 break;
117 }
118 }
119 return list_entry;
120 }
121
122
jochen (gone - plz use gerrit) 2011/05/19 14:37:11 only one empty line
markusheintz_ 2011/05/23 19:55:11 Done.
123 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698