| 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 | 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 "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
| 11 #include "chrome/browser/extensions/settings/settings_backend.h" | |
| 12 #include "chrome/browser/extensions/settings/settings_namespace.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" | 13 #include "chrome/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 // | 18 // |
| 19 // NOTE: these all have "*SettingsFunction" names left over from when the API | 19 // NOTE: these all have "*SettingsFunction" names left over from when the API |
| 20 // was called the "Settings API" (now "Storage API"). | 20 // was called the "Settings API" (now "Storage API"). |
| 21 // TODO(kalman): Rename these functions, and all files under | 21 // TODO(kalman): Rename these functions, and all files under |
| 22 // chrome/browser/extensions/settings. | 22 // chrome/browser/extensions/settings. |
| 23 class SettingsFunction : public AsyncExtensionFunction { | 23 class SettingsFunction : public AsyncExtensionFunction { |
| 24 protected: | 24 protected: |
| 25 SettingsFunction(); | 25 SettingsFunction(); |
| 26 virtual ~SettingsFunction(); | 26 virtual ~SettingsFunction(); |
| 27 | 27 |
| 28 // ExtensionFunction: | 28 // ExtensionFunction: |
| 29 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; | 29 virtual bool ShouldSkipQuotaLimiting() const OVERRIDE; |
| 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 // The SettingsFrontend makes sure this is posted to the appropriate thread. |
| 34 // | |
| 35 // Implementations should fill in args themselves, though (like RunImpl) | 34 // Implementations should fill in args themselves, though (like RunImpl) |
| 36 // may return false to imply failure. | 35 // may return false to imply failure. |
| 37 virtual bool RunWithStorage(ValueStore* storage) = 0; | 36 virtual bool RunWithStorage(ValueStore* storage) = 0; |
| 38 | 37 |
| 39 // Sets error_ or result_ depending on the value of a storage ReadResult, and | 38 // Sets error_ or result_ depending on the value of a storage ReadResult, and |
| 40 // returns whether the result implies success (i.e. !error). | 39 // returns whether the result implies success (i.e. !error). |
| 41 bool UseReadResult(ValueStore::ReadResult result); | 40 bool UseReadResult(ValueStore::ReadResult result); |
| 42 | 41 |
| 43 // Sets error_ depending on the value of a storage WriteResult, sends a | 42 // Sets error_ depending on the value of a storage WriteResult, sends a |
| 44 // change notification if needed, and returns whether the result implies | 43 // change notification if needed, and returns whether the result implies |
| 45 // success (i.e. !error). | 44 // success (i.e. !error). |
| 46 bool UseWriteResult(ValueStore::WriteResult result); | 45 bool UseWriteResult(ValueStore::WriteResult result); |
| 47 | 46 |
| 48 private: | 47 private: |
| 49 // Called via PostTask from RunImpl. Calls RunWithStorage and then | 48 // Called via PostTask from RunImpl. Calls RunWithStorage and then |
| 50 // SendReponse with its success value. | 49 // SendReponse with its success value. |
| 51 void RunWithStorageOnFileThread(ValueStore* storage); | 50 void AsyncRunWithStorage(ValueStore* storage); |
| 52 | 51 |
| 53 // The settings namespace the call was for. For example, SYNC if the API | 52 // The settings namespace the call was for. For example, SYNC if the API |
| 54 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. | 53 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. |
| 55 settings_namespace::Namespace settings_namespace_; | 54 settings_namespace::Namespace settings_namespace_; |
| 56 | 55 |
| 57 // Observers, cached so that it's only grabbed from the UI thread. | 56 // Observers, cached so that it's only grabbed from the UI thread. |
| 58 scoped_refptr<SettingsObserverList> observers_; | 57 scoped_refptr<SettingsObserverList> observers_; |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 class GetSettingsFunction : public SettingsFunction { | 60 class GetSettingsFunction : public SettingsFunction { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 protected: | 120 protected: |
| 122 virtual ~GetBytesInUseSettingsFunction() {} | 121 virtual ~GetBytesInUseSettingsFunction() {} |
| 123 | 122 |
| 124 // SettingsFunction: | 123 // SettingsFunction: |
| 125 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; | 124 virtual bool RunWithStorage(ValueStore* storage) OVERRIDE; |
| 126 }; | 125 }; |
| 127 | 126 |
| 128 } // namespace extensions | 127 } // namespace extensions |
| 129 | 128 |
| 130 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ | 129 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ |
| OLD | NEW |