OLD | NEW |
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 "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 PrefService* DirectSettingFunctionBase::GetPrefService() { | 22 PrefService* DirectSettingFunctionBase::GetPrefService() { |
23 return GetProfile()->GetPrefs(); | 23 return GetProfile()->GetPrefs(); |
24 } | 24 } |
25 | 25 |
26 bool DirectSettingFunctionBase::IsCalledFromComponentExtension() { | 26 bool DirectSettingFunctionBase::IsCalledFromComponentExtension() { |
27 return GetExtension()->location() == Manifest::COMPONENT; | 27 return GetExtension()->location() == Manifest::COMPONENT; |
28 } | 28 } |
29 | 29 |
30 GetDirectSettingFunction::GetDirectSettingFunction() {} | 30 GetDirectSettingFunction::GetDirectSettingFunction() {} |
31 | 31 |
32 bool GetDirectSettingFunction::RunImpl() { | 32 bool GetDirectSettingFunction::RunSync() { |
33 EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); | 33 EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); |
34 | 34 |
35 std::string pref_key; | 35 std::string pref_key; |
36 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | 36 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); |
37 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) | 37 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) |
38 ->IsPreferenceOnWhitelist(pref_key)); | 38 ->IsPreferenceOnWhitelist(pref_key)); |
39 | 39 |
40 const PrefService::Preference* preference = | 40 const PrefService::Preference* preference = |
41 GetPrefService()->FindPreference(pref_key.c_str()); | 41 GetPrefService()->FindPreference(pref_key.c_str()); |
42 EXTENSION_FUNCTION_VALIDATE(preference); | 42 EXTENSION_FUNCTION_VALIDATE(preference); |
43 const base::Value* value = preference->GetValue(); | 43 const base::Value* value = preference->GetValue(); |
44 | 44 |
45 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 45 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
46 result->Set(preference_api_constants::kValue, value->DeepCopy()); | 46 result->Set(preference_api_constants::kValue, value->DeepCopy()); |
47 SetResult(result.release()); | 47 SetResult(result.release()); |
48 | 48 |
49 return true; | 49 return true; |
50 } | 50 } |
51 | 51 |
52 GetDirectSettingFunction::~GetDirectSettingFunction() {} | 52 GetDirectSettingFunction::~GetDirectSettingFunction() {} |
53 | 53 |
54 SetDirectSettingFunction::SetDirectSettingFunction() {} | 54 SetDirectSettingFunction::SetDirectSettingFunction() {} |
55 | 55 |
56 bool SetDirectSettingFunction::RunImpl() { | 56 bool SetDirectSettingFunction::RunSync() { |
57 EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); | 57 EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); |
58 | 58 |
59 std::string pref_key; | 59 std::string pref_key; |
60 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | 60 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); |
61 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) | 61 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) |
62 ->IsPreferenceOnWhitelist(pref_key)); | 62 ->IsPreferenceOnWhitelist(pref_key)); |
63 | 63 |
64 base::DictionaryValue* details = NULL; | 64 base::DictionaryValue* details = NULL; |
65 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); | 65 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
66 | 66 |
(...skipping 10 matching lines...) Expand all Loading... |
77 | 77 |
78 pref_service->Set(pref_key.c_str(), *value); | 78 pref_service->Set(pref_key.c_str(), *value); |
79 | 79 |
80 return true; | 80 return true; |
81 } | 81 } |
82 | 82 |
83 SetDirectSettingFunction::~SetDirectSettingFunction() {} | 83 SetDirectSettingFunction::~SetDirectSettingFunction() {} |
84 | 84 |
85 ClearDirectSettingFunction::ClearDirectSettingFunction() {} | 85 ClearDirectSettingFunction::ClearDirectSettingFunction() {} |
86 | 86 |
87 bool ClearDirectSettingFunction::RunImpl() { | 87 bool ClearDirectSettingFunction::RunSync() { |
88 EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); | 88 EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); |
89 | 89 |
90 std::string pref_key; | 90 std::string pref_key; |
91 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); | 91 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); |
92 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) | 92 EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) |
93 ->IsPreferenceOnWhitelist(pref_key)); | 93 ->IsPreferenceOnWhitelist(pref_key)); |
94 GetPrefService()->ClearPref(pref_key.c_str()); | 94 GetPrefService()->ClearPref(pref_key.c_str()); |
95 | 95 |
96 return true; | 96 return true; |
97 } | 97 } |
98 | 98 |
99 ClearDirectSettingFunction::~ClearDirectSettingFunction() {} | 99 ClearDirectSettingFunction::~ClearDirectSettingFunction() {} |
100 | 100 |
101 } // namespace chromedirectsetting | 101 } // namespace chromedirectsetting |
102 } // namespace extensions | 102 } // namespace extensions |
103 | 103 |
OLD | NEW |