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

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: dgrogan comments #2, mihai comments #1 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), for compliance with 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 };
63
64 class SetSettingsFunction : public SettingsFunction {
65 public:
66 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set");
67
68 protected:
69 bool RunWithStorage(ExtensionSettingsStorage* storage);
70 };
71
72 class RemoveSettingsFunction : public SettingsFunction {
73 public:
74 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove");
75
76 protected:
77 bool RunWithStorage(ExtensionSettingsStorage* storage);
78 };
79
80 class ClearSettingsFunction : public SettingsFunction {
81 public:
82 DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear");
83
84 protected:
85 bool RunWithStorage(ExtensionSettingsStorage* storage);
86 };
87
88 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698