@@ -45,7 +45,6 @@ import {
45
45
import { SyncEngine } from './sync_engine' ;
46
46
import { View , ViewDocumentChanges } from './view' ;
47
47
48
- import { PersistenceSettings } from '../api/database' ;
49
48
import {
50
49
LruGarbageCollector ,
51
50
LruParams ,
@@ -56,7 +55,6 @@ import {
56
55
SharedClientState ,
57
56
WebStorageSharedClientState
58
57
} from '../local/shared_client_state' ;
59
- import { assert } from '../util/assert' ;
60
58
import { AutoId } from '../util/misc' ;
61
59
import { DatabaseId , DatabaseInfo } from './database_info' ;
62
60
import { Query } from './query' ;
@@ -72,6 +70,23 @@ const DOM_EXCEPTION_ABORTED = 20;
72
70
/** The DOMException code for quota exceeded. */
73
71
const DOM_EXCEPTION_QUOTA_EXCEEDED = 22 ;
74
72
73
+ export class IndexedDbPersistenceSettings {
74
+ constructor (
75
+ readonly cacheSizeBytes : number ,
76
+ readonly experimentalTabSynchronization : boolean
77
+ ) { }
78
+
79
+ lruParams ( ) : LruParams {
80
+ return LruParams . withCacheSize ( this . cacheSizeBytes ) ;
81
+ }
82
+ }
83
+
84
+ export class MemoryPersistenceSettings { }
85
+
86
+ export type InternalPersistenceSettings =
87
+ | IndexedDbPersistenceSettings
88
+ | MemoryPersistenceSettings ;
89
+
75
90
/**
76
91
* FirestoreClient is a top-level class that constructs and owns all of the
77
92
* pieces of the client SDK architecture. It is responsible for creating the
@@ -146,10 +161,7 @@ export class FirestoreClient {
146
161
* start for any reason. If usePersistence is false this is
147
162
* unconditionally resolved.
148
163
*/
149
- start (
150
- persistenceSettings : PersistenceSettings ,
151
- cacheSizeBytes : number
152
- ) : Promise < void > {
164
+ start ( persistenceSettings : InternalPersistenceSettings ) : Promise < void > {
153
165
// We defer our initialization until we get the current user from
154
166
// setChangeListener(). We block the async queue until we got the initial
155
167
// user and the initialization is completed. This will prevent any scheduled
@@ -172,12 +184,7 @@ export class FirestoreClient {
172
184
if ( ! initialized ) {
173
185
initialized = true ;
174
186
175
- this . initializePersistence (
176
- persistenceSettings ,
177
- persistenceResult ,
178
- user ,
179
- cacheSizeBytes
180
- )
187
+ this . initializePersistence ( persistenceSettings , persistenceResult , user )
181
188
. then ( maybeLruGc => this . initializeRest ( user , maybeLruGc ) )
182
189
. then ( initializationDone . resolve , initializationDone . reject ) ;
183
190
} else {
@@ -223,17 +230,12 @@ export class FirestoreClient {
223
230
* succeeded.
224
231
*/
225
232
private initializePersistence (
226
- persistenceSettings : PersistenceSettings ,
233
+ persistenceSettings : InternalPersistenceSettings ,
227
234
persistenceResult : Deferred < void > ,
228
- user : User ,
229
- cacheSizeBytes : number
235
+ user : User
230
236
) : Promise < LruGarbageCollector | null > {
231
- if ( persistenceSettings . enabled ) {
232
- return this . startIndexedDbPersistence (
233
- user ,
234
- persistenceSettings ,
235
- cacheSizeBytes
236
- )
237
+ if ( persistenceSettings instanceof IndexedDbPersistenceSettings ) {
238
+ return this . startIndexedDbPersistence ( user , persistenceSettings )
237
239
. then ( maybeLruGc => {
238
240
persistenceResult . resolve ( ) ;
239
241
return maybeLruGc ;
@@ -301,14 +303,8 @@ export class FirestoreClient {
301
303
*/
302
304
private startIndexedDbPersistence (
303
305
user : User ,
304
- settings : PersistenceSettings ,
305
- cacheSizeBytes : number
306
+ settings : IndexedDbPersistenceSettings
306
307
) : Promise < LruGarbageCollector > {
307
- assert (
308
- settings . enabled ,
309
- 'Should only start IndexedDb persitence with offline persistence enabled.'
310
- ) ;
311
-
312
308
// TODO(http://b/33384523): For now we just disable garbage collection
313
309
// when persistence is enabled.
314
310
const storagePrefix = IndexedDbPersistence . buildStoragePrefix (
@@ -331,7 +327,7 @@ export class FirestoreClient {
331
327
}
332
328
333
329
let persistence : IndexedDbPersistence ;
334
- const lruParams = LruParams . withCacheSize ( cacheSizeBytes ) ;
330
+ const lruParams = settings . lruParams ( ) ;
335
331
if ( settings . experimentalTabSynchronization ) {
336
332
this . sharedClientState = new WebStorageSharedClientState (
337
333
this . asyncQueue ,
0 commit comments