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