Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/extensions/extension_settings_api.h

Issue 7189029: Implement an initial extension settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Change where extension settings are saved, update TODO, api test Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_
7 #pragma once
8
9 #include "chrome/browser/extensions/extension_function.h"
10 #include "chrome/browser/extensions/extension_settings.h"
11 #include "chrome/browser/extensions/extension_settings_storage.h"
12
13 // Superclass of all settings functions.
14 class SettingsFunction : public AsyncExtensionFunction {
15 public:
16 virtual ~SettingsFunction() {}
17
18 // Extension settings function implementations should do their work here, and
19 // either run a StorageResultCallback or fill the function result / call
20 // SendResponse themselves.
21 // The exception is that implementations can return false to immediately
22 // call SendResponse(false) -- this is so that the extensions macros work.
Mihai Parparita -not on Chrome 2011/06/21 23:40:11 Not sure what "macros" refers to here.
not at google - send to devlin 2011/06/22 09:40:38 Oh like EXTENSION_FUNCTION_VALIDATE.
23 virtual bool RunWithStorage(ExtensionSettingsStorage* storage) = 0;
24
25 bool RunImpl();
26
27 protected:
28 // GetStorage() callback to run the given ExtensionFunction's RunWithStorage.
29 // Declared here to access to the protected members of ExtensionFunction.
30 class GetStorageCallback : public ExtensionSettings::Callback {
31 public:
32 explicit GetStorageCallback(SettingsFunction* settings_function);
33 ~GetStorageCallback();
34 void Run(ExtensionSettingsStorage* storage);
35
36 private:
37 scoped_refptr<SettingsFunction> settings_function_;
38 };
39
40 // Callback from all storage methods (Get/Set/Remove/Clear) which sets the
41 // appropriate fields of the extension function (result/error) and sends a
42 // response.
43 // Declared here to access to the protected members of ExtensionFunction.
44 class StorageResultCallback : public ExtensionSettingsStorage::Callback {
45 public:
46 explicit StorageResultCallback(SettingsFunction* settings_function);
47 ~StorageResultCallback();
48 void OnSuccess(DictionaryValue* settings);
49 void OnFailure(const std::string& message);
50
51 private:
52 scoped_refptr<SettingsFunction> settings_function_;
53 };
54 };
55
56 class GetSettingsFunction : public SettingsFunction {
57 public:
58 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get");
59
60 protected:
61 bool RunWithStorage(ExtensionSettingsStorage* storage);
62 std::string Thing();
Mihai Parparita -not on Chrome 2011/06/21 23:40:11 I don't think you need any of the Thing() methods.
not at google - send to devlin 2011/06/22 09:40:38 Oops. Debugging cleanup fail.
63 };
64
65 class SetSettingsFunction : public SettingsFunction {
66 public:
67 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set");
68
69 protected:
70 bool RunWithStorage(ExtensionSettingsStorage* storage);
71 std::string Thing();
72 };
73
74 class RemoveSettingsFunction : public SettingsFunction {
75 public:
76 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove");
77
78 protected:
79 bool RunWithStorage(ExtensionSettingsStorage* storage);
80 std::string Thing();
81 };
82
83 class ClearSettingsFunction : public SettingsFunction {
84 public:
85 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear");
86
87 protected:
88 bool RunWithStorage(ExtensionSettingsStorage* storage);
89 std::string Thing();
90 };
91
92 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698