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 "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 SupervisedProvider::~SupervisedProvider() { |
| 44 } |
| 45 |
| 46 RuleIterator* SupervisedProvider::GetRuleIterator( |
| 47 ContentSettingsType content_type, |
| 48 const ResourceIdentifier& resource_identifier, |
| 49 bool incognito) const { |
| 50 scoped_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); |
| 51 return value_map_.GetRuleIterator(content_type, resource_identifier, |
| 52 auto_lock.Pass()); |
| 53 } |
| 54 |
| 55 void SupervisedProvider::OnSupervisedSettingsAvailable( |
| 56 const base::DictionaryValue* settings) { |
| 57 if (!settings) |
| 58 return; |
| 59 std::vector<ContentSettingsType> to_notify; |
| 60 // Entering locked scope to update content settings. |
| 61 { |
| 62 base::AutoLock auto_lock(lock_); |
| 63 bool new_value, old_value; |
| 64 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) { |
| 65 if (settings->GetBoolean(entry.setting_name, &new_value)) { |
| 66 old_value = !value_map_.IsContentSettingEnabled(entry.content_type); |
| 67 if (new_value != old_value) { |
| 68 to_notify.push_back(entry.content_type); |
| 69 value_map_.SetContentSettingDisabled(entry.content_type, new_value); |
| 70 } |
| 71 } |
| 72 } |
| 73 } |
| 74 for (const auto& notification : to_notify) { |
| 75 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(), |
| 76 notification, std::string()); |
| 77 } |
| 78 } |
| 79 |
| 80 // Since the SupervisedProvider is a read only content settings provider, all |
| 81 // methods of the ProviderInterface that set or delete any settings do nothing. |
| 82 bool SupervisedProvider::SetWebsiteSetting( |
| 83 const ContentSettingsPattern& primary_pattern, |
| 84 const ContentSettingsPattern& secondary_pattern, |
| 85 ContentSettingsType content_type, |
| 86 const ResourceIdentifier& resource_identifier, |
| 87 base::Value* value) { |
| 88 return false; |
| 89 } |
| 90 |
| 91 void SupervisedProvider::ClearAllContentSettingsRules( |
| 92 ContentSettingsType content_type) { |
| 93 } |
| 94 |
| 95 void SupervisedProvider::ShutdownOnUIThread() { |
| 96 DCHECK(CalledOnValidThread()); |
| 97 RemoveAllObservers(); |
| 98 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 99 } |
| 100 |
| 101 } // namespace content_settings |
OLD | NEW |