Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: chrome/browser/content_settings/content_settings_supervised_provider.cc

Issue 2628883008: Add a supervised user setting to allow all cookies. (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/content_settings/content_settings_supervised_provider.h " 5 #include "chrome/browser/content_settings/content_settings_supervised_provider.h "
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "chrome/browser/supervised_user/supervised_user_constants.h" 11 #include "chrome/browser/supervised_user/supervised_user_constants.h"
12 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 12 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
13 13
14 namespace { 14 namespace {
15 15
16 struct ContentSettingsFromSupervisedSettingsEntry { 16 struct ContentSettingsFromSupervisedSettingsEntry {
17 const char* setting_name; 17 const char* setting_name;
18 ContentSettingsType content_type; 18 ContentSettingsType content_type;
19 ContentSetting content_setting;
19 }; 20 };
20 21
21 const ContentSettingsFromSupervisedSettingsEntry 22 const ContentSettingsFromSupervisedSettingsEntry
22 kContentSettingsFromSupervisedSettingsMap[] = { 23 kContentSettingsFromSupervisedSettingsMap[] = {
23 { 24 {
24 supervised_users::kGeolocationDisabled, 25 supervised_users::kGeolocationDisabled,
25 CONTENT_SETTINGS_TYPE_GEOLOCATION, 26 CONTENT_SETTINGS_TYPE_GEOLOCATION,
27 CONTENT_SETTING_BLOCK,
26 }, { 28 }, {
27 supervised_users::kCameraMicDisabled, 29 supervised_users::kCameraMicDisabled,
28 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 30 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
31 CONTENT_SETTING_BLOCK,
29 }, { 32 }, {
30 supervised_users::kCameraMicDisabled, 33 supervised_users::kCameraMicDisabled,
31 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 34 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
35 CONTENT_SETTING_BLOCK,
36 }, {
37 supervised_users::kCookiesAlwaysAllowed,
38 CONTENT_SETTINGS_TYPE_COOKIES,
39 CONTENT_SETTING_ALLOW,
32 } 40 }
33 }; 41 };
34 42
35 } // namespace 43 } // namespace
36 44
37 namespace content_settings { 45 namespace content_settings {
38 46
39 SupervisedProvider::SupervisedProvider( 47 SupervisedProvider::SupervisedProvider(
40 SupervisedUserSettingsService* supervised_user_settings_service) { 48 SupervisedUserSettingsService* supervised_user_settings_service) {
41 49
42 // The SupervisedProvider is owned by the HostContentSettingsMap which 50 // The SupervisedProvider is owned by the HostContentSettingsMap which
43 // DependsOn the SupervisedUserSettingsService (through their factories). 51 // DependsOn the SupervisedUserSettingsService (through their factories).
44 // This means this will get destroyed before the SUSS and will be 52 // This means this will get destroyed before the SUSS and will be
45 // unsubscribed from it. 53 // unsubscribed from it.
46 user_settings_subscription_ = supervised_user_settings_service->Subscribe( 54 user_settings_subscription_ = supervised_user_settings_service->Subscribe(
47 base::Bind( 55 base::Bind(
48 &content_settings::SupervisedProvider::OnSupervisedSettingsAvailable, 56 &content_settings::SupervisedProvider::OnSupervisedSettingsAvailable,
49 base::Unretained(this))); 57 base::Unretained(this)));
50 } 58 }
51 59
52 SupervisedProvider::~SupervisedProvider() { 60 SupervisedProvider::~SupervisedProvider() {
53 } 61 }
54 62
55 std::unique_ptr<RuleIterator> SupervisedProvider::GetRuleIterator( 63 std::unique_ptr<RuleIterator> SupervisedProvider::GetRuleIterator(
56 ContentSettingsType content_type, 64 ContentSettingsType content_type,
57 const ResourceIdentifier& resource_identifier, 65 const ResourceIdentifier& resource_identifier,
58 bool incognito) const { 66 bool incognito) const {
59 std::unique_ptr<base::AutoLock> auto_lock(new base::AutoLock(lock_)); 67 base::AutoLock auto_lock(lock_);
60 return value_map_.GetRuleIterator(content_type, resource_identifier, 68 return value_map_.GetRuleIterator(content_type, resource_identifier);
61 std::move(auto_lock));
62 } 69 }
63 70
64 void SupervisedProvider::OnSupervisedSettingsAvailable( 71 void SupervisedProvider::OnSupervisedSettingsAvailable(
65 const base::DictionaryValue* settings) { 72 const base::DictionaryValue* settings) {
66 std::vector<ContentSettingsType> to_notify; 73 std::vector<ContentSettingsType> to_notify;
67 // Entering locked scope to update content settings. 74 // Entering locked scope to update content settings.
68 { 75 {
69 base::AutoLock auto_lock(lock_); 76 base::AutoLock auto_lock(lock_);
70 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) { 77 for (const auto& entry : kContentSettingsFromSupervisedSettingsMap) {
71 bool new_value = false; 78 ContentSetting new_setting = CONTENT_SETTING_DEFAULT;
72 if (settings && settings->HasKey(entry.setting_name)) { 79 if (settings && settings->HasKey(entry.setting_name)) {
73 bool is_bool = settings->GetBoolean(entry.setting_name, &new_value); 80 bool new_is_set = false;
81 bool is_bool = settings->GetBoolean(entry.setting_name, &new_is_set);
74 DCHECK(is_bool); 82 DCHECK(is_bool);
83 if (new_is_set)
84 new_setting = entry.content_setting;
75 } 85 }
76 bool old_value = !value_map_.IsContentSettingEnabled(entry.content_type); 86 if (new_setting != value_map_.GetContentSetting(entry.content_type)) {
77 if (new_value != old_value) {
78 to_notify.push_back(entry.content_type); 87 to_notify.push_back(entry.content_type);
79 value_map_.SetContentSettingDisabled(entry.content_type, new_value); 88 value_map_.SetContentSetting(entry.content_type, new_setting);
80 } 89 }
81 } 90 }
82 } 91 }
83 for (const auto& notification : to_notify) { 92 for (ContentSettingsType type : to_notify) {
84 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(), 93 NotifyObservers(ContentSettingsPattern(), ContentSettingsPattern(),
85 notification, std::string()); 94 type, std::string());
86 } 95 }
87 } 96 }
88 97
89 // Since the SupervisedProvider is a read only content settings provider, all 98 // Since the SupervisedProvider is a read only content settings provider, all
90 // methods of the ProviderInterface that set or delete any settings do nothing. 99 // methods of the ProviderInterface that set or delete any settings do nothing.
91 bool SupervisedProvider::SetWebsiteSetting( 100 bool SupervisedProvider::SetWebsiteSetting(
92 const ContentSettingsPattern& primary_pattern, 101 const ContentSettingsPattern& primary_pattern,
93 const ContentSettingsPattern& secondary_pattern, 102 const ContentSettingsPattern& secondary_pattern,
94 ContentSettingsType content_type, 103 ContentSettingsType content_type,
95 const ResourceIdentifier& resource_identifier, 104 const ResourceIdentifier& resource_identifier,
96 base::Value* value) { 105 base::Value* value) {
97 return false; 106 return false;
98 } 107 }
99 108
100 void SupervisedProvider::ClearAllContentSettingsRules( 109 void SupervisedProvider::ClearAllContentSettingsRules(
101 ContentSettingsType content_type) { 110 ContentSettingsType content_type) {
102 } 111 }
103 112
104 void SupervisedProvider::ShutdownOnUIThread() { 113 void SupervisedProvider::ShutdownOnUIThread() {
105 DCHECK(CalledOnValidThread()); 114 DCHECK(CalledOnValidThread());
106 RemoveAllObservers(); 115 RemoveAllObservers();
107 user_settings_subscription_.reset(); 116 user_settings_subscription_.reset();
108 } 117 }
109 118
110 } // namespace content_settings 119 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698