summaryrefslogtreecommitdiff
path: root/chromium/components/services/leveldb/public/interfaces/leveldb.mojom
blob: ab3312a6f46b931b31413f7c55543a48accdbcdc (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2015 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 leveldb.mojom;

import "components/services/filesystem/public/interfaces/directory.mojom";
import "mojo/public/mojom/base/memory_allocator_dump_cross_process_uid.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";

enum DatabaseError {
  OK,
  NOT_FOUND,
  CORRUPTION,
  NOT_SUPPORTED,
  INVALID_ARGUMENT,
  IO_ERROR
};

enum BatchOperationType {
  PUT_KEY,
  DELETE_KEY,
  DELETE_PREFIXED_KEY,
  // |key| is source prefixed key, |value| is destination prefixed key.
  COPY_PREFIXED_KEY
};

// TODO(dmurph): change to a union type for value population.
struct BatchedOperation {
  BatchOperationType type;
  array<uint8> key;
  // Populated for operations of types PUT_KEY and COPY_PREFIXED_KEY.
  array<uint8>? value;
};

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

enum SharedReadCache {
  Default,
  Web,
};

// Options which control the behavior of a database. (This struct corresponds
// with the struct in leveldb's options.h.)
//
// Note: This struct does not have default values. The values are set by a
// struct trait which copies values to/from a leveldb_env::Options instance.
struct OpenOptions {
  // TODO(erg): Find all comparators and copy them into the service.

  // If true, the database will be created if it is missing.
  bool create_if_missing;

  // If true, an error is raised if the database already exists.
  bool error_if_exists;

  // If true, the implementation will do aggressive checking of the
  // data it is processing and will stop early if it detects any
  // errors.
  bool paranoid_checks;

  // Amount of data to build up in memory (backed by an unsorted log
  // on disk) before converting to a sorted on-disk file.
  uint64 write_buffer_size;

  // Number of open files that can be used by the DB.
  int32 max_open_files;

  // The shared read cache to use.
  SharedReadCache shared_block_read_cache = SharedReadCache.Default;
};

// Service which hands out databases.
interface LevelDBService {
  // Open the database with the specified "name" in the specified "directory".
  // Fails if the database doesn't already exist.
  Open(filesystem.mojom.Directory directory,
       string dbname,
       mojo_base.mojom.MemoryAllocatorDumpCrossProcessUid? memory_dump_id,
       associated LevelDBDatabase& database) => (DatabaseError status);

  // Open the database with the specified "name" in the specified "directory".
  OpenWithOptions(OpenOptions options,
                  filesystem.mojom.Directory directory,
                  string dbname,
                  mojo_base.mojom.MemoryAllocatorDumpCrossProcessUid?
                  memory_dump_id,
                  associated LevelDBDatabase& database) => (DatabaseError status);

  // Opens a database stored purely in memory.
  // "tracking_name" will be used for memory-infra reporting to associate memory
  // use with its origin.
  OpenInMemory(mojo_base.mojom.MemoryAllocatorDumpCrossProcessUid?
               memory_dump_id, string tracking_name,
               associated LevelDBDatabase& database) => (DatabaseError status);

  // Destroys the contents of the specified database. Returns OK if the database
  // already didn't exist.
  Destroy(filesystem.mojom.Directory directory,
          string dbname) => (DatabaseError status);
};

// A leveldb database.
interface LevelDBDatabase {
  // Basic Interface -------------------------------------------------------

  // Sets the database entry for "key" to "value". Returns OK on success.
  Put(array<uint8> key, array<uint8> value) => (DatabaseError status);

  // 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) => (DatabaseError status);

  DeletePrefixed(array<uint8> key_prefix) => (DatabaseError status);

  // Atomically performs all |operations|.
  // The DELETE_PREFIXED_KEY applies to all keys that exist before these
  // operations execute. If a 'put' operation precedes a delete prefix, then it
  // will only be deleted if it was a previously-populated key in the database.
  // The COPY_PREFIXED_KEY operations will always ignore all other changes in
  // the operations batch. It will not copy records that were inserted earlier
  // in the operations list.
  Write(array<BatchedOperation> operations) => (DatabaseError status);

  Get(array<uint8> key) => (DatabaseError status, array<uint8> value);

  GetPrefixed(array<uint8> key_prefix)
      => (DatabaseError status, array<KeyValue> data);

  // Copies all data from the source prefix to the destination prefix. Useful
  // for deep copies.
  CopyPrefixed(array<uint8> source_key_prefix,
               array<uint8> destination_key_prefix)
      => (DatabaseError status);

  // Snapshots -------------------------------------------------------------

  // Returns a handle to the current database state.
  GetSnapshot() => (mojo_base.mojom.UnguessableToken snapshot);

  // Releases a previously acquired snapshot.
  ReleaseSnapshot(mojo_base.mojom.UnguessableToken snapshot);

  // If |key| exists at the time |snapshot_id| was taken, return OK and the
  // value. Otherwise return NOT_FOUND.
  GetFromSnapshot(mojo_base.mojom.UnguessableToken snapshot,
                  array<uint8> key)
      => (DatabaseError status, array<uint8> value);

  // Iteartors -------------------------------------------------------------

  // Creates an iterator, either from the current view or from a snapshot.
  NewIterator() => (mojo_base.mojom.UnguessableToken iterator);
  NewIteratorFromSnapshot(mojo_base.mojom.UnguessableToken snapshot)
      => (mojo_base.mojom.UnguessableToken? iterator);

  ReleaseIterator(mojo_base.mojom.UnguessableToken iterator);

  // Positions the iterator at the first key, last key, or the first key after
  // |target|.
  [Sync]
  IteratorSeekToFirst(mojo_base.mojom.UnguessableToken iterator)
      => (bool valid, DatabaseError status, array<uint8>? key,
          array<uint8>? value);
  [Sync]
  IteratorSeekToLast(mojo_base.mojom.UnguessableToken iterator)
      => (bool valid, DatabaseError status, array<uint8>? key,
          array<uint8>? value);
  [Sync]
  IteratorSeek(mojo_base.mojom.UnguessableToken iterator, array<uint8> target)
      => (bool valid, DatabaseError status, array<uint8>? key,
          array<uint8>? value);

  // Moves forward or backwards in iterator space.
  [Sync]
  IteratorNext(mojo_base.mojom.UnguessableToken iterator)
      => (bool valid, DatabaseError status, array<uint8>? key,
          array<uint8>? value);
  [Sync]
  IteratorPrev(mojo_base.mojom.UnguessableToken iterator)
      => (bool valid, DatabaseError status, array<uint8>? key,
          array<uint8>? value);
};