| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 module content; | 5 module content; |
| 6 | 6 |
| 7 import "components/leveldb/public/interfaces/leveldb.mojom"; | 7 import "components/leveldb/public/interfaces/leveldb.mojom"; |
| 8 | 8 |
| 9 // Gives information about changes to a LevelDB database. | 9 // Gives information about changes to a LevelDB database. |
| 10 // The reason this is a parameter to DeleteAll and GetAll below, instead of | 10 // The reason this is a parameter to DeleteAll and GetAll below, instead of |
| 11 // being specified when opening a LevelDBWrapper, is to avoid the client getting | 11 // being specified when opening a LevelDBWrapper, is to avoid the client getting |
| 12 // callbacks for changes that have already been applied to its database that | 12 // callbacks for changes that have already been applied to its database that |
| 13 // it's fetching via GetAll or it's clearing via DeleteAll. | 13 // it's fetching via GetAll or it's clearing via DeleteAll. |
| 14 // In the methods below, |source| is a user-defined string which was passed to |
| 15 // the various LevelDBWrapper methods. |
| 16 // Note that observer methods are called before the callbacks for the |
| 17 // LevelDBWrapper methods are run. |
| 14 interface LevelDBObserver { | 18 interface LevelDBObserver { |
| 15 KeyChanged(array<uint8> key, array<uint8> new_value, array<uint8> old_value, | 19 KeyChanged(array<uint8> key, array<uint8> new_value, array<uint8> old_value, |
| 16 string source); | 20 string source); |
| 17 KeyDeleted(array<uint8> key, string source); | 21 KeyDeleted(array<uint8> key, array<uint8> old_value, string source); |
| 18 AllDeleted(string source); | 22 AllDeleted(string source); |
| 19 }; | 23 }; |
| 20 | 24 |
| 21 struct KeyValue { | 25 struct KeyValue { |
| 22 array<uint8> key; | 26 array<uint8> key; |
| 23 array<uint8> value; | 27 array<uint8> value; |
| 24 }; | 28 }; |
| 25 | 29 |
| 26 // A wrapper around leveldb that supports giving notifications when values | 30 // A wrapper around leveldb that supports giving notifications when values |
| 27 // change. | 31 // change. |
| 28 interface LevelDBWrapper { | 32 interface LevelDBWrapper { |
| 29 // Sets the database entry for "key" to "value". Returns OK on success. | 33 // Sets the database entry for |key| to |value|. Returns OK on success. |
| 30 Put(array<uint8> key, array<uint8> value, string source) | 34 Put(array<uint8> key, array<uint8> value, string source) |
| 31 => (leveldb.DatabaseError status); | 35 => (leveldb.DatabaseError status); |
| 32 | 36 |
| 33 // Remove the database entry (if any) for "key". Returns OK on | 37 // Remove the database entry (if any) for |key|. Returns OK on success, and a |
| 34 // success, and a non-OK status on error. It is not an error if "key" | 38 // non-OK status on error. It is not an error if |key| did not exist in the |
| 35 // did not exist in the database. | 39 // database. |
| 36 Delete(array<uint8> key, string source) => (leveldb.DatabaseError status); | 40 Delete(array<uint8> key, string source) => (leveldb.DatabaseError status); |
| 37 | 41 |
| 38 // Removes all the entries. | 42 // Removes all the entries. |
| 39 DeleteAll(LevelDBObserver observer, string source) | 43 DeleteAll(LevelDBObserver observer, string source) |
| 40 => (leveldb.DatabaseError status); | 44 => (leveldb.DatabaseError status); |
| 41 | 45 |
| 42 // Returns the value of the given key. | 46 // Returns the value of the |key|. |
| 43 Get(array<uint8> key) => (leveldb.DatabaseError status, array<uint8> value); | 47 Get(array<uint8> key) => (leveldb.DatabaseError status, array<uint8> value); |
| 44 | 48 |
| 45 // Only used with small databases. Returns all key/value pairs. | 49 // Only used with small databases. Returns all key/value pairs. |
| 46 [Sync] | 50 [Sync] |
| 47 GetAll(LevelDBObserver observer) | 51 GetAll(LevelDBObserver observer) |
| 48 => (leveldb.DatabaseError status, array<KeyValue> data); | 52 => (leveldb.DatabaseError status, array<KeyValue> data); |
| 49 }; | 53 }; |
| OLD | NEW |