summaryrefslogtreecommitdiff
path: root/chromium/content/common/leveldb_wrapper.mojom
blob: e099618c3727e8a5442c9cf388ebf0aaecc61dff (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
// Copyright 2016 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.

module content.mojom;

import "components/leveldb/public/interfaces/leveldb.mojom";

// Gives information about changes to a LevelDB database.
// Note that observer methods are called before the callbacks for the
// LevelDBWrapper methods are run.
interface LevelDBObserver {
  KeyAdded(array<uint8> key, array<uint8> value, string source);
  KeyChanged(array<uint8> key, array<uint8> new_value, array<uint8> old_value,
             string source);
  KeyDeleted(array<uint8> key, array<uint8> old_value, string source);
  AllDeleted(string source);
};

struct KeyValue {
  array<uint8> key;
  array<uint8> value;
};

// Since the GetAll call is synchronous, LevelDBWrapper users need this
// asynchronously delivered notification to avoid applying changes to the
// returned array that it already contains. This is not sent over the
// normal LevelDBObserver interface as there can be many observers and
// only the connection that made the GetAll call needs to be notified of
// its completion.
interface LevelDBWrapperGetAllCallback {
  Complete(bool success);
};

// A wrapper around leveldb that supports giving notifications when values
// change.
interface LevelDBWrapper {
  AddObserver(associated LevelDBObserver observer);

  // Sets the database entry for |key| to |value|. Returns OK on success.
  Put(array<uint8> key, array<uint8> value, string source) => (bool success);

  // Remove the database entry (if any) for |key|.  Returns OK on success, and a
  // non-OK status on error.  It is not an error if |key| did not exist in the
  // database.
  Delete(array<uint8> key, string source) => (bool success);

  // Removes all the entries.
  DeleteAll(string source) => (bool success);

  // Returns the value of the |key|.
  Get(array<uint8> key) => (bool success, array<uint8> value);

  // Only used with small databases. Returns all key/value pairs.
  [Sync]
  GetAll(associated LevelDBWrapperGetAllCallback complete_callback)
    => (leveldb.mojom.DatabaseError status, array<KeyValue> data);
};