OLD | NEW |
(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 "base/synchronization/lock.h" |
| 11 #include "base/values.h" |
| 12 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 struct ContentSettingsFromSupervisedSettingsEntry { |
| 17 const char* setting_name; |
| 18 ContentSettingsType content_type; |
| 19 }; |
| 20 |
| 21 const ContentSettingsFromSupervisedSettingsEntry |
| 22 kContentSettingsFromSupervisedSettingsMap[] = { |
| 23 { |
| 24 supervised_users::kGeolocationDisabled, |
| 25 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 26 }, { |
| 27 supervised_users::kCameraMicDisabled, |
| 28 CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
| 29 } |
| 30 }; |
| 31 |
| 32 } // namespace |
| 33 |
| 34 namespace content_settings { |
| 35 |
| 36 RuleIterator* SupervisedProvider::GetRuleIterator( |
| 37 ContentSettingsType content_type, |
| 38 const ResourceIdentifier& resource_identifier, |
| 39 bool incognito) const { |
| 40 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); |
| 41 return value_map_.GetRuleIterator(content_type, resource_identifier, |
| 42 auto_lock.Pass()); |
| 43 } |
| 44 |
| 45 void SupervisedProvider::OnSupervisedSettingsAvailable( |
| 46 const base::DictionaryValue* settings) { |
| 47 if (!settings) |
| 48 return; |
| 49 std::vector<ContentSettingsType> to_notify; |
| 50 // Entering locked scope to update content settings. |
| 51 { |
| 52 base::AutoLock auto_lock(lock_); |
| 53 bool new_value, old_value; |
| 54 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) { |
| 55 if (settings->GetBoolean(entry.setting_name, &new_value)) { |
| 56 old_value = !value_map_.IsContentSettingEnabled(entry.content_type); |
| 57 if (new_value != old_value) { |
| 58 to_notify.push_back(entry.content_type); |
| 59 value_map_.SetContentSettingDisabled(entry.content_type, new_value); |
| 60 } |
| 61 } |
| 62 } |
| 63 } |
| 64 for (const auto& notification : to_notify) { |
| 65 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(), |
| 66 notification, std::string()); |
| 67 } |
| 68 } |
| 69 |
| 70 // Since the SupervisedProvider is a read only content settings provider, all |
| 71 // methods of the ProviderInterface that set or delete any settings do nothing. |
| 72 bool SupervisedProvider::SetWebsiteSetting( |
| 73 const ContentSettingsPattern& primary_pattern, |
| 74 const ContentSettingsPattern& secondary_pattern, |
| 75 ContentSettingsType content_type, |
| 76 const ResourceIdentifier& resource_identifier, |
| 77 base::Value* value) { |
| 78 return false; |
| 79 } |
| 80 |
| 81 void SupervisedProvider::ClearAllContentSettingsRules( |
| 82 ContentSettingsType content_type) { |
| 83 } |
| 84 |
| 85 void SupervisedProvider::ShutdownOnUIThread() { |
| 86 DCHECK(CalledOnValidThread()); |
| 87 RemoveAllObservers(); |
| 88 } |
| 89 |
| 90 } // namespace content_settings |
OLD | NEW |