tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mozIBridgedSyncEngine.idl (8951B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "nsISupports.idl"
      6 
      7 interface nsIVariant;
      8 
      9 // A generic callback called with a result. Variants are automatically unboxed
     10 // in JavaScript: for example, a `UTF8String` will be passed as a string
     11 // argument; an `Int32` or `Int64` as a number. Methods that don't return a
     12 // value, like `setLastSync` or `setUploaded`, will pass a `null` variant to
     13 // `handleSuccess`. For all callback types in this file, either `handleSuccess`
     14 // or `handleError` is guaranteed to be called once.
     15 [scriptable, uuid(9b7dd2a3-df99-4469-9ea9-61b222098695)]
     16 interface mozIBridgedSyncEngineCallback : nsISupports {
     17    void handleSuccess(in nsIVariant result);
     18    void handleError(in nsresult code, in AUTF8String message);
     19 };
     20 
     21 // A callback called after the engine applies incoming records. This is separate
     22 // from `mozIBridgedSyncEngineCallback` because variants can't hold an
     23 // `Array<T>` type.
     24 [scriptable, uuid(2776cdd5-799a-4009-b2f3-356d940a5244)]
     25 interface mozIBridgedSyncEngineApplyCallback : nsISupports {
     26    // Notifies Sync that the bridged engine has finished applying incoming
     27    // records, and has outgoing records. Sync encrypts and uploads these
     28    // records, and notifies the engine that the upload succeeded by
     29    // calling `engine.setUploaded(uploadedOutgoingRecordIds, ...)`.
     30    void handleSuccess(in Array<AUTF8String> outgoingEnvelopesAsJSON);
     31 
     32    // Notifies Sync that the bridged engine failed to apply the staged records.
     33    void handleError(in nsresult code, in AUTF8String message);
     34 };
     35 
     36 // A bridged engine is implemented in Rust. It handles storage internally, and
     37 // exposes a minimal interface for the JS Sync code to control it.
     38 [scriptable, uuid(3b2b80be-c30e-4498-8065-01809cfe8d47)]
     39 interface mozIBridgedSyncEngine : nsISupports {
     40    // The storage version for this engine's collection. If the version in the
     41    // server's `meta/global` record is newer than ours, we'll refuse to sync,
     42    // since we might not understand the data; if it's older, we'll wipe the
     43    // collection on the server, and upload our data as if on a first sync.
     44    readonly attribute long storageVersion;
     45 
     46    // Whether this engine tolerates skipped records, where a "skipped" record
     47    // is one that would cause the server's published limits to be exceeded
     48    // (for example, a single record where the payload is larger than the
     49    // server accepts.)
     50    // If this returns true, we will just skip the record without even attempting
     51    // to upload. If this is false, we'll abort the entire batch.
     52    // If the engine allows this, it will need to detect this scenario by noticing
     53    // the ID is not in the 'success' records reported to `setUploaded`.
     54    // (Note that this is not to be confused with the fact server's can currently
     55    // reject records as part of a POST - but we hope to remove this ability from
     56    // the server API. Note also that this is not bullet-proof - if the count of
     57    // records is high, it's possible that we will have committed a previous
     58    // batch before we hit the relevant limits, so things might have been written.
     59    // We hope to fix this by ensuring batch limits are such that this is
     60    // impossible)
     61    readonly attribute boolean allowSkippedRecord;
     62 
     63    // Returns the last sync time, in milliseconds, for this engine's
     64    // collection. This is used to build the collection URL for fetching
     65    // incoming records, and as the initial value of the `X-I-U-S` header on
     66    // upload. If the engine persists incoming records in a permanent (non-temp)
     67    // table, `getLastSync` can return a "high water mark" that's the newer of
     68    // the collection's last sync time, and the most recent record modification
     69    // time. This avoids redownloading incoming records that were previously
     70    // downloaded, but not applied.
     71    void getLastSync(in mozIBridgedSyncEngineCallback callback);
     72 
     73    // Sets the last sync time, in milliseconds. This is used to fast-forward
     74    // the last sync time for the engine's collection after fetching all
     75    // records, and after each `setUploaded` call with the `X-L-M` header from
     76    // the server. It may be called multiple times per sync.
     77    void setLastSync(in long long lastSyncMillis,
     78                     in mozIBridgedSyncEngineCallback callback);
     79 
     80    // Returns the sync ID for this engine's collection. Used for testing;
     81    // Sync only calls `ensureCurrentSyncId` and `resetSyncId`. On success,
     82    // calls `callback.handleSuccess(in AUTF8String currentSyncId)`.
     83    void getSyncId(in mozIBridgedSyncEngineCallback callback);
     84 
     85    // Generates a new sync ID for this engine, and resets all local Sync
     86    // metadata, including the last sync time and any change flags, to start
     87    // over as a first sync. On success, calls
     88    // `callback.handleSuccess(newSyncId)`, where `newSyncId` is
     89    // `AUTF8String` variant. Sync will upload the new sync ID in the
     90    // `meta/global` record.
     91    void resetSyncId(in mozIBridgedSyncEngineCallback callback);
     92 
     93    // Ensures that the local sync ID for the engine matches the sync ID for
     94    // the collection on the server. On a mismatch, the engine can:
     95    //   1. Reset all local Sync state, adopt `newSyncId` as the new sync ID,
     96    //      and call `callback.handleSuccess(newSyncId)`. Most engines should
     97    //      do this.
     98    //   2. Ignore the given `newSyncId`, use its existing local sync ID
     99    //      without resetting any state, and call
    100    //      `callback.handleSuccess(existingSyncId)`. This is useful if, for
    101    //      example, the underlying database has been restored from a backup,
    102    //      and the engine would like to force a reset and first sync on all
    103    //      other devices.
    104    //   3. Ignore the given `newSyncId`, reset all local Sync state, and
    105    //      generate a fresh sync ID, as if `resetSyncId`. This resets the
    106    //      engine's state everywhere, locally and on all other devices.
    107    // If the callback is called with a different sync ID than `newSyncId`,
    108    // Sync will reupload `meta/global` with the different ID. Otherwise, it
    109    // will assume that the engine has adopted the `newSyncId`, and do nothing.
    110    void ensureCurrentSyncId(in AUTF8String newSyncId,
    111                             in mozIBridgedSyncEngineCallback callback);
    112 
    113    // Notifies the engine that sync is starting. The engine can use this method
    114    // to set up temp tables for merging, for example. This will only be called
    115    // once per sync, and before any `storeIncoming` calls.
    116    void syncStarted(in mozIBridgedSyncEngineCallback callback);
    117 
    118    // Stages a batch of incoming records, and calls the `callback` when
    119    // done. This method may be called multiple times per sync, once per
    120    // incoming batch, and always after `syncStarted`. Flushing incoming records
    121    // more often incurs more writes to disk, but avoids redownloading and
    122    // reapplying more records if syncing is interrupted. Typically, engines
    123    // will stage incoming records in an SQLite temp table, and merge them with
    124    // the local database when `apply` is called.
    125    void storeIncoming(in Array<AUTF8String> incomingEnvelopesAsJSON,
    126                       in mozIBridgedSyncEngineCallback callback);
    127 
    128    // Applies all the staged records, and calls the `callback` with
    129    // outgoing records to upload. This will always be called after
    130    // `storeIncoming`, and only once per sync. Application should be atomic:
    131    // either all incoming records apply successfully, or none.
    132    void apply(in mozIBridgedSyncEngineApplyCallback callback);
    133 
    134    // Notifies the engine that Sync successfully uploaded the records with the
    135    // given IDs. This method may be called multiple times per sync, once per
    136    // batch upload. This will always be called after `apply`.
    137    void setUploaded(in long long newTimestampMillis,
    138                     in Array<AUTF8String> uploadedIds,
    139                     in mozIBridgedSyncEngineCallback callback);
    140 
    141    // Notifies the engine that syncing has finished, and the engine shouldn't
    142    // expect any more `setUploaded` calls. At this point, any outgoing records
    143    // that weren't passed to `setUploaded` should be assumed failed. This is
    144    // guaranteed to be called even if the sync fails. This will only be called
    145    // once per sync.
    146    void syncFinished(in mozIBridgedSyncEngineCallback callback);
    147 
    148    // Resets all local Sync metadata, including the sync ID, last sync time,
    149    // and any change flags, but preserves all data. After a reset, the engine will
    150    // sync as if for the first time.
    151    void reset(in mozIBridgedSyncEngineCallback callback);
    152 
    153    // Erases all locally stored data and metadata for this engine.
    154    void wipe(in mozIBridgedSyncEngineCallback callback);
    155 };