Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_supervised_provider.cc
blobe956f0a6898ea08653e54c3795363faacddcfcd2
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.
5 #include "chrome/browser/content_settings/content_settings_supervised_provider.h"
7 #include <string>
8 #include <vector>
10 #include "chrome/browser/supervised_user/supervised_user_constants.h"
11 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
13 namespace {
15 struct ContentSettingsFromSupervisedSettingsEntry {
16 const char* setting_name;
17 ContentSettingsType content_type;
20 const ContentSettingsFromSupervisedSettingsEntry
21 kContentSettingsFromSupervisedSettingsMap[] = {
23 supervised_users::kGeolocationDisabled,
24 CONTENT_SETTINGS_TYPE_GEOLOCATION,
25 }, {
26 supervised_users::kCameraMicDisabled,
27 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
28 }, {
29 supervised_users::kCameraMicDisabled,
30 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
34 } // namespace
36 namespace content_settings {
38 SupervisedProvider::SupervisedProvider(
39 SupervisedUserSettingsService* supervised_user_settings_service) {
41 // The SupervisedProvider is owned by the HostContentSettingsMap which
42 // DependsOn the SupervisedUserSettingsService (through their factories).
43 // This means this will get destroyed before the SUSS and will be
44 // unsubscribed from it.
45 user_settings_subscription_ = supervised_user_settings_service->Subscribe(
46 base::Bind(
47 &content_settings::SupervisedProvider::OnSupervisedSettingsAvailable,
48 base::Unretained(this)));
51 SupervisedProvider::~SupervisedProvider() {
54 RuleIterator* SupervisedProvider::GetRuleIterator(
55 ContentSettingsType content_type,
56 const ResourceIdentifier& resource_identifier,
57 bool incognito) const {
58 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_));
59 return value_map_.GetRuleIterator(content_type, resource_identifier,
60 auto_lock.Pass());
63 void SupervisedProvider::OnSupervisedSettingsAvailable(
64 const base::DictionaryValue* settings) {
65 std::vector<ContentSettingsType> to_notify;
66 // Entering locked scope to update content settings.
68 base::AutoLock auto_lock(lock_);
69 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) {
70 bool new_value = false;
71 if (settings && settings->HasKey(entry.setting_name)) {
72 bool is_bool = settings->GetBoolean(entry.setting_name, &new_value);
73 DCHECK(is_bool);
75 bool old_value = !value_map_.IsContentSettingEnabled(entry.content_type);
76 if (new_value != old_value) {
77 to_notify.push_back(entry.content_type);
78 value_map_.SetContentSettingDisabled(entry.content_type, new_value);
82 for (const auto& notification : to_notify) {
83 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(),
84 notification, std::string());
88 // Since the SupervisedProvider is a read only content settings provider, all
89 // methods of the ProviderInterface that set or delete any settings do nothing.
90 bool SupervisedProvider::SetWebsiteSetting(
91 const ContentSettingsPattern& primary_pattern,
92 const ContentSettingsPattern& secondary_pattern,
93 ContentSettingsType content_type,
94 const ResourceIdentifier& resource_identifier,
95 base::Value* value) {
96 return false;
99 void SupervisedProvider::ClearAllContentSettingsRules(
100 ContentSettingsType content_type) {
103 void SupervisedProvider::ShutdownOnUIThread() {
104 DCHECK(CalledOnValidThread());
105 RemoveAllObservers();
106 user_settings_subscription_.reset();
109 } // namespace content_settings