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

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

Issue 356543003: Audit the last usage of Geolocation and Notification permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests and a few more methods. 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 #include "chrome/browser/content_settings/host_content_settings_map.h" 5 #include "chrome/browser/content_settings/host_content_settings_map.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/clock.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/content_settings/content_settings_custom_extension_prov ider.h" 17 #include "chrome/browser/content_settings/content_settings_custom_extension_prov ider.h"
17 #include "chrome/browser/content_settings/content_settings_default_provider.h" 18 #include "chrome/browser/content_settings/content_settings_default_provider.h"
18 #include "chrome/browser/content_settings/content_settings_details.h" 19 #include "chrome/browser/content_settings/content_settings_details.h"
19 #include "chrome/browser/content_settings/content_settings_internal_extension_pr ovider.h" 20 #include "chrome/browser/content_settings/content_settings_internal_extension_pr ovider.h"
20 #include "chrome/browser/content_settings/content_settings_observable_provider.h " 21 #include "chrome/browser/content_settings/content_settings_observable_provider.h "
21 #include "chrome/browser/content_settings/content_settings_policy_provider.h" 22 #include "chrome/browser/content_settings/content_settings_policy_provider.h"
22 #include "chrome/browser/content_settings/content_settings_pref_provider.h" 23 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
23 #include "chrome/browser/content_settings/content_settings_provider.h" 24 #include "chrome/browser/content_settings/content_settings_provider.h"
24 #include "chrome/browser/content_settings/content_settings_rule.h" 25 #include "chrome/browser/content_settings/content_settings_rule.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 NOTREACHED(); 292 NOTREACHED();
292 } 293 }
293 294
294 void HostContentSettingsMap::SetContentSetting( 295 void HostContentSettingsMap::SetContentSetting(
295 const ContentSettingsPattern& primary_pattern, 296 const ContentSettingsPattern& primary_pattern,
296 const ContentSettingsPattern& secondary_pattern, 297 const ContentSettingsPattern& secondary_pattern,
297 ContentSettingsType content_type, 298 ContentSettingsType content_type,
298 const std::string& resource_identifier, 299 const std::string& resource_identifier,
299 ContentSetting setting) { 300 ContentSetting setting) {
300 DCHECK(!ContentTypeHasCompoundValue(content_type)); 301 DCHECK(!ContentTypeHasCompoundValue(content_type));
302
303 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
304 content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
305 UpdateLastUsageByPattern(primary_pattern, secondary_pattern, content_type);
dewittj 2014/06/26 23:17:47 why is it only these two types?
Daniel Nishi 2014/06/27 17:25:19 At the time of the patch, these are the two types
306 }
307
301 base::Value* value = NULL; 308 base::Value* value = NULL;
302 if (setting != CONTENT_SETTING_DEFAULT) 309 if (setting != CONTENT_SETTING_DEFAULT)
303 value = base::Value::CreateIntegerValue(setting); 310 value = base::Value::CreateIntegerValue(setting);
304 SetWebsiteSetting(primary_pattern, 311 SetWebsiteSetting(primary_pattern,
305 secondary_pattern, 312 secondary_pattern,
306 content_type, 313 content_type,
307 resource_identifier, 314 resource_identifier,
308 value); 315 value);
309 } 316 }
310 317
318 void HostContentSettingsMap::UpdateLastUsage(const GURL& primary_url,
319 const GURL& secondary_url,
320 ContentSettingsType content_type) {
321 UpdateLastUsageByPattern(
322 ContentSettingsPattern::FromURLNoWildcard(primary_url),
323 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
324 content_type);
325 }
326
327 void HostContentSettingsMap::UpdateLastUsageByPattern(
328 const ContentSettingsPattern& primary_pattern,
329 const ContentSettingsPattern& secondary_pattern,
330 ContentSettingsType content_type) {
331 UsedContentSettingsProviders();
332
333 static_cast<content_settings::PrefProvider*>(
334 content_settings_providers_[PREF_PROVIDER])
335 ->UpdateLastUsage(primary_pattern, secondary_pattern, content_type);
336 }
337
338 base::Time HostContentSettingsMap::GetLastUsage(
339 const GURL& primary_url,
340 const GURL& secondary_url,
341 ContentSettingsType content_type) {
342 return GetLastUsageByPattern(
343 ContentSettingsPattern::FromURLNoWildcard(primary_url),
344 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
345 content_type);
346 }
347
348 base::Time HostContentSettingsMap::GetLastUsageByPattern(
349 const ContentSettingsPattern& primary_pattern,
350 const ContentSettingsPattern& secondary_pattern,
351 ContentSettingsType content_type) {
352 UsedContentSettingsProviders();
353
354 return static_cast<content_settings::PrefProvider*>(
355 content_settings_providers_[PREF_PROVIDER])
356 ->GetLastUsage(primary_pattern, secondary_pattern, content_type);
357 }
358
359 void HostContentSettingsMap::SetPrefClockForTesting(base::Clock* clock) {
360 UsedContentSettingsProviders();
361
362 static_cast<content_settings::PrefProvider*>(
363 content_settings_providers_[PREF_PROVIDER])->SetClockForTesting(clock);
364 }
365
311 void HostContentSettingsMap::AddExceptionForURL( 366 void HostContentSettingsMap::AddExceptionForURL(
312 const GURL& primary_url, 367 const GURL& primary_url,
313 const GURL& secondary_url, 368 const GURL& secondary_url,
314 ContentSettingsType content_type, 369 ContentSettingsType content_type,
315 ContentSetting setting) { 370 ContentSetting setting) {
316 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must 371 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must
317 // match. 372 // match.
318 DCHECK(primary_url == secondary_url); 373 DCHECK(primary_url == secondary_url);
319 DCHECK(!ContentTypeHasCompoundValue(content_type)); 374 DCHECK(!ContentTypeHasCompoundValue(content_type));
320 375
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 HostContentSettingsMap::GetProviderTypeFromSource( 686 HostContentSettingsMap::GetProviderTypeFromSource(
632 const std::string& source) { 687 const std::string& source) {
633 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { 688 for (size_t i = 0; i < arraysize(kProviderNames); ++i) {
634 if (source == kProviderNames[i]) 689 if (source == kProviderNames[i])
635 return static_cast<ProviderType>(i); 690 return static_cast<ProviderType>(i);
636 } 691 }
637 692
638 NOTREACHED(); 693 NOTREACHED();
639 return DEFAULT_PROVIDER; 694 return DEFAULT_PROVIDER;
640 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698