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

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

Issue 542253003: Add a global on/off switch for content settings and expose a toggle on the Website Settings options… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@global-settings
Patch Set: Forgot to clarify ownership comments. Created 6 years, 3 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
(Empty)
1 // Copyright 2014 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_override_provider.h"
6
7 #include <string>
8
9 #include "base/auto_reset.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "base/values.h"
13 #include "chrome/browser/content_settings/content_settings_utils.h"
14 #include "chrome/common/content_settings.h"
15 #include "chrome/common/pref_names.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "content/public/browser/browser_thread.h"
18
19 using content::BrowserThread;
20
21 namespace content_settings {
22
23 // static
24 void OverrideProvider::RegisterProfilePrefs(
25 user_prefs::PrefRegistrySyncable* registry) {
26 registry->RegisterDictionaryPref(
27 prefs::kOverrideContentSettings,
28 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
29 }
30
31 OverrideProvider::OverrideProvider(PrefService* prefs, bool incognito)
32 : prefs_(prefs), is_incognito_(incognito) {
33 DCHECK(prefs_);
34
35 // Read global overrides.
36 ReadOverrideSettings();
37 }
38
39 OverrideProvider::~OverrideProvider() {
40 }
41
42 void OverrideProvider::SetContentSetting(ContentSettingsType content_type,
43 bool is_enabled) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Bernhard Bauer 2014/09/10 17:44:53 There is a DCHECK_CURRENTLY_ON macro that will giv
Daniel Nishi 2014/09/10 23:30:20 Done.
45 DCHECK(prefs_);
46
47 if (is_incognito_)
48 return;
49
50 DictionaryPrefUpdate update(prefs_, prefs::kOverrideContentSettings);
51 base::DictionaryValue* default_settings_dictionary = update.Get();
52 base::AutoLock lock(lock_);
53 override_settings_[content_type] = is_enabled;
54 default_settings_dictionary->SetWithoutPathExpansion(
55 GetTypeName(content_type), new base::FundamentalValue(is_enabled));
56 }
57
58 bool OverrideProvider::IsEnabled(ContentSettingsType content_type) const {
59 base::AutoLock lock(lock_);
60 std::map<ContentSettingsType, bool>::const_iterator it =
61 override_settings_.find(content_type);
62 if (it == override_settings_.end())
63 return true;
64
65 return it->second;
66 }
67
68 void OverrideProvider::ReadOverrideSettings() {
69 const base::DictionaryValue* override_settings_dictionary =
Bernhard Bauer 2014/09/10 17:44:54 I would DCHECK that you're on the UI thread here.
Daniel Nishi 2014/09/10 23:30:21 Done.
70 prefs_->GetDictionary(prefs::kOverrideContentSettings);
71
72 override_settings_.clear();
73
74 if (override_settings_dictionary) {
75 for (base::DictionaryValue::Iterator i(*override_settings_dictionary);
76 !i.IsAtEnd();
77 i.Advance()) {
78 const std::string& content_type(i.key());
79 for (size_t type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) {
80 if (content_type == GetTypeName(ContentSettingsType(type))) {
81 bool bool_value = true;
82 bool rv = i.value().GetAsBoolean(&bool_value);
83 DCHECK(rv);
84 override_settings_[ContentSettingsType(type)] = bool_value;
85 break;
86 }
87 }
88 }
89 }
90 }
91 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698