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

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

Issue 902833003: Add a HostContentSettingsMap layer for Supervised Users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Comments Created 5 years, 9 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 (c) 2015 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_supervised_provider.h "
6
7 #include <string>
8 #include <vector>
9
10 #include "chrome/browser/supervised_user/supervised_user_constants.h"
11 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
12
13 namespace {
14
15 struct ContentSettingsFromSupervisedSettingsEntry {
16 const char* setting_name;
17 ContentSettingsType content_type;
18 };
19
20 const ContentSettingsFromSupervisedSettingsEntry
21 kContentSettingsFromSupervisedSettingsMap[] = {
22 {
23 supervised_users::kGeolocationDisabled,
24 CONTENT_SETTINGS_TYPE_GEOLOCATION,
25 }, {
26 supervised_users::kCameraMicDisabled,
27 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
28 }
29 };
30
31 } // namespace
32
33 namespace content_settings {
34
35 SupervisedProvider::SupervisedProvider(
36 SupervisedUserSettingsService* supervised_user_settings_service)
37 : weak_ptr_factory_(this) {
38 supervised_user_settings_service->Subscribe(base::Bind(
39 &content_settings::SupervisedProvider::OnSupervisedSettingsAvailable,
40 weak_ptr_factory_.GetWeakPtr()));
41 }
42
43 RuleIterator* SupervisedProvider::GetRuleIterator(
44 ContentSettingsType content_type,
45 const ResourceIdentifier& resource_identifier,
46 bool incognito) const {
47 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_));
48 return value_map_.GetRuleIterator(content_type, resource_identifier,
49 auto_lock.Pass());
50 }
51
52 void SupervisedProvider::OnSupervisedSettingsAvailable(
53 const base::DictionaryValue* settings) {
54 if (!settings)
55 return;
56 std::vector<ContentSettingsType> to_notify;
57 // Entering locked scope to update content settings.
58 {
59 base::AutoLock auto_lock(lock_);
60 bool new_value, old_value;
61 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) {
62 if (settings->GetBoolean(entry.setting_name, &new_value)) {
63 old_value = !value_map_.IsContentSettingEnabled(entry.content_type);
64 if (new_value != old_value) {
65 to_notify.push_back(entry.content_type);
66 value_map_.SetContentSettingDisabled(entry.content_type, new_value);
67 }
68 }
69 }
70 }
71 for (const auto& notification : to_notify) {
72 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(),
73 notification, std::string());
74 }
75 }
76
77 // Since the SupervisedProvider is a read only content settings provider, all
78 // methods of the ProviderInterface that set or delete any settings do nothing.
79 bool SupervisedProvider::SetWebsiteSetting(
80 const ContentSettingsPattern& primary_pattern,
81 const ContentSettingsPattern& secondary_pattern,
82 ContentSettingsType content_type,
83 const ResourceIdentifier& resource_identifier,
84 base::Value* value) {
85 return false;
86 }
87
88 void SupervisedProvider::ClearAllContentSettingsRules(
89 ContentSettingsType content_type) {
90 }
91
92 void SupervisedProvider::ShutdownOnUIThread() {
93 DCHECK(CalledOnValidThread());
94 RemoveAllObservers();
95 }
96
97 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698