Skip to content

Commit

Permalink
Add debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyparrish committed Feb 23, 2024
1 parent cdc716e commit 107cd06
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/offline/indexeddb/storage_mechanism.js
Expand Up @@ -46,12 +46,16 @@ shaka.offline.indexeddb.StorageMechanism = class {
this.v5_ = null;
/** @private {shaka.extern.EmeSessionStorageCell} */
this.sessions_ = null;
/** @private {number} */
this.id_ = ++shaka.offline.indexeddb.StorageMechanism.nextid;
}

/**
* @override
*/
init() {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'initializing');

const name = shaka.offline.indexeddb.StorageMechanism.DB_NAME;
const version = shaka.offline.indexeddb.StorageMechanism.VERSION;

Expand All @@ -61,6 +65,7 @@ shaka.offline.indexeddb.StorageMechanism = class {
// called at all, so that this method doesn't hang forever.
let timedOut = false;
const timeOutTimer = new shaka.util.Timer(() => {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'timed out');
timedOut = true;
p.reject(new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
Expand All @@ -71,6 +76,7 @@ shaka.offline.indexeddb.StorageMechanism = class {

const open = window.indexedDB.open(name, version);
open.onsuccess = (event) => {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'success');
if (timedOut) {
// Too late, we have already given up on opening the storage mechanism.
return;
Expand All @@ -90,10 +96,12 @@ shaka.offline.indexeddb.StorageMechanism = class {
p.resolve();
};
open.onupgradeneeded = (event) => {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'upgrading');
// Add object stores for the latest version only.
this.createStores_(open.result);
};
open.onerror = (event) => {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'error', event.error);
if (timedOut) {
// Too late, we have already given up on opening the storage mechanism.
return;
Expand All @@ -109,6 +117,8 @@ shaka.offline.indexeddb.StorageMechanism = class {
event.preventDefault();
};
open.onblocked = (event) => {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'blocked',
event.oldVersion, event.newVersion);
if (timedOut) {
// Too late, we have already given up on opening the storage mechanism.
return;
Expand All @@ -129,6 +139,7 @@ shaka.offline.indexeddb.StorageMechanism = class {
* @override
*/
async destroy() {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'destroy');
if (this.v1_) {
await this.v1_.destroy();
}
Expand All @@ -144,11 +155,16 @@ shaka.offline.indexeddb.StorageMechanism = class {
if (this.sessions_) {
await this.sessions_.destroy();
}
shaka.log.debug('STORAGE INSTANCE', this.id_, 'destroy', 'cells done');

// If we were never initialized, then |db_| will still be null.
if (this.db_) {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'destroy', 'DB close');
this.db_.close();
} else {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'destroy', 'no DB');
}
shaka.log.debug('STORAGE INSTANCE', this.id_, 'destroy', 'complete');
}

/**
Expand Down Expand Up @@ -185,6 +201,7 @@ shaka.offline.indexeddb.StorageMechanism = class {
* @override
*/
async erase() {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'erase');
// Not all cells may have been created, so only destroy the ones that
// were created.
if (this.v1_) {
Expand All @@ -199,11 +216,21 @@ shaka.offline.indexeddb.StorageMechanism = class {
if (this.v5_) {
await this.v5_.destroy();
}
/* FIXME: missing?
if (this.sessions_) {
await this.sessions_.destroy();
}
*/
shaka.log.debug('STORAGE INSTANCE', this.id_, 'erase', 'cells done');

// |db_| will only be null if the muxer was not initialized. We need to
// close the connection in order delete the database without it being
// blocked.
if (this.db_) {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'erase', 'DB close');
this.db_.close();
} else {
shaka.log.debug('STORAGE INSTANCE', this.id_, 'erase', 'no DB');
this.db_.close();
}

Expand All @@ -215,6 +242,9 @@ shaka.offline.indexeddb.StorageMechanism = class {
this.v2_ = null;
this.v3_ = null;
this.v5_ = null;
/* FIXME: missing?
this.sessions_ = null;
*/

await this.init();
}
Expand Down Expand Up @@ -399,6 +429,8 @@ shaka.offline.indexeddb.StorageMechanism.V3_MANIFEST_STORE = 'manifest-v3';
shaka.offline.indexeddb.StorageMechanism.V5_MANIFEST_STORE = 'manifest-v5';
/** @const {string} */
shaka.offline.indexeddb.StorageMechanism.SESSION_ID_STORE = 'session-ids';
/** @type {number} */
shaka.offline.indexeddb.StorageMechanism.nextid = 0;


// Since this may be called before the polyfills remove indexeddb support from
Expand Down

0 comments on commit 107cd06

Please sign in to comment.