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

Side by Side Diff: chrome/browser/extensions/api/preference/preference_api.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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) 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 <utility> 10 #include <utility>
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 // Mapping from extension pref keys to browser pref keys and permissions. 336 // Mapping from extension pref keys to browser pref keys and permissions.
337 PrefMap mapping_; 337 PrefMap mapping_;
338 338
339 // Mapping from browser pref keys to extension event names and permissions. 339 // Mapping from browser pref keys to extension event names and permissions.
340 PrefMap event_mapping_; 340 PrefMap event_mapping_;
341 341
342 // Mapping from browser pref keys to transformers. 342 // Mapping from browser pref keys to transformers.
343 std::map<std::string, PrefTransformerInterface*> transformers_; 343 std::map<std::string, PrefTransformerInterface*> transformers_;
344 344
345 scoped_ptr<PrefTransformerInterface> identity_transformer_; 345 std::unique_ptr<PrefTransformerInterface> identity_transformer_;
346 346
347 DISALLOW_COPY_AND_ASSIGN(PrefMapping); 347 DISALLOW_COPY_AND_ASSIGN(PrefMapping);
348 }; 348 };
349 349
350 } // namespace 350 } // namespace
351 351
352 PreferenceEventRouter::PreferenceEventRouter(Profile* profile) 352 PreferenceEventRouter::PreferenceEventRouter(Profile* profile)
353 : profile_(profile) { 353 : profile_(profile) {
354 registrar_.Init(profile_->GetPrefs()); 354 registrar_.Init(profile_->GetPrefs());
355 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs()); 355 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs());
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (!ValidateBrowserPref( 631 if (!ValidateBrowserPref(
632 pref_key, PreferenceFunction::PERMISSION_TYPE_READ, &browser_pref)) { 632 pref_key, PreferenceFunction::PERMISSION_TYPE_READ, &browser_pref)) {
633 return false; 633 return false;
634 } 634 }
635 PrefService* prefs = incognito ? GetProfile()->GetOffTheRecordPrefs() 635 PrefService* prefs = incognito ? GetProfile()->GetOffTheRecordPrefs()
636 : GetProfile()->GetPrefs(); 636 : GetProfile()->GetPrefs();
637 const PrefService::Preference* pref = 637 const PrefService::Preference* pref =
638 prefs->FindPreference(browser_pref.c_str()); 638 prefs->FindPreference(browser_pref.c_str());
639 CHECK(pref); 639 CHECK(pref);
640 640
641 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); 641 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
642 642
643 // Retrieve level of control. 643 // Retrieve level of control.
644 std::string level_of_control = helpers::GetLevelOfControl( 644 std::string level_of_control = helpers::GetLevelOfControl(
645 GetProfile(), extension_id(), browser_pref, incognito); 645 GetProfile(), extension_id(), browser_pref, incognito);
646 result->SetString(keys::kLevelOfControl, level_of_control); 646 result->SetString(keys::kLevelOfControl, level_of_control);
647 647
648 // Retrieve pref value. 648 // Retrieve pref value.
649 PrefTransformerInterface* transformer = 649 PrefTransformerInterface* transformer =
650 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 650 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
651 base::Value* transformed_value = 651 base::Value* transformed_value =
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile()); 723 ExtensionPrefs* prefs = ExtensionPrefs::Get(GetProfile());
724 const PrefService::Preference* pref = 724 const PrefService::Preference* pref =
725 prefs->pref_service()->FindPreference(browser_pref.c_str()); 725 prefs->pref_service()->FindPreference(browser_pref.c_str());
726 CHECK(pref); 726 CHECK(pref);
727 727
728 // Validate new value. 728 // Validate new value.
729 PrefTransformerInterface* transformer = 729 PrefTransformerInterface* transformer =
730 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 730 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
731 std::string error; 731 std::string error;
732 bool bad_message = false; 732 bool bad_message = false;
733 scoped_ptr<base::Value> browser_pref_value( 733 std::unique_ptr<base::Value> browser_pref_value(
734 transformer->ExtensionToBrowserPref(value, &error, &bad_message)); 734 transformer->ExtensionToBrowserPref(value, &error, &bad_message));
735 if (!browser_pref_value) { 735 if (!browser_pref_value) {
736 error_ = error; 736 error_ = error;
737 bad_message_ = bad_message; 737 bad_message_ = bad_message;
738 return false; 738 return false;
739 } 739 }
740 EXTENSION_FUNCTION_VALIDATE(browser_pref_value->GetType() == pref->GetType()); 740 EXTENSION_FUNCTION_VALIDATE(browser_pref_value->GetType() == pref->GetType());
741 741
742 // Validate also that the stored value can be converted back by the 742 // Validate also that the stored value can be converted back by the
743 // transformer. 743 // transformer.
744 scoped_ptr<base::Value> extensionPrefValue( 744 std::unique_ptr<base::Value> extensionPrefValue(
745 transformer->BrowserToExtensionPref(browser_pref_value.get())); 745 transformer->BrowserToExtensionPref(browser_pref_value.get()));
746 if (!extensionPrefValue) { 746 if (!extensionPrefValue) {
747 error_ = ErrorUtils::FormatErrorMessage(kConversionErrorMessage, 747 error_ = ErrorUtils::FormatErrorMessage(kConversionErrorMessage,
748 pref->name()); 748 pref->name());
749 bad_message_ = true; 749 bad_message_ = true;
750 return false; 750 return false;
751 } 751 }
752 752
753 PreferenceAPI::Get(GetProfile())->SetExtensionControlledPref( 753 PreferenceAPI::Get(GetProfile())->SetExtensionControlledPref(
754 extension_id(), browser_pref, scope, browser_pref_value.release()); 754 extension_id(), browser_pref, scope, browser_pref_value.release());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) { 793 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) {
794 return false; 794 return false;
795 } 795 }
796 796
797 PreferenceAPI::Get(GetProfile()) 797 PreferenceAPI::Get(GetProfile())
798 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 798 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
799 return true; 799 return true;
800 } 800 }
801 801
802 } // namespace extensions 802 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698