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_EXTENSION_SETTINGS_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_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 "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
11 #include "chrome/browser/extensions/extension_settings_backend.h" | 11 #include "chrome/browser/extensions/extension_settings_backend.h" |
12 #include "chrome/browser/extensions/extension_settings_storage.h" | 12 #include "chrome/browser/extensions/extension_settings_storage.h" |
13 | 13 |
14 // Superclass of all settings functions. | 14 // Superclass of all settings functions. |
15 class SettingsFunction : public AsyncExtensionFunction { | 15 class SettingsFunction : public AsyncExtensionFunction { |
16 protected: | 16 protected: |
17 virtual bool RunImpl() OVERRIDE; | 17 virtual bool RunImpl() OVERRIDE; |
18 | 18 |
19 // Extension settings function implementations should do their work here. | 19 // Extension settings function implementations should do their work here. |
20 // This runs on the FILE thread. | 20 // This runs on the FILE thread. |
21 // | 21 // |
22 // Implementations should fill in args themselves, though (like RunImpl) | 22 // Implementations should fill in args themselves, though (like RunImpl) |
23 // may return false to imply failure. | 23 // may return false to imply failure. |
24 virtual bool RunWithStorage(ExtensionSettingsStorage* storage) = 0; | 24 virtual bool RunWithStorage( |
| 25 ExtensionSettingsBackend* backend, |
| 26 ExtensionSettingsStorage* storage) = 0; |
25 | 27 |
26 // Sets error_ or result_ depending on the value of a storage Result, and | 28 // Sets error_ or result_ depending on the value of a storage Result, and |
27 // returns whether the Result implies success (i.e. !error). | 29 // returns whether the Result implies success (i.e. !error). |
28 bool UseResult(const ExtensionSettingsStorage::Result& storage_result); | 30 bool UseResult( |
| 31 ExtensionSettingsBackend* backend, |
| 32 const ExtensionSettingsStorage::Result& storage_result); |
29 | 33 |
30 private: | 34 private: |
31 // Called via PostTask from RunImpl. Calls RunWithStorage and then | 35 // Called via PostTask from RunImpl. Calls RunWithStorage and then |
32 // SendReponse with its success value. | 36 // SendReponse with its success value. |
33 void RunWithBackendOnFileThread(ExtensionSettingsBackend* backend); | 37 void RunWithBackendOnFileThread(ExtensionSettingsBackend* backend); |
34 }; | 38 }; |
35 | 39 |
36 class GetSettingsFunction : public SettingsFunction { | 40 class GetSettingsFunction : public SettingsFunction { |
37 public: | 41 public: |
38 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get"); | 42 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get"); |
39 | 43 |
40 protected: | 44 protected: |
41 virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE; | 45 virtual bool RunWithStorage( |
| 46 ExtensionSettingsBackend* backend, |
| 47 ExtensionSettingsStorage* storage) OVERRIDE; |
42 }; | 48 }; |
43 | 49 |
44 class SetSettingsFunction : public SettingsFunction { | 50 class SetSettingsFunction : public SettingsFunction { |
45 public: | 51 public: |
46 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set"); | 52 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set"); |
47 | 53 |
48 protected: | 54 protected: |
49 virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE; | 55 virtual bool RunWithStorage( |
| 56 ExtensionSettingsBackend* backend, |
| 57 ExtensionSettingsStorage* storage) OVERRIDE; |
50 }; | 58 }; |
51 | 59 |
52 class RemoveSettingsFunction : public SettingsFunction { | 60 class RemoveSettingsFunction : public SettingsFunction { |
53 public: | 61 public: |
54 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove"); | 62 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove"); |
55 | 63 |
56 protected: | 64 protected: |
57 virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE; | 65 virtual bool RunWithStorage( |
| 66 ExtensionSettingsBackend* backend, |
| 67 ExtensionSettingsStorage* storage) OVERRIDE; |
58 }; | 68 }; |
59 | 69 |
60 class ClearSettingsFunction : public SettingsFunction { | 70 class ClearSettingsFunction : public SettingsFunction { |
61 public: | 71 public: |
62 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear"); | 72 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear"); |
63 | 73 |
64 protected: | 74 protected: |
65 virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE; | 75 virtual bool RunWithStorage( |
| 76 ExtensionSettingsBackend* backend, |
| 77 ExtensionSettingsStorage* storage) OVERRIDE; |
66 }; | 78 }; |
67 | 79 |
68 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_ | 80 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_ |
OLD | NEW |