| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 12 #include "chrome/browser/extensions/settings/settings_backend.h" | 12 #include "chrome/browser/extensions/settings/settings_backend.h" |
| 13 #include "chrome/browser/extensions/settings/settings_namespace.h" | 13 #include "chrome/browser/extensions/settings/settings_namespace.h" |
| 14 #include "chrome/browser/extensions/settings/settings_storage.h" | 14 #include "chrome/browser/extensions/settings/settings_storage.h" |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 // Superclass of all settings functions. | 18 // Superclass of all settings functions. |
| 19 // | 19 // |
| 20 // NOTE: these all have "*SettingsFunction" names left over from when the API | 20 // NOTE: these all have "*SettingsFunction" names left over from when the API |
| 21 // was called the "Settings API" (now "Storage API"). | 21 // was called the "Settings API" (now "Storage API"). |
| 22 // TODO(kalman): Rename these functions, and all files under | 22 // TODO(kalman): Rename these functions, and all files under |
| 23 // chrome/browser/extensions/settings. | 23 // chrome/browser/extensions/settings. |
| 24 class SettingsFunction : public AsyncExtensionFunction { | 24 class SettingsFunction : public AsyncExtensionFunction { |
| 25 public: | 25 protected: |
| 26 SettingsFunction(); | 26 SettingsFunction(); |
| 27 virtual ~SettingsFunction(); | 27 virtual ~SettingsFunction(); |
| 28 | 28 |
| 29 protected: | 29 // ExtensionFunction: |
| 30 virtual bool RunImpl() OVERRIDE; | 30 virtual bool RunImpl() OVERRIDE; |
| 31 | 31 |
| 32 // Extension settings function implementations should do their work here. | 32 // Extension settings function implementations should do their work here. |
| 33 // This runs on the FILE thread. | 33 // This runs on the FILE thread. |
| 34 // | 34 // |
| 35 // Implementations should fill in args themselves, though (like RunImpl) | 35 // Implementations should fill in args themselves, though (like RunImpl) |
| 36 // may return false to imply failure. | 36 // may return false to imply failure. |
| 37 virtual bool RunWithStorage(SettingsStorage* storage) = 0; | 37 virtual bool RunWithStorage(SettingsStorage* storage) = 0; |
| 38 | 38 |
| 39 // Sets error_ or result_ depending on the value of a storage ReadResult, and | 39 // Sets error_ or result_ depending on the value of a storage ReadResult, and |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 // Observers, cached so that it's only grabbed from the UI thread. | 57 // Observers, cached so that it's only grabbed from the UI thread. |
| 58 scoped_refptr<SettingsObserverList> observers_; | 58 scoped_refptr<SettingsObserverList> observers_; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class GetSettingsFunction : public SettingsFunction { | 61 class GetSettingsFunction : public SettingsFunction { |
| 62 public: | 62 public: |
| 63 DECLARE_EXTENSION_FUNCTION_NAME("storage.get"); | 63 DECLARE_EXTENSION_FUNCTION_NAME("storage.get"); |
| 64 | 64 |
| 65 protected: | 65 protected: |
| 66 virtual ~GetSettingsFunction() {} |
| 67 |
| 68 // SettingsFunction: |
| 66 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; | 69 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 67 }; | 70 }; |
| 68 | 71 |
| 69 class SetSettingsFunction : public SettingsFunction { | 72 class SetSettingsFunction : public SettingsFunction { |
| 70 public: | 73 public: |
| 71 DECLARE_EXTENSION_FUNCTION_NAME("storage.set"); | 74 DECLARE_EXTENSION_FUNCTION_NAME("storage.set"); |
| 72 | 75 |
| 73 protected: | 76 protected: |
| 77 virtual ~SetSettingsFunction() {} |
| 78 |
| 79 // SettingsFunction: |
| 74 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; | 80 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 75 | 81 |
| 82 // ExtensionFunction: |
| 76 virtual void GetQuotaLimitHeuristics( | 83 virtual void GetQuotaLimitHeuristics( |
| 77 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 84 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 78 }; | 85 }; |
| 79 | 86 |
| 80 class RemoveSettingsFunction : public SettingsFunction { | 87 class RemoveSettingsFunction : public SettingsFunction { |
| 81 public: | 88 public: |
| 82 DECLARE_EXTENSION_FUNCTION_NAME("storage.remove"); | 89 DECLARE_EXTENSION_FUNCTION_NAME("storage.remove"); |
| 83 | 90 |
| 84 protected: | 91 protected: |
| 92 virtual ~RemoveSettingsFunction() {} |
| 93 |
| 94 // SettingsFunction: |
| 85 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; | 95 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 86 | 96 |
| 97 // ExtensionFunction: |
| 87 virtual void GetQuotaLimitHeuristics( | 98 virtual void GetQuotaLimitHeuristics( |
| 88 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 99 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 89 }; | 100 }; |
| 90 | 101 |
| 91 class ClearSettingsFunction : public SettingsFunction { | 102 class ClearSettingsFunction : public SettingsFunction { |
| 92 public: | 103 public: |
| 93 DECLARE_EXTENSION_FUNCTION_NAME("storage.clear"); | 104 DECLARE_EXTENSION_FUNCTION_NAME("storage.clear"); |
| 94 | 105 |
| 95 protected: | 106 protected: |
| 107 virtual ~ClearSettingsFunction() {} |
| 108 |
| 109 // SettingsFunction: |
| 96 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; | 110 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 97 | 111 |
| 112 // ExtensionFunction: |
| 98 virtual void GetQuotaLimitHeuristics( | 113 virtual void GetQuotaLimitHeuristics( |
| 99 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 114 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 100 }; | 115 }; |
| 101 | 116 |
| 102 class GetBytesInUseSettingsFunction : public SettingsFunction { | 117 class GetBytesInUseSettingsFunction : public SettingsFunction { |
| 103 public: | 118 public: |
| 104 DECLARE_EXTENSION_FUNCTION_NAME("storage.getBytesInUse"); | 119 DECLARE_EXTENSION_FUNCTION_NAME("storage.getBytesInUse"); |
| 105 | 120 |
| 106 protected: | 121 protected: |
| 122 virtual ~GetBytesInUseSettingsFunction() {} |
| 123 |
| 124 // SettingsFunction: |
| 107 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; | 125 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 108 }; | 126 }; |
| 109 | 127 |
| 110 } // namespace extensions | 128 } // namespace extensions |
| 111 | 129 |
| 112 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ | 130 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ |
| OLD | NEW |