| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_storage.h" | 14 #include "chrome/browser/extensions/settings/settings_storage.h" |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 // Superclass of all settings functions. | 18 // Superclass of all settings functions. |
| 18 class SettingsFunction : public AsyncExtensionFunction { | 19 class SettingsFunction : public AsyncExtensionFunction { |
| 20 public: |
| 21 SettingsFunction(); |
| 22 virtual ~SettingsFunction(); |
| 23 |
| 19 protected: | 24 protected: |
| 20 virtual bool RunImpl() OVERRIDE; | 25 virtual bool RunImpl() OVERRIDE; |
| 21 | 26 |
| 22 // Extension settings function implementations should do their work here. | 27 // Extension settings function implementations should do their work here. |
| 23 // This runs on the FILE thread. | 28 // This runs on the FILE thread. |
| 24 // | 29 // |
| 25 // Implementations should fill in args themselves, though (like RunImpl) | 30 // Implementations should fill in args themselves, though (like RunImpl) |
| 26 // may return false to imply failure. | 31 // may return false to imply failure. |
| 27 virtual bool RunWithStorage( | 32 virtual bool RunWithStorage(SettingsStorage* storage) = 0; |
| 28 scoped_refptr<SettingsObserverList> observers, | |
| 29 SettingsStorage* storage) = 0; | |
| 30 | 33 |
| 31 // Sets error_ or result_ depending on the value of a storage ReadResult, and | 34 // Sets error_ or result_ depending on the value of a storage ReadResult, and |
| 32 // returns whether the result implies success (i.e. !error). | 35 // returns whether the result implies success (i.e. !error). |
| 33 bool UseReadResult( | 36 bool UseReadResult(const SettingsStorage::ReadResult& result); |
| 34 const SettingsStorage::ReadResult& result); | |
| 35 | 37 |
| 36 // Sets error_ depending on the value of a storage WriteResult, sends a | 38 // Sets error_ depending on the value of a storage WriteResult, sends a |
| 37 // change notification if needed, and returns whether the result implies | 39 // change notification if needed, and returns whether the result implies |
| 38 // success (i.e. !error). | 40 // success (i.e. !error). |
| 39 bool UseWriteResult( | 41 bool UseWriteResult(const SettingsStorage::WriteResult& result); |
| 40 scoped_refptr<SettingsObserverList> observers, | |
| 41 const SettingsStorage::WriteResult& result); | |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 // Called via PostTask from RunImpl. Calls RunWithStorage and then | 44 // Called via PostTask from RunImpl. Calls RunWithStorage and then |
| 45 // SendReponse with its success value. | 45 // SendReponse with its success value. |
| 46 void RunWithStorageOnFileThread( | 46 void RunWithStorageOnFileThread(SettingsStorage* storage); |
| 47 scoped_refptr<SettingsObserverList> observers, | 47 |
| 48 SettingsStorage* storage); | 48 // The settings namespace the call was for. For example, SYNC if the API |
| 49 // call was chrome.settings.experimental.sync..., LOCAL if .local, etc. |
| 50 settings_namespace::Namespace settings_namespace_; |
| 51 |
| 52 // Observers, cached so that it's only grabbed from the UI thread. |
| 53 scoped_refptr<SettingsObserverList> observers_; |
| 49 }; | 54 }; |
| 50 | 55 |
| 51 class GetSettingsFunction : public SettingsFunction { | 56 class GetSettingsFunction : public SettingsFunction { |
| 52 public: | 57 public: |
| 53 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get"); | 58 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get"); |
| 54 | 59 |
| 55 protected: | 60 protected: |
| 56 virtual bool RunWithStorage( | 61 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 57 scoped_refptr<SettingsObserverList> observers, | |
| 58 SettingsStorage* storage) OVERRIDE; | |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 class SetSettingsFunction : public SettingsFunction { | 64 class SetSettingsFunction : public SettingsFunction { |
| 62 public: | 65 public: |
| 63 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set"); | 66 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set"); |
| 64 | 67 |
| 65 protected: | 68 protected: |
| 66 virtual bool RunWithStorage( | 69 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 67 scoped_refptr<SettingsObserverList> observers, | |
| 68 SettingsStorage* storage) OVERRIDE; | |
| 69 | 70 |
| 70 virtual void GetQuotaLimitHeuristics( | 71 virtual void GetQuotaLimitHeuristics( |
| 71 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 72 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 72 }; | 73 }; |
| 73 | 74 |
| 74 class RemoveSettingsFunction : public SettingsFunction { | 75 class RemoveSettingsFunction : public SettingsFunction { |
| 75 public: | 76 public: |
| 76 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove"); | 77 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove"); |
| 77 | 78 |
| 78 protected: | 79 protected: |
| 79 virtual bool RunWithStorage( | 80 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 80 scoped_refptr<SettingsObserverList> observers, | |
| 81 SettingsStorage* storage) OVERRIDE; | |
| 82 | 81 |
| 83 virtual void GetQuotaLimitHeuristics( | 82 virtual void GetQuotaLimitHeuristics( |
| 84 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 83 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 85 }; | 84 }; |
| 86 | 85 |
| 87 class ClearSettingsFunction : public SettingsFunction { | 86 class ClearSettingsFunction : public SettingsFunction { |
| 88 public: | 87 public: |
| 89 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear"); | 88 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear"); |
| 90 | 89 |
| 91 protected: | 90 protected: |
| 92 virtual bool RunWithStorage( | 91 virtual bool RunWithStorage(SettingsStorage* storage) OVERRIDE; |
| 93 scoped_refptr<SettingsObserverList> observers, | |
| 94 SettingsStorage* storage) OVERRIDE; | |
| 95 | 92 |
| 96 virtual void GetQuotaLimitHeuristics( | 93 virtual void GetQuotaLimitHeuristics( |
| 97 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 94 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 98 }; | 95 }; |
| 99 | 96 |
| 100 } // namespace extensions | 97 } // namespace extensions |
| 101 | 98 |
| 102 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ | 99 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_API_H_ |
| OLD | NEW |