OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/supervised_user/supervised_user_pref_store.h" | 5 #include "chrome/browser/supervised_user/supervised_user_pref_store.h" |
6 | 6 |
| 7 #include <utility> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/prefs/pref_value_map.h" | 12 #include "base/prefs/pref_value_map.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
15 #include "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" | 16 #include "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" |
16 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 17 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 bool SupervisedUserPrefStore::IsInitializationComplete() const { | 106 bool SupervisedUserPrefStore::IsInitializationComplete() const { |
106 return !!prefs_; | 107 return !!prefs_; |
107 } | 108 } |
108 | 109 |
109 SupervisedUserPrefStore::~SupervisedUserPrefStore() { | 110 SupervisedUserPrefStore::~SupervisedUserPrefStore() { |
110 } | 111 } |
111 | 112 |
112 void SupervisedUserPrefStore::OnNewSettingsAvailable( | 113 void SupervisedUserPrefStore::OnNewSettingsAvailable( |
113 const base::DictionaryValue* settings) { | 114 const base::DictionaryValue* settings) { |
114 scoped_ptr<PrefValueMap> old_prefs = prefs_.Pass(); | 115 scoped_ptr<PrefValueMap> old_prefs = std::move(prefs_); |
115 prefs_.reset(new PrefValueMap); | 116 prefs_.reset(new PrefValueMap); |
116 if (settings) { | 117 if (settings) { |
117 // Set hardcoded prefs and defaults. | 118 // Set hardcoded prefs and defaults. |
118 prefs_->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); | 119 prefs_->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); |
119 prefs_->SetInteger(prefs::kDefaultSupervisedUserFilteringBehavior, | 120 prefs_->SetInteger(prefs::kDefaultSupervisedUserFilteringBehavior, |
120 SupervisedUserURLFilter::ALLOW); | 121 SupervisedUserURLFilter::ALLOW); |
121 prefs_->SetBoolean(prefs::kForceGoogleSafeSearch, true); | 122 prefs_->SetBoolean(prefs::kForceGoogleSafeSearch, true); |
122 prefs_->SetBoolean(prefs::kForceYouTubeSafetyMode, true); | 123 prefs_->SetBoolean(prefs::kForceYouTubeSafetyMode, true); |
123 prefs_->SetBoolean(prefs::kHideWebStoreIcon, true); | 124 prefs_->SetBoolean(prefs::kHideWebStoreIcon, true); |
124 prefs_->SetInteger(prefs::kIncognitoModeAvailability, | 125 prefs_->SetInteger(prefs::kIncognitoModeAvailability, |
(...skipping 16 matching lines...) Expand all Loading... |
141 prefs_->SetInteger(prefs::kIncognitoModeAvailability, | 142 prefs_->SetInteger(prefs::kIncognitoModeAvailability, |
142 record_history ? IncognitoModePrefs::DISABLED | 143 record_history ? IncognitoModePrefs::DISABLED |
143 : IncognitoModePrefs::ENABLED); | 144 : IncognitoModePrefs::ENABLED); |
144 } | 145 } |
145 | 146 |
146 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 147 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
147 switches::kEnableSupervisedUserManagedBookmarksFolder)) { | 148 switches::kEnableSupervisedUserManagedBookmarksFolder)) { |
148 // Reconstruct bookmarks from split settings. | 149 // Reconstruct bookmarks from split settings. |
149 prefs_->SetValue( | 150 prefs_->SetValue( |
150 bookmarks::prefs::kSupervisedBookmarks, | 151 bookmarks::prefs::kSupervisedBookmarks, |
151 SupervisedUserBookmarksHandler::BuildBookmarksTree(*settings).Pass()); | 152 SupervisedUserBookmarksHandler::BuildBookmarksTree(*settings)); |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 if (!old_prefs) { | 156 if (!old_prefs) { |
156 FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted(true)); | 157 FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted(true)); |
157 return; | 158 return; |
158 } | 159 } |
159 | 160 |
160 std::vector<std::string> changed_prefs; | 161 std::vector<std::string> changed_prefs; |
161 prefs_->GetDifferingKeys(old_prefs.get(), &changed_prefs); | 162 prefs_->GetDifferingKeys(old_prefs.get(), &changed_prefs); |
162 | 163 |
163 // Send out change notifications. | 164 // Send out change notifications. |
164 for (const std::string& pref : changed_prefs) { | 165 for (const std::string& pref : changed_prefs) { |
165 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(pref)); | 166 FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(pref)); |
166 } | 167 } |
167 } | 168 } |
168 | 169 |
169 // Callback to unsubscribe from the supervised user settings service. | 170 // Callback to unsubscribe from the supervised user settings service. |
170 void SupervisedUserPrefStore::Observe( | 171 void SupervisedUserPrefStore::Observe( |
171 int type, | 172 int type, |
172 const content::NotificationSource& src, | 173 const content::NotificationSource& src, |
173 const content::NotificationDetails& details) { | 174 const content::NotificationDetails& details) { |
174 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 175 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
175 user_settings_subscription_.reset(); | 176 user_settings_subscription_.reset(); |
176 } | 177 } |
OLD | NEW |