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

Side by Side Diff: net/reporting/reporting_cache.h

Issue 2779983002: Reporting: Properly support endpoints with includeSubdomains. (Closed)
Patch Set: Make requested changes. Created 3 years, 8 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
« no previous file with comments | « no previous file | net/reporting/reporting_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_REPORTING_REPORTING_CACHE_H_ 5 #ifndef NET_REPORTING_REPORTING_CACHE_H_
6 #define NET_REPORTING_REPORTING_CACHE_H_ 6 #define NET_REPORTING_REPORTING_CACHE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 // Gets all of the clients in the cache, regardless of origin or group. 101 // Gets all of the clients in the cache, regardless of origin or group.
102 // 102 //
103 // (Clears any existing data in |*clients_out|.) 103 // (Clears any existing data in |*clients_out|.)
104 void GetClients(std::vector<const ReportingClient*>* clients_out) const; 104 void GetClients(std::vector<const ReportingClient*>* clients_out) const;
105 105
106 // Gets all of the clients configured for a particular origin in a particular 106 // Gets all of the clients configured for a particular origin in a particular
107 // group. The returned pointers are only guaranteed to be valid if no calls 107 // group. The returned pointers are only guaranteed to be valid if no calls
108 // have been made to |SetClient| or |RemoveEndpoint| in between. 108 // have been made to |SetClient| or |RemoveEndpoint| in between.
109 // 109 //
110 // If no origin match is found, the cache will return clients from the most
111 // specific superdomain which contains any clients with includeSubdomains set.
112 // For example, given the origin https://foo.bar.baz.com/, the cache would
113 // prioritize returning each potential match below over the ones below it:
114 //
115 // 1. https://foo.bar.baz.com/ (exact origin match)
116 // 2. https://foo.bar.baz.com:444/ (technically, a superdomain)
117 // 3. https://bar.baz.com/, https://bar.baz.com:444/, etc. (superdomain)
118 // 4. https://baz.com/, https://baz.com:444/, etc. (superdomain)
119 // etc.
120 //
110 // (Clears any existing data in |*clients_out|.) 121 // (Clears any existing data in |*clients_out|.)
111 void GetClientsForOriginAndGroup( 122 void GetClientsForOriginAndGroup(
112 const url::Origin& origin, 123 const url::Origin& origin,
113 const std::string& group, 124 const std::string& group,
114 std::vector<const ReportingClient*>* clients_out) const; 125 std::vector<const ReportingClient*>* clients_out) const;
115 126
116 // Removes a set of clients. 127 // Removes a set of clients.
117 // 128 //
118 // May invalidate ReportingClient pointers returned by |GetClients| or 129 // May invalidate ReportingClient pointers returned by |GetClients| or
119 // |GetClientsForOriginAndGroup|. 130 // |GetClientsForOriginAndGroup|.
(...skipping 21 matching lines...) Expand all
141 152
142 bool IsReportPendingForTesting(const ReportingReport* report) const { 153 bool IsReportPendingForTesting(const ReportingReport* report) const {
143 return base::ContainsKey(pending_reports_, report); 154 return base::ContainsKey(pending_reports_, report);
144 } 155 }
145 156
146 bool IsReportDoomedForTesting(const ReportingReport* report) const { 157 bool IsReportDoomedForTesting(const ReportingReport* report) const {
147 return base::ContainsKey(doomed_reports_, report); 158 return base::ContainsKey(doomed_reports_, report);
148 } 159 }
149 160
150 private: 161 private:
162 void MaybeAddWildcardClient(const ReportingClient* client);
163
164 void MaybeRemoveWildcardClient(const ReportingClient* client);
165
166 void GetWildcardClientsForDomainAndGroup(
167 const std::string& domain,
168 const std::string& group,
169 std::vector<const ReportingClient*>* clients_out) const;
170
151 ReportingContext* context_; 171 ReportingContext* context_;
152 172
153 // Owns all clients, keyed by origin, then endpoint URL. 173 // Owns all clients, keyed by origin, then endpoint URL.
154 // (These would be unordered_map, but neither url::Origin nor GURL has a hash 174 // (These would be unordered_map, but neither url::Origin nor GURL has a hash
155 // function implemented.) 175 // function implemented.)
156 std::map<url::Origin, std::map<GURL, std::unique_ptr<ReportingClient>>> 176 std::map<url::Origin, std::map<GURL, std::unique_ptr<ReportingClient>>>
157 clients_; 177 clients_;
158 178
179 // References but does not own all clients with includeSubdomains set, keyed
180 // by domain name.
181 std::unordered_map<std::string, std::unordered_set<const ReportingClient*>>
182 wildcard_clients_;
183
159 // Owns all reports, keyed by const raw pointer for easier lookup. 184 // Owns all reports, keyed by const raw pointer for easier lookup.
160 std::unordered_map<const ReportingReport*, std::unique_ptr<ReportingReport>> 185 std::unordered_map<const ReportingReport*, std::unique_ptr<ReportingReport>>
161 reports_; 186 reports_;
162 187
163 // Reports that have been marked pending (in use elsewhere and should not be 188 // Reports that have been marked pending (in use elsewhere and should not be
164 // deleted until no longer pending). 189 // deleted until no longer pending).
165 std::unordered_set<const ReportingReport*> pending_reports_; 190 std::unordered_set<const ReportingReport*> pending_reports_;
166 191
167 // Reports that have been marked doomed (would have been deleted, but were 192 // Reports that have been marked doomed (would have been deleted, but were
168 // pending when the deletion was requested). 193 // pending when the deletion was requested).
169 std::unordered_set<const ReportingReport*> doomed_reports_; 194 std::unordered_set<const ReportingReport*> doomed_reports_;
170 195
171 DISALLOW_COPY_AND_ASSIGN(ReportingCache); 196 DISALLOW_COPY_AND_ASSIGN(ReportingCache);
172 }; 197 };
173 198
174 } // namespace net 199 } // namespace net
175 200
176 #endif // NET_REPORTING_REPORTING_CACHE_H_ 201 #endif // NET_REPORTING_REPORTING_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | net/reporting/reporting_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698