| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | |
| 11 #include "chrome/browser/extensions/api/storage/settings_observer.h" | |
| 12 #include "chrome/browser/extensions/extension_function.h" | |
| 13 #include "chrome/browser/value_store/value_store.h" | |
| 14 | |
| 15 namespace extensions { | |
| 16 | |
| 17 // Superclass of all settings functions. | |
| 18 class SettingsFunction : public AsyncExtensionFunction { | |
| 19 protected: | |
| 20 SettingsFunction(); | |
| 21 virtual ~SettingsFunction(); | |
| 22 | |
| 23 // ExtensionFunction: | |
| 24 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; | |
| 25 virtual bool RunImpl() OVERRIDE; | |
| 26 | |
| 27 // Extension settings function implementations should do their work here. | |
| 28 // The SettingsFrontend makes sure this is posted to the appropriate thread. | |
| 29 // Implementations should fill in args themselves, though (like RunImpl) | |
| 30 // may return false to imply failure. | |
| 31 virtual bool RunWithStorage(ValueStore* storage) = 0; | |
| 32 | |
| 33 // Sets error_ or result_ depending on the value of a storage ReadResult, and | |
| 34 // returns whether the result implies success (i.e. !error). | |
| 35 bool UseReadResult(ValueStore::ReadResult result); | |
| 36 | |
| 37 // Sets error_ depending on the value of a storage WriteResult, sends a | |
| 38 // change notification if needed, and returns whether the result implies | |
| 39 // success (i.e. !error). | |
| 40 bool UseWriteResult(ValueStore::WriteResult result); | |
| 41 | |
| 42 private: | |
| 43 // Called via PostTask from RunImpl. Calls RunWithStorage and then | |
| 44 // SendResponse with its success value. | |
| 45 void AsyncRunWithStorage(ValueStore* storage); | |
| 46 | |
| 47 // The settings namespace the call was for. For example, SYNC if the API | |
| 48 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. | |
| 49 settings_namespace::Namespace settings_namespace_; | |
| 50 | |
| 51 // Observers, cached so that it's only grabbed from the UI thread. | |
| 52 scoped_refptr<SettingsObserverList> observers_; | |
| 53 }; | |
| 54 | |
| 55 class StorageGetFunction : public SettingsFunction { | |
| 56 public: | |
| 57 DECLARE_EXTENSION_FUNCTION_NAME("storage.get"); | |
| 58 | |
| 59 protected: | |
| 60 virtual ~StorageGetFunction() {} | |
| 61 | |
| 62 // SettingsFunction: | |
| 63 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | |
| 64 }; | |
| 65 | |
| 66 class StorageSetFunction : public SettingsFunction { | |
| 67 public: | |
| 68 DECLARE_EXTENSION_FUNCTION_NAME("storage.set"); | |
| 69 | |
| 70 protected: | |
| 71 virtual ~StorageSetFunction() {} | |
| 72 | |
| 73 // SettingsFunction: | |
| 74 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | |
| 75 | |
| 76 // ExtensionFunction: | |
| 77 virtual void GetQuotaLimitHeuristics( | |
| 78 QuotaLimitHeuristics* heuristics) const OVERRIDE; | |
| 79 }; | |
| 80 | |
| 81 class StorageRemoveFunction : public SettingsFunction { | |
| 82 public: | |
| 83 DECLARE_EXTENSION_FUNCTION_NAME("storage.remove"); | |
| 84 | |
| 85 protected: | |
| 86 virtual ~StorageRemoveFunction() {} | |
| 87 | |
| 88 // SettingsFunction: | |
| 89 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | |
| 90 | |
| 91 // ExtensionFunction: | |
| 92 virtual void GetQuotaLimitHeuristics( | |
| 93 QuotaLimitHeuristics* heuristics) const OVERRIDE; | |
| 94 }; | |
| 95 | |
| 96 class StorageClearFunction : public SettingsFunction { | |
| 97 public: | |
| 98 DECLARE_EXTENSION_FUNCTION_NAME("storage.clear"); | |
| 99 | |
| 100 protected: | |
| 101 virtual ~StorageClearFunction() {} | |
| 102 | |
| 103 // SettingsFunction: | |
| 104 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | |
| 105 | |
| 106 // ExtensionFunction: | |
| 107 virtual void GetQuotaLimitHeuristics( | |
| 108 QuotaLimitHeuristics* heuristics) const OVERRIDE; | |
| 109 }; | |
| 110 | |
| 111 class StorageGetBytesInUseFunction : public SettingsFunction { | |
| 112 public: | |
| 113 DECLARE_EXTENSION_FUNCTION_NAME("storage.getBytesInUse"); | |
| 114 | |
| 115 protected: | |
| 116 virtual ~StorageGetBytesInUseFunction() {} | |
| 117 | |
| 118 // SettingsFunction: | |
| 119 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | |
| 120 }; | |
| 121 | |
| 122 } // namespace extensions | |
| 123 | |
| 124 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_STORAGE_API_H_ | |
| OLD | NEW |