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

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

Issue 2298493003: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: fix Created 4 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chrome_direct_setting.h" 5 #include "chrome/browser/extensions/api/preference/chrome_direct_setting.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/extensions/api/preference/chrome_direct_setting_api.h" 12 #include "chrome/browser/extensions/api/preference/chrome_direct_setting_api.h"
13 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" 13 #include "chrome/browser/extensions/api/preference/preference_api_constants.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
16 16
17 namespace extensions { 17 namespace extensions {
18 namespace chromedirectsetting { 18 namespace chromedirectsetting {
19 19
20 DirectSettingFunctionBase::DirectSettingFunctionBase() {} 20 DirectSettingFunctionBase::DirectSettingFunctionBase() {}
21 21
22 DirectSettingFunctionBase::~DirectSettingFunctionBase() {} 22 DirectSettingFunctionBase::~DirectSettingFunctionBase() {}
23 23
24 PrefService* DirectSettingFunctionBase::GetPrefService() { 24 PrefService* DirectSettingFunctionBase::GetPrefService() {
25 return GetProfile()->GetPrefs(); 25 return Profile::FromBrowserContext(browser_context())->GetPrefs();
26 } 26 }
27 27
28 GetDirectSettingFunction::GetDirectSettingFunction() {} 28 GetDirectSettingFunction::GetDirectSettingFunction() {}
29 29
30 bool GetDirectSettingFunction::RunSync() { 30 ExtensionFunction::ResponseAction GetDirectSettingFunction::Run() {
31 std::string pref_key; 31 std::string pref_key;
32 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); 32 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
33 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) 33 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(browser_context())
34 ->IsPreferenceOnWhitelist(pref_key)); 34 ->IsPreferenceOnWhitelist(pref_key));
35 35
36 const PrefService::Preference* preference = 36 const PrefService::Preference* preference =
37 GetPrefService()->FindPreference(pref_key.c_str()); 37 GetPrefService()->FindPreference(pref_key.c_str());
38 EXTENSION_FUNCTION_VALIDATE(preference); 38 EXTENSION_FUNCTION_VALIDATE(preference);
39 const base::Value* value = preference->GetValue(); 39 const base::Value* value = preference->GetValue();
40 40
41 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); 41 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
42 result->Set(preference_api_constants::kValue, value->DeepCopy()); 42 result->Set(preference_api_constants::kValue, value->DeepCopy());
43 SetResult(std::move(result)); 43 return RespondNow(OneArgument(std::move(result)));
44
45 return true;
46 } 44 }
47 45
48 GetDirectSettingFunction::~GetDirectSettingFunction() {} 46 GetDirectSettingFunction::~GetDirectSettingFunction() {}
49 47
50 SetDirectSettingFunction::SetDirectSettingFunction() {} 48 SetDirectSettingFunction::SetDirectSettingFunction() {}
51 49
52 bool SetDirectSettingFunction::RunSync() { 50 ExtensionFunction::ResponseAction SetDirectSettingFunction::Run() {
53 std::string pref_key; 51 std::string pref_key;
54 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); 52 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
55 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) 53 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(browser_context())
56 ->IsPreferenceOnWhitelist(pref_key)); 54 ->IsPreferenceOnWhitelist(pref_key));
57 55
58 base::DictionaryValue* details = NULL; 56 base::DictionaryValue* details = NULL;
59 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); 57 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details));
60 58
61 base::Value* value = NULL; 59 base::Value* value = NULL;
62 EXTENSION_FUNCTION_VALIDATE( 60 EXTENSION_FUNCTION_VALIDATE(
63 details->Get(preference_api_constants::kValue, &value)); 61 details->Get(preference_api_constants::kValue, &value));
64 62
65 PrefService* pref_service = GetPrefService(); 63 PrefService* pref_service = GetPrefService();
66 const PrefService::Preference* preference = 64 const PrefService::Preference* preference =
67 pref_service->FindPreference(pref_key.c_str()); 65 pref_service->FindPreference(pref_key.c_str());
68 EXTENSION_FUNCTION_VALIDATE(preference); 66 EXTENSION_FUNCTION_VALIDATE(preference);
69 67
70 EXTENSION_FUNCTION_VALIDATE(value->GetType() == preference->GetType()); 68 EXTENSION_FUNCTION_VALIDATE(value->GetType() == preference->GetType());
71 69
72 pref_service->Set(pref_key.c_str(), *value); 70 pref_service->Set(pref_key.c_str(), *value);
73 71
74 return true; 72 return RespondNow(NoArguments());
75 } 73 }
76 74
77 SetDirectSettingFunction::~SetDirectSettingFunction() {} 75 SetDirectSettingFunction::~SetDirectSettingFunction() {}
78 76
79 ClearDirectSettingFunction::ClearDirectSettingFunction() {} 77 ClearDirectSettingFunction::ClearDirectSettingFunction() {}
80 78
81 bool ClearDirectSettingFunction::RunSync() { 79 ExtensionFunction::ResponseAction ClearDirectSettingFunction::Run() {
82 std::string pref_key; 80 std::string pref_key;
83 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); 81 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key));
84 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) 82 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(browser_context())
85 ->IsPreferenceOnWhitelist(pref_key)); 83 ->IsPreferenceOnWhitelist(pref_key));
86 GetPrefService()->ClearPref(pref_key.c_str()); 84 GetPrefService()->ClearPref(pref_key.c_str());
87 85
88 return true; 86 return RespondNow(NoArguments());
89 } 87 }
90 88
91 ClearDirectSettingFunction::~ClearDirectSettingFunction() {} 89 ClearDirectSettingFunction::~ClearDirectSettingFunction() {}
92 90
93 } // namespace chromedirectsetting 91 } // namespace chromedirectsetting
94 } // namespace extensions 92 } // namespace extensions
95 93
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/preference/chrome_direct_setting.h ('k') | chrome/browser/extensions/extension_tab_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698