No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_supervised_provider.cc
blobf6294446a218b66ab540075a45638de2e26bf6c8
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)
40 : weak_ptr_factory_(this) {
41 supervised_user_settings_service->Subscribe(base::Bind(
42 &content_settings::SupervisedProvider::OnSupervisedSettingsAvailable,
43 weak_ptr_factory_.GetWeakPtr()));
46 SupervisedProvider::~SupervisedProvider() {
49 RuleIterator* SupervisedProvider::GetRuleIterator(
50 ContentSettingsType content_type,
51 const ResourceIdentifier& resource_identifier,
52 bool incognito) const {
53 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_));
54 return value_map_.GetRuleIterator(content_type, resource_identifier,
55 auto_lock.Pass());
58 void SupervisedProvider::OnSupervisedSettingsAvailable(
59 const base::DictionaryValue* settings) {
60 std::vector<ContentSettingsType> to_notify;
61 // Entering locked scope to update content settings.
63 base::AutoLock auto_lock(lock_);
64 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) {
65 bool new_value = false;
66 if (settings && settings->HasKey(entry.setting_name)) {
67 bool is_bool = settings->GetBoolean(entry.setting_name, &new_value);
68 DCHECK(is_bool);
70 bool old_value = !value_map_.IsContentSettingEnabled(entry.content_type);
71 if (new_value != old_value) {
72 to_notify.push_back(entry.content_type);
73 value_map_.SetContentSettingDisabled(entry.content_type, new_value);
77 for (const auto& notification : to_notify) {
78 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(),
79 notification, std::string());
83 // Since the SupervisedProvider is a read only content settings provider, all
84 // methods of the ProviderInterface that set or delete any settings do nothing.
85 bool SupervisedProvider::SetWebsiteSetting(
86 const ContentSettingsPattern& primary_pattern,
87 const ContentSettingsPattern& secondary_pattern,
88 ContentSettingsType content_type,
89 const ResourceIdentifier& resource_identifier,
90 base::Value* value) {
91 return false;
94 void SupervisedProvider::ClearAllContentSettingsRules(
95 ContentSettingsType content_type) {
98 void SupervisedProvider::ShutdownOnUIThread() {
99 DCHECK(CalledOnValidThread());
100 RemoveAllObservers();
101 weak_ptr_factory_.InvalidateWeakPtrs();
104 } // namespace content_settings