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

Side by Side Diff: chrome/browser/extensions/extension_settings_noop_storage.cc

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 #include "chrome/browser/extensions/extension_settings_noop_storage.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "base/task.h"
10
11 namespace {
12
13 // Calls OnSuccess() of a callback with settings, after posting back to the UI
14 // thread.
15 class SuccessResultClosure {
16 public:
17 SuccessResultClosure(ExtensionSettingsStorage::Callback* callback,
18 DictionaryValue* settings) : callback_(callback), settings_(settings) {
19 }
20
21 ~SuccessResultClosure() {
22 delete callback_;
23 }
24
25 void Run() {
26 MessageLoop::current()->PostTask(FROM_HERE,
27 base::Bind(&SuccessResultClosure::Run2, base::Unretained(this)));
28 }
29
30 private:
31 void Run2() {
32 callback_->OnSuccess(settings_);
33 delete this;
34 }
35
36 ExtensionSettingsStorage::Callback* callback_;
37 DictionaryValue* settings_;
38 };
39
40 } // namespace
41
42 void ExtensionSettingsNoopStorage::Get(const std::string& key,
43 ExtensionSettingsStorage::Callback* callback) {
44 (new SuccessResultClosure(callback, new DictionaryValue()))->Run();
45 }
46
47 void ExtensionSettingsNoopStorage::Get(const ListValue& keys,
48 ExtensionSettingsStorage::Callback* callback) {
49 (new SuccessResultClosure(callback, new DictionaryValue()))->Run();
50 }
51
52 void ExtensionSettingsNoopStorage::Get(
53 ExtensionSettingsStorage::Callback* callback) {
54 (new SuccessResultClosure(callback, new DictionaryValue()))->Run();
55 }
56
57 void ExtensionSettingsNoopStorage::Set(const std::string& key,
58 const Value& value, ExtensionSettingsStorage::Callback* callback) {
59 DictionaryValue* settings = new DictionaryValue();
60 settings->Set(key, value.DeepCopy());
61 (new SuccessResultClosure(callback, settings))->Run();
62 }
63
64 void ExtensionSettingsNoopStorage::Set(const DictionaryValue& values,
65 ExtensionSettingsStorage::Callback* callback) {
66 (new SuccessResultClosure(callback, values.DeepCopy()))->Run();
67 }
68
69 void ExtensionSettingsNoopStorage::Remove(const std::string& key,
70 ExtensionSettingsStorage::Callback *callback) {
71 (new SuccessResultClosure(callback, new DictionaryValue()))->Run();
72 }
73
74 void ExtensionSettingsNoopStorage::Remove(const ListValue& keys,
75 ExtensionSettingsStorage::Callback *callback) {
76 (new SuccessResultClosure(callback, new DictionaryValue()))->Run();
77 }
78
79 void ExtensionSettingsNoopStorage::Clear(
80 ExtensionSettingsStorage::Callback* callback) {
81 (new SuccessResultClosure(callback, new DictionaryValue()))->Run();
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698