summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_settings_api.h
blob: 2cc87a09babdeeb1ca2a7b29c1ea6ba36a18f3df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_
#pragma once

#include "base/compiler_specific.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/extensions/extension_settings.h"
#include "chrome/browser/extensions/extension_settings_storage.h"

// Superclass of all settings functions.
class SettingsFunction : public AsyncExtensionFunction {
 protected:
  virtual bool RunImpl() OVERRIDE;

  // Extension settings function implementations should do their work here.
  // This runs on the FILE thread.
  //
  // Implementations should fill in args themselves, though (like RunImpl)
  // may return false to imply failure.
  virtual bool RunWithStorage(ExtensionSettingsStorage* storage) = 0;

  // Sets error_ or result_ depending on the value of a storage Result, and
  // returns whether the Result implies success (i.e. !error).
  bool UseResult(const ExtensionSettingsStorage::Result& storage_result);

 private:
  // Called via PostTask from RunImpl.  Calls RunWithStorage and then
  // SendReponse with its success value.
  void RunWithSettingsOnFileThread(ExtensionSettings* settings);
};

class GetSettingsFunction : public SettingsFunction {
 public:
  DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.get");

 protected:
  virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE;
};

class SetSettingsFunction : public SettingsFunction {
 public:
  DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.set");

 protected:
  virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE;
};

class RemoveSettingsFunction : public SettingsFunction {
 public:
  DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.remove");

 protected:
  virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE;
};

class ClearSettingsFunction : public SettingsFunction {
 public:
  DECLARE_EXTENSION_FUNCTION_NAME("experimental.settings.clear");

 protected:
  virtual bool RunWithStorage(ExtensionSettingsStorage* storage) OVERRIDE;
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_API_H_