OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_H__ |
| 7 |
| 8 #include "base/containers/hash_tables.h" |
| 9 #include "chrome/browser/extensions/extension_function.h" |
| 10 |
| 11 class PrefService; |
| 12 |
| 13 namespace extensions { |
| 14 namespace chromedirectsetting { |
| 15 |
| 16 typedef base::hash_set<std::string> PreferenceWhitelist; |
| 17 |
| 18 // Base class to host instance method helpers. |
| 19 class DirectSettingFunctionBase : public SyncExtensionFunction { |
| 20 protected: |
| 21 explicit DirectSettingFunctionBase() {} |
| 22 virtual ~DirectSettingFunctionBase() {} |
| 23 |
| 24 // Returns the user pref service. |
| 25 PrefService* GetPrefService(); |
| 26 |
| 27 // Returns true if the caller is a component extension. |
| 28 bool IsCalledFromComponentExtension(); |
| 29 |
| 30 // Returns true if the preference is on the whitelist. |
| 31 bool IsPreferenceOnWhitelist(const std::string &pref_key); |
| 32 |
| 33 private: |
| 34 // Creates the preference whitelist. |
| 35 static PreferenceWhitelist CreatePreferenceWhitelist(); |
| 36 |
| 37 static const PreferenceWhitelist preference_whitelist_; |
| 38 DISALLOW_COPY_AND_ASSIGN(DirectSettingFunctionBase); |
| 39 }; |
| 40 |
| 41 class GetDirectSettingFunction : public DirectSettingFunctionBase { |
| 42 public: |
| 43 DECLARE_EXTENSION_FUNCTION("types.private.ChromeDirectSetting.get", |
| 44 TYPES_PRIVATE_CHROMEDIRECTSETTING_GET) |
| 45 |
| 46 explicit GetDirectSettingFunction() {} |
| 47 |
| 48 protected: |
| 49 // ExtensionFunction: |
| 50 virtual bool RunImpl() OVERRIDE; |
| 51 |
| 52 private: |
| 53 virtual ~GetDirectSettingFunction() {} |
| 54 DISALLOW_COPY_AND_ASSIGN(GetDirectSettingFunction); |
| 55 }; |
| 56 |
| 57 class SetDirectSettingFunction : public DirectSettingFunctionBase { |
| 58 public: |
| 59 DECLARE_EXTENSION_FUNCTION("types.private.ChromeDirectSetting.set", |
| 60 TYPES_PRIVATE_CHROMEDIRECTSETTING_SET) |
| 61 |
| 62 explicit SetDirectSettingFunction() {} |
| 63 |
| 64 protected: |
| 65 // ExtensionFunction: |
| 66 virtual bool RunImpl() OVERRIDE; |
| 67 |
| 68 private: |
| 69 virtual ~SetDirectSettingFunction() {} |
| 70 DISALLOW_COPY_AND_ASSIGN(SetDirectSettingFunction); |
| 71 }; |
| 72 |
| 73 class ClearDirectSettingFunction : public DirectSettingFunctionBase { |
| 74 public: |
| 75 DECLARE_EXTENSION_FUNCTION("types.private.ChromeDirectSetting.clear", |
| 76 TYPES_PRIVATE_CHROMEDIRECTSETTING_CLEAR) |
| 77 |
| 78 explicit ClearDirectSettingFunction() {} |
| 79 |
| 80 protected: |
| 81 // ExtensionFunction: |
| 82 virtual bool RunImpl() OVERRIDE; |
| 83 |
| 84 private: |
| 85 virtual ~ClearDirectSettingFunction() {} |
| 86 DISALLOW_COPY_AND_ASSIGN(ClearDirectSettingFunction); |
| 87 }; |
| 88 |
| 89 } // namespace chromedirectsetting |
| 90 } // namespace extensions |
| 91 |
| 92 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_CHROME_DIRECT_SETTING_H__ |
| 93 |
OLD | NEW |