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