OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/preference/preference_api.h" | 5 #include "chrome/browser/extensions/api/preference/preference_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
| 10 #include <memory> |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 const std::string& browser_pref) { | 375 const std::string& browser_pref) { |
375 bool incognito = (pref_service != profile_->GetPrefs()); | 376 bool incognito = (pref_service != profile_->GetPrefs()); |
376 | 377 |
377 std::string event_name; | 378 std::string event_name; |
378 APIPermission::ID permission = APIPermission::kInvalid; | 379 APIPermission::ID permission = APIPermission::kInvalid; |
379 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( | 380 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( |
380 browser_pref, &event_name, &permission); | 381 browser_pref, &event_name, &permission); |
381 DCHECK(rv); | 382 DCHECK(rv); |
382 | 383 |
383 base::ListValue args; | 384 base::ListValue args; |
384 base::DictionaryValue* dict = new base::DictionaryValue(); | |
385 args.Append(dict); | |
386 const PrefService::Preference* pref = | 385 const PrefService::Preference* pref = |
387 pref_service->FindPreference(browser_pref.c_str()); | 386 pref_service->FindPreference(browser_pref.c_str()); |
388 CHECK(pref); | 387 CHECK(pref); |
389 PrefTransformerInterface* transformer = | 388 PrefTransformerInterface* transformer = |
390 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); | 389 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); |
391 base::Value* transformed_value = | 390 base::Value* transformed_value = |
392 transformer->BrowserToExtensionPref(pref->GetValue()); | 391 transformer->BrowserToExtensionPref(pref->GetValue()); |
393 if (!transformed_value) { | 392 if (!transformed_value) { |
394 LOG(ERROR) << ErrorUtils::FormatErrorMessage(kConversionErrorMessage, | 393 LOG(ERROR) << ErrorUtils::FormatErrorMessage(kConversionErrorMessage, |
395 pref->name()); | 394 pref->name()); |
396 return; | 395 return; |
397 } | 396 } |
398 | 397 |
| 398 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
399 dict->Set(keys::kValue, transformed_value); | 399 dict->Set(keys::kValue, transformed_value); |
400 if (incognito) { | 400 if (incognito) { |
401 ExtensionPrefs* ep = ExtensionPrefs::Get(profile_); | 401 ExtensionPrefs* ep = ExtensionPrefs::Get(profile_); |
402 dict->SetBoolean(keys::kIncognitoSpecific, | 402 dict->SetBoolean(keys::kIncognitoSpecific, |
403 ep->HasIncognitoPrefValue(browser_pref)); | 403 ep->HasIncognitoPrefValue(browser_pref)); |
404 } | 404 } |
| 405 args.Append(std::move(dict)); |
405 | 406 |
406 // TODO(kalman): Have a histogram value for each pref type. | 407 // TODO(kalman): Have a histogram value for each pref type. |
407 // This isn't so important for the current use case of these | 408 // This isn't so important for the current use case of these |
408 // histograms, which is to track which event types are waking up event | 409 // histograms, which is to track which event types are waking up event |
409 // pages, or which are delivered to persistent background pages. Simply | 410 // pages, or which are delivered to persistent background pages. Simply |
410 // "a setting changed" is enough detail for that. However if we try to | 411 // "a setting changed" is enough detail for that. However if we try to |
411 // use these histograms for any fine-grained logic (like removing the | 412 // use these histograms for any fine-grained logic (like removing the |
412 // string event name altogether), or if we discover this event is | 413 // string event name altogether), or if we discover this event is |
413 // firing a lot and want to understand that better, then this will need | 414 // firing a lot and want to understand that better, then this will need |
414 // to change. | 415 // to change. |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) { | 797 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) { |
797 return false; | 798 return false; |
798 } | 799 } |
799 | 800 |
800 PreferenceAPI::Get(GetProfile()) | 801 PreferenceAPI::Get(GetProfile()) |
801 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); | 802 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); |
802 return true; | 803 return true; |
803 } | 804 } |
804 | 805 |
805 } // namespace extensions | 806 } // namespace extensions |
OLD | NEW |