| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ | 6 #define EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "extensions/browser/api/storage/settings_namespace.h" | 10 #include "extensions/browser/api/storage/settings_namespace.h" |
| 11 #include "extensions/browser/api/storage/settings_observer.h" | 11 #include "extensions/browser/api/storage/settings_observer.h" |
| 12 #include "extensions/browser/extension_function.h" | 12 #include "extensions/browser/extension_function.h" |
| 13 #include "extensions/browser/value_store/value_store.h" | 13 #include "extensions/browser/value_store/value_store.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 // Superclass of all settings functions. | 17 // Superclass of all settings functions. |
| 18 class SettingsFunction : public UIThreadExtensionFunction { | 18 class SettingsFunction : public UIThreadExtensionFunction { |
| 19 protected: | 19 protected: |
| 20 SettingsFunction(); | 20 SettingsFunction(); |
| 21 virtual ~SettingsFunction(); | 21 ~SettingsFunction() override; |
| 22 | 22 |
| 23 // ExtensionFunction: | 23 // ExtensionFunction: |
| 24 virtual bool ShouldSkipQuotaLimiting() const override; | 24 bool ShouldSkipQuotaLimiting() const override; |
| 25 virtual ResponseAction Run() override; | 25 ResponseAction Run() override; |
| 26 | 26 |
| 27 // Extension settings function implementations should do their work here. | 27 // Extension settings function implementations should do their work here. |
| 28 // The StorageFrontend makes sure this is posted to the appropriate thread. | 28 // The StorageFrontend makes sure this is posted to the appropriate thread. |
| 29 virtual ResponseValue RunWithStorage(ValueStore* storage) = 0; | 29 virtual ResponseValue RunWithStorage(ValueStore* storage) = 0; |
| 30 | 30 |
| 31 // Handles the |result| of a read function. | 31 // Handles the |result| of a read function. |
| 32 // - If the result succeeded, this will set |result_| and return. | 32 // - If the result succeeded, this will set |result_| and return. |
| 33 // - If |result| failed with a ValueStore::CORRUPTION error, this will call | 33 // - If |result| failed with a ValueStore::CORRUPTION error, this will call |
| 34 // RestoreStorageAndRetry(), and return that result. | 34 // RestoreStorageAndRetry(), and return that result. |
| 35 // - If the |result| failed with a different error, this will set |error_| | 35 // - If the |result| failed with a different error, this will set |error_| |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 // Observers, cached so that it's only grabbed from the UI thread. | 71 // Observers, cached so that it's only grabbed from the UI thread. |
| 72 scoped_refptr<SettingsObserverList> observers_; | 72 scoped_refptr<SettingsObserverList> observers_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class StorageStorageAreaGetFunction : public SettingsFunction { | 75 class StorageStorageAreaGetFunction : public SettingsFunction { |
| 76 public: | 76 public: |
| 77 DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) | 77 DECLARE_EXTENSION_FUNCTION("storage.get", STORAGE_GET) |
| 78 | 78 |
| 79 protected: | 79 protected: |
| 80 virtual ~StorageStorageAreaGetFunction() {} | 80 ~StorageStorageAreaGetFunction() override {} |
| 81 | 81 |
| 82 // SettingsFunction: | 82 // SettingsFunction: |
| 83 virtual ResponseValue RunWithStorage(ValueStore* storage) override; | 83 ResponseValue RunWithStorage(ValueStore* storage) override; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class StorageStorageAreaSetFunction : public SettingsFunction { | 86 class StorageStorageAreaSetFunction : public SettingsFunction { |
| 87 public: | 87 public: |
| 88 DECLARE_EXTENSION_FUNCTION("storage.set", STORAGE_SET) | 88 DECLARE_EXTENSION_FUNCTION("storage.set", STORAGE_SET) |
| 89 | 89 |
| 90 protected: | 90 protected: |
| 91 virtual ~StorageStorageAreaSetFunction() {} | 91 ~StorageStorageAreaSetFunction() override {} |
| 92 | 92 |
| 93 // SettingsFunction: | 93 // SettingsFunction: |
| 94 virtual ResponseValue RunWithStorage(ValueStore* storage) override; | 94 ResponseValue RunWithStorage(ValueStore* storage) override; |
| 95 | 95 |
| 96 // ExtensionFunction: | 96 // ExtensionFunction: |
| 97 virtual void GetQuotaLimitHeuristics( | 97 void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const override; |
| 98 QuotaLimitHeuristics* heuristics) const override; | |
| 99 }; | 98 }; |
| 100 | 99 |
| 101 class StorageStorageAreaRemoveFunction : public SettingsFunction { | 100 class StorageStorageAreaRemoveFunction : public SettingsFunction { |
| 102 public: | 101 public: |
| 103 DECLARE_EXTENSION_FUNCTION("storage.remove", STORAGE_REMOVE) | 102 DECLARE_EXTENSION_FUNCTION("storage.remove", STORAGE_REMOVE) |
| 104 | 103 |
| 105 protected: | 104 protected: |
| 106 virtual ~StorageStorageAreaRemoveFunction() {} | 105 ~StorageStorageAreaRemoveFunction() override {} |
| 107 | 106 |
| 108 // SettingsFunction: | 107 // SettingsFunction: |
| 109 virtual ResponseValue RunWithStorage(ValueStore* storage) override; | 108 ResponseValue RunWithStorage(ValueStore* storage) override; |
| 110 | 109 |
| 111 // ExtensionFunction: | 110 // ExtensionFunction: |
| 112 virtual void GetQuotaLimitHeuristics( | 111 void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const override; |
| 113 QuotaLimitHeuristics* heuristics) const override; | |
| 114 }; | 112 }; |
| 115 | 113 |
| 116 class StorageStorageAreaClearFunction : public SettingsFunction { | 114 class StorageStorageAreaClearFunction : public SettingsFunction { |
| 117 public: | 115 public: |
| 118 DECLARE_EXTENSION_FUNCTION("storage.clear", STORAGE_CLEAR) | 116 DECLARE_EXTENSION_FUNCTION("storage.clear", STORAGE_CLEAR) |
| 119 | 117 |
| 120 protected: | 118 protected: |
| 121 virtual ~StorageStorageAreaClearFunction() {} | 119 ~StorageStorageAreaClearFunction() override {} |
| 122 | 120 |
| 123 // SettingsFunction: | 121 // SettingsFunction: |
| 124 virtual ResponseValue RunWithStorage(ValueStore* storage) override; | 122 ResponseValue RunWithStorage(ValueStore* storage) override; |
| 125 | 123 |
| 126 // ExtensionFunction: | 124 // ExtensionFunction: |
| 127 virtual void GetQuotaLimitHeuristics( | 125 void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const override; |
| 128 QuotaLimitHeuristics* heuristics) const override; | |
| 129 }; | 126 }; |
| 130 | 127 |
| 131 class StorageStorageAreaGetBytesInUseFunction : public SettingsFunction { | 128 class StorageStorageAreaGetBytesInUseFunction : public SettingsFunction { |
| 132 public: | 129 public: |
| 133 DECLARE_EXTENSION_FUNCTION("storage.getBytesInUse", STORAGE_GETBYTESINUSE) | 130 DECLARE_EXTENSION_FUNCTION("storage.getBytesInUse", STORAGE_GETBYTESINUSE) |
| 134 | 131 |
| 135 protected: | 132 protected: |
| 136 virtual ~StorageStorageAreaGetBytesInUseFunction() {} | 133 ~StorageStorageAreaGetBytesInUseFunction() override {} |
| 137 | 134 |
| 138 // SettingsFunction: | 135 // SettingsFunction: |
| 139 virtual ResponseValue RunWithStorage(ValueStore* storage) override; | 136 ResponseValue RunWithStorage(ValueStore* storage) override; |
| 140 }; | 137 }; |
| 141 | 138 |
| 142 } // namespace extensions | 139 } // namespace extensions |
| 143 | 140 |
| 144 #endif // EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ | 141 #endif // EXTENSIONS_BROWSER_API_STORAGE_STORAGE_API_H_ |
| OLD | NEW |