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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.h

Issue 356543003: Audit the last usage of Geolocation and Notification permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update the utils. Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // Maps hostnames to custom content settings. Written on the UI thread and read 5 // Maps hostnames to custom content settings. Written on the UI thread and read
6 // on any thread. One instance per profile. 6 // on any thread. One instance per profile.
7 7
8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
10 10
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/basictypes.h" 15 #include "base/basictypes.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/prefs/pref_change_registrar.h" 17 #include "base/prefs/pref_change_registrar.h"
18 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
19 #include "base/tuple.h" 19 #include "base/tuple.h"
20 #include "chrome/browser/content_settings/content_settings_observer.h" 20 #include "chrome/browser/content_settings/content_settings_observer.h"
21 #include "chrome/common/content_settings.h" 21 #include "chrome/common/content_settings.h"
22 #include "chrome/common/content_settings_pattern.h" 22 #include "chrome/common/content_settings_pattern.h"
23 #include "chrome/common/content_settings_types.h" 23 #include "chrome/common/content_settings_types.h"
24 24
25 class ExtensionService; 25 class ExtensionService;
26 class GURL; 26 class GURL;
27 class PrefService; 27 class PrefService;
28 28
29 namespace base { 29 namespace base {
30 class Clock;
30 class Value; 31 class Value;
31 } 32 }
32 33
33 namespace content_settings { 34 namespace content_settings {
34 class ProviderInterface; 35 class ProviderInterface;
35 } 36 }
36 37
37 namespace user_prefs { 38 namespace user_prefs {
38 class PrefRegistrySyncable; 39 class PrefRegistrySyncable;
39 } 40 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Returns the ProviderType associated with the given source string. 193 // Returns the ProviderType associated with the given source string.
193 // TODO(estade): I regret adding this. At the moment there are no legitimate 194 // TODO(estade): I regret adding this. At the moment there are no legitimate
194 // uses. We should stick to ProviderType rather than string so we don't have 195 // uses. We should stick to ProviderType rather than string so we don't have
195 // to convert backwards. 196 // to convert backwards.
196 static ProviderType GetProviderTypeFromSource(const std::string& source); 197 static ProviderType GetProviderTypeFromSource(const std::string& source);
197 198
198 bool is_off_the_record() const { 199 bool is_off_the_record() const {
199 return is_off_the_record_; 200 return is_off_the_record_;
200 } 201 }
201 202
203 // Returns a single |ContentSetting| which applies to the given URLs, just as
204 // |GetContentSetting| does. If the setting is allowed, it also records the
205 // last usage to preferences.
206 //
207 // This should only be called on the UI thread, unlike |GetContentSetting|.
208 ContentSetting GetContentSettingAndMaybeUpdateLastUsage(
209 const GURL& primary_url,
210 const GURL& secondary_url,
211 ContentSettingsType content_type,
212 const std::string& resource_identifier);
213
214 // Sets the last time that a given content type has been used for the pattern
215 // which matches the URLs to the current time.
216 void UpdateLastUsage(const GURL& primary_url,
217 const GURL& secondary_url,
218 ContentSettingsType content_type);
219
220 // Returns the last time the pattern that matches the URL has requested
221 // permission for the |content_type| setting.
222 base::Time GetLastUsage(const GURL& primary_url,
223 const GURL& secondary_url,
224 ContentSettingsType content_type);
225
226 // Returns the last time the pattern has requested permission for the
227 // |content_type| setting.
228 base::Time GetLastUsageByPattern(
229 const ContentSettingsPattern& primary_pattern,
230 const ContentSettingsPattern& secondary_pattern,
231 ContentSettingsType content_type);
232
233 // Passes ownership of |clock|.
Bernhard Bauer 2014/07/14 10:50:32 Why not use a scoped_ptr then?
Daniel Nishi 2014/07/14 17:12:54 Done.
234 void SetPrefClockForTesting(base::Clock* clock);
235
202 private: 236 private:
203 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; 237 friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
204 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; 238 friend class HostContentSettingsMapTest_NonDefaultSettings_Test;
205 239
206 typedef std::map<ProviderType, content_settings::ProviderInterface*> 240 typedef std::map<ProviderType, content_settings::ProviderInterface*>
207 ProviderMap; 241 ProviderMap;
208 typedef ProviderMap::iterator ProviderIterator; 242 typedef ProviderMap::iterator ProviderIterator;
209 typedef ProviderMap::const_iterator ConstProviderIterator; 243 typedef ProviderMap::const_iterator ConstProviderIterator;
210 244
211 virtual ~HostContentSettingsMap(); 245 virtual ~HostContentSettingsMap();
(...skipping 17 matching lines...) Expand all
229 const std::string& resource_identifier, 263 const std::string& resource_identifier,
230 ContentSettingsForOneType* settings, 264 ContentSettingsForOneType* settings,
231 bool incognito) const; 265 bool incognito) const;
232 266
233 // Call UsedContentSettingsProviders() whenever you access 267 // Call UsedContentSettingsProviders() whenever you access
234 // content_settings_providers_ (apart from initialization and 268 // content_settings_providers_ (apart from initialization and
235 // teardown), so that we can DCHECK in RegisterExtensionService that 269 // teardown), so that we can DCHECK in RegisterExtensionService that
236 // it is not being called too late. 270 // it is not being called too late.
237 void UsedContentSettingsProviders() const; 271 void UsedContentSettingsProviders() const;
238 272
273 // Convenience method for updating the last usage of a content type for a
274 // pattern.
275 void UpdateLastUsageByPattern(const ContentSettingsPattern& primary_pattern,
276 const ContentSettingsPattern& secondary_pattern,
277 ContentSettingsType content_type);
278
239 #ifndef NDEBUG 279 #ifndef NDEBUG
240 // This starts as the thread ID of the thread that constructs this 280 // This starts as the thread ID of the thread that constructs this
241 // object, and remains until used by a different thread, at which 281 // object, and remains until used by a different thread, at which
242 // point it is set to base::kInvalidThreadId. This allows us to 282 // point it is set to base::kInvalidThreadId. This allows us to
243 // DCHECK on unsafe usage of content_settings_providers_ (they 283 // DCHECK on unsafe usage of content_settings_providers_ (they
244 // should be set up on a single thread, after which they are 284 // should be set up on a single thread, after which they are
245 // immutable). 285 // immutable).
246 mutable base::PlatformThreadId used_from_thread_id_; 286 mutable base::PlatformThreadId used_from_thread_id_;
247 #endif 287 #endif
248 288
249 // Weak; owned by the Profile. 289 // Weak; owned by the Profile.
250 PrefService* prefs_; 290 PrefService* prefs_;
251 291
252 // Whether this settings map is for an OTR session. 292 // Whether this settings map is for an OTR session.
253 bool is_off_the_record_; 293 bool is_off_the_record_;
254 294
255 // Content setting providers. This is only modified at construction 295 // Content setting providers. This is only modified at construction
256 // time and by RegisterExtensionService, both of which should happen 296 // time and by RegisterExtensionService, both of which should happen
257 // before any other uses of it. 297 // before any other uses of it.
258 ProviderMap content_settings_providers_; 298 ProviderMap content_settings_providers_;
259 299
260 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); 300 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap);
261 }; 301 };
262 302
263 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 303 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698