OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_EXTENSION_SETTINGS_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "chrome/browser/extensions/extension_function.h" |
| 11 #include "chrome/browser/extensions/extension_settings.h" |
| 12 #include "chrome/browser/extensions/extension_settings_storage.h" |
| 13 |
| 14 // Superclass of all settings functions. |
| 15 class SettingsFunction : public AsyncExtensionFunction { |
| 16 public: |
| 17 // Extension settings function implementations should do their work here, and |
| 18 // either run a StorageResultCallback or fill the function result / call |
| 19 // SendResponse themselves. |
| 20 // The exception is that implementations can return false to immediately |
| 21 // call SendResponse(false), for compliance with EXTENSION_FUNCTION_VALIDATE. |
| 22 virtual bool RunWithStorageImpl(ExtensionSettingsStorage* storage) = 0; |
| 23 |
| 24 virtual bool RunImpl() OVERRIDE; |
| 25 |
| 26 // Callback from all storage methods (Get/Set/Remove/Clear) which sets the |
| 27 // appropriate fields of the extension function (result/error) and sends a |
| 28 // response. |
| 29 // Declared here to access to the protected members of ExtensionFunction. |
| 30 class StorageResultCallback : public ExtensionSettingsStorage::Callback { |
| 31 public: |
| 32 explicit StorageResultCallback(SettingsFunction* settings_function); |
| 33 virtual ~StorageResultCallback(); |
| 34 virtual void OnSuccess(DictionaryValue* settings) OVERRIDE; |
| 35 virtual void OnFailure(const std::string& message) OVERRIDE; |
| 36 |
| 37 private: |
| 38 scoped_refptr<SettingsFunction> settings_function_; |
| 39 }; |
| 40 |
| 41 private: |
| 42 // Callback method from GetStorage(); delegates to RunWithStorageImpl. |
| 43 void RunWithStorage(ExtensionSettingsStorage* storage); |
| 44 }; |
| 45 |
| 46 class GetSettingsFunction : public SettingsFunction { |
| 47 public: |
| 48 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get"); |
| 49 |
| 50 protected: |
| 51 virtual bool RunWithStorageImpl(ExtensionSettingsStorage* storage) OVERRIDE; |
| 52 }; |
| 53 |
| 54 class SetSettingsFunction : public SettingsFunction { |
| 55 public: |
| 56 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set"); |
| 57 |
| 58 protected: |
| 59 virtual bool RunWithStorageImpl(ExtensionSettingsStorage* storage) OVERRIDE; |
| 60 }; |
| 61 |
| 62 class RemoveSettingsFunction : public SettingsFunction { |
| 63 public: |
| 64 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove"); |
| 65 |
| 66 protected: |
| 67 virtual bool RunWithStorageImpl(ExtensionSettingsStorage* storage) OVERRIDE; |
| 68 }; |
| 69 |
| 70 class ClearSettingsFunction : public SettingsFunction { |
| 71 public: |
| 72 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear"); |
| 73 |
| 74 protected: |
| 75 virtual bool RunWithStorageImpl(ExtensionSettingsStorage* storage) OVERRIDE; |
| 76 }; |
| 77 |
| 78 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_ |
OLD | NEW |