OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_preference_api.h" | 5 #include "chrome/browser/extensions/extension_preference_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 scoped_ptr<PrefTransformerInterface> identity_transformer_; | 195 scoped_ptr<PrefTransformerInterface> identity_transformer_; |
196 | 196 |
197 DISALLOW_COPY_AND_ASSIGN(PrefMapping); | 197 DISALLOW_COPY_AND_ASSIGN(PrefMapping); |
198 }; | 198 }; |
199 | 199 |
200 } // namespace | 200 } // namespace |
201 | 201 |
202 ExtensionPreferenceEventRouter::ExtensionPreferenceEventRouter( | 202 ExtensionPreferenceEventRouter::ExtensionPreferenceEventRouter( |
203 Profile* profile) : profile_(profile) { | 203 Profile* profile) : profile_(profile) { |
| 204 } |
| 205 |
| 206 ExtensionPreferenceEventRouter::~ExtensionPreferenceEventRouter() {} |
| 207 |
| 208 void ExtensionPreferenceEventRouter::Init() { |
204 registrar_.Init(profile_->GetPrefs()); | 209 registrar_.Init(profile_->GetPrefs()); |
205 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs()); | 210 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs()); |
206 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { | 211 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { |
207 registrar_.Add(kPrefMapping[i].browser_pref, this); | 212 registrar_.Add(kPrefMapping[i].browser_pref, this); |
208 incognito_registrar_.Add(kPrefMapping[i].browser_pref, this); | 213 incognito_registrar_.Add(kPrefMapping[i].browser_pref, this); |
209 } | 214 } |
210 } | 215 } |
211 | 216 |
212 ExtensionPreferenceEventRouter::~ExtensionPreferenceEventRouter() { } | |
213 | |
214 void ExtensionPreferenceEventRouter::Observe( | 217 void ExtensionPreferenceEventRouter::Observe( |
215 NotificationType type, | 218 NotificationType type, |
216 const NotificationSource& source, | 219 const NotificationSource& source, |
217 const NotificationDetails& details) { | 220 const NotificationDetails& details) { |
218 if (type == NotificationType::PREF_CHANGED) { | 221 if (type == NotificationType::PREF_CHANGED) { |
219 const std::string* pref_key = | 222 const std::string* pref_key = |
220 Details<const std::string>(details).ptr(); | 223 Details<const std::string>(details).ptr(); |
221 OnPrefChanged(Source<PrefService>(source).ptr(), *pref_key); | 224 OnPrefChanged(Source<PrefService>(source).ptr(), *pref_key); |
222 } else { | 225 } else { |
223 NOTREACHED(); | 226 NOTREACHED(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( | 415 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( |
413 pref_key, &browser_pref, &permission)); | 416 pref_key, &browser_pref, &permission)); |
414 if (!GetExtension()->HasApiPermission(permission)) { | 417 if (!GetExtension()->HasApiPermission(permission)) { |
415 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); | 418 error_ = base::StringPrintf(kPermissionErrorMessage, pref_key.c_str()); |
416 return false; | 419 return false; |
417 } | 420 } |
418 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); | 421 ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); |
419 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, incognito); | 422 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, incognito); |
420 return true; | 423 return true; |
421 } | 424 } |
OLD | NEW |