mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-16 16:16:40 +03:00
Add Back Progress on Remove
Tracking progress when removing an asset was missing from the new storage system. This CL adds that support back. Issue #1248 Change-Id: Iab275cd75af817cfc34ee0888ddeea257b1ead56
This commit is contained in:
@@ -289,9 +289,12 @@ shaka.extern.StorageCell.prototype.addSegments = function(segments) {};
|
||||
* is not found, then that removal should be considered successful.
|
||||
*
|
||||
* @param {!Array.<number>} keys
|
||||
* @param {function(number)} onRemove A callback for when a segment is removed
|
||||
* from the cell. The key of the segment
|
||||
* will be passed to the callback.
|
||||
* @return {!Promise}
|
||||
*/
|
||||
shaka.extern.StorageCell.prototype.removeSegments = function(keys) {};
|
||||
shaka.extern.StorageCell.prototype.removeSegments = function(keys, onRemove) {};
|
||||
|
||||
|
||||
/**
|
||||
@@ -333,9 +336,13 @@ shaka.extern.StorageCell.prototype.updateManifestExpiration =
|
||||
* is not found, then that removal should be considered successful.
|
||||
*
|
||||
* @param {!Array.<number>} keys
|
||||
* @param {function(number)} onRemove A callback for when a manifest is removed
|
||||
* from the cell. The key of the manifest
|
||||
* will be passed to the callback.
|
||||
* @return {!Promise}
|
||||
*/
|
||||
shaka.extern.StorageCell.prototype.removeManifests = function(keys) {};
|
||||
shaka.extern.StorageCell.prototype.removeManifests =
|
||||
function(keys, onRemove) {};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,9 @@ shaka.offline.indexeddb.V1StorageCell = class {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
removeSegments(keys) { return this.remove_(this.segmentStore_, keys); }
|
||||
removeSegments(keys, onRemove) {
|
||||
return this.remove_(this.segmentStore_, keys, onRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
@@ -131,7 +133,9 @@ shaka.offline.indexeddb.V1StorageCell = class {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
removeManifests(keys) { return this.remove_(this.manifestStore_, keys); }
|
||||
removeManifests(keys, onRemove) {
|
||||
return this.remove_(this.manifestStore_, keys, onRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
@@ -195,15 +199,16 @@ shaka.offline.indexeddb.V1StorageCell = class {
|
||||
/**
|
||||
* @param {string} storeName
|
||||
* @param {!Array.<number>} keys
|
||||
* @param {function(number)} onRemove
|
||||
* @return {!Promise}
|
||||
* @private
|
||||
*/
|
||||
remove_(storeName, keys) {
|
||||
remove_(storeName, keys, onRemove) {
|
||||
let op = this.connection_.startReadWriteOperation(storeName);
|
||||
let store = op.store();
|
||||
|
||||
keys.forEach((key) => {
|
||||
store.delete(key);
|
||||
store.delete(key).onsuccess = () => onRemove(key);
|
||||
});
|
||||
|
||||
return op.promise();
|
||||
|
||||
@@ -69,7 +69,9 @@ shaka.offline.indexeddb.V2StorageCell = class {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
removeSegments(keys) { return this.remove_(this.segmentStore_, keys); }
|
||||
removeSegments(keys, onRemove) {
|
||||
return this.remove_(this.segmentStore_, keys, onRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
@@ -102,7 +104,9 @@ shaka.offline.indexeddb.V2StorageCell = class {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
removeManifests(keys) { return this.remove_(this.manifestStore_, keys); }
|
||||
removeManifests(keys, onRemove) {
|
||||
return this.remove_(this.manifestStore_, keys, onRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* @override
|
||||
@@ -183,15 +187,16 @@ shaka.offline.indexeddb.V2StorageCell = class {
|
||||
/**
|
||||
* @param {string} storeName
|
||||
* @param {!Array.<number>} keys
|
||||
* @param {function(number)} onRemove
|
||||
* @return {!Promise}
|
||||
* @private
|
||||
*/
|
||||
remove_(storeName, keys) {
|
||||
remove_(storeName, keys, onRemove) {
|
||||
let op = this.connection_.startReadWriteOperation(storeName);
|
||||
let store = op.store();
|
||||
|
||||
keys.forEach((key) => {
|
||||
store.delete(key);
|
||||
store.delete(key).onsuccess = () => onRemove(key);
|
||||
});
|
||||
|
||||
return op.promise();
|
||||
|
||||
+14
-2
@@ -373,9 +373,21 @@ shaka.offline.Storage.prototype.removeFromStorage_ = function(
|
||||
/** @type {!Array.<number>} */
|
||||
let segmentIds = shaka.offline.Storage.getAllSegmentIds_(manifest);
|
||||
|
||||
// Count(segments) + Count(manifests)
|
||||
let toRemove = segmentIds.length + 1;
|
||||
let removed = 0;
|
||||
|
||||
let pendingContent = shaka.offline.StoredContentUtils.fromManifestDB(
|
||||
uri, manifest);
|
||||
|
||||
let onRemove = (key) => {
|
||||
removed += 1;
|
||||
this.config_.progressCallback(pendingContent, removed / toRemove);
|
||||
};
|
||||
|
||||
return Promise.all([
|
||||
storage.removeSegments(segmentIds),
|
||||
storage.removeManifests([uri.key()])
|
||||
storage.removeSegments(segmentIds, onRemove),
|
||||
storage.removeManifests([uri.key()], onRemove)
|
||||
]);
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ describe('IndexeddbStorageCell', function() {
|
||||
const segmentStore = 'segment-store';
|
||||
const manifestStore = 'manifest-store';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
/** @type {!Array.<shaka.extern.StorageCell>} */
|
||||
let cells = [];
|
||||
|
||||
@@ -78,7 +80,7 @@ describe('IndexeddbStorageCell', function() {
|
||||
OfflineUtils.expectSegmentToEqual(found[1], segments[1]);
|
||||
OfflineUtils.expectSegmentToEqual(found[2], segments[2]);
|
||||
|
||||
return cell.removeSegments(keys);
|
||||
return cell.removeSegments(keys, noop);
|
||||
}).then(() => {
|
||||
// The get should fail as there should be no entries under the keys
|
||||
// anymore.
|
||||
@@ -121,7 +123,7 @@ describe('IndexeddbStorageCell', function() {
|
||||
expect(found[1]).toEqual(manifests[1]);
|
||||
expect(found[2]).toEqual(manifests[2]);
|
||||
|
||||
return cell.removeManifests(keys);
|
||||
return cell.removeManifests(keys, noop);
|
||||
}).then(() => {
|
||||
// The get should fail as there should be no entries under the keys
|
||||
// anymore.
|
||||
|
||||
@@ -106,7 +106,8 @@ describe('OfflineManifestParser', function() {
|
||||
handle.path.mechanism, handle.path.cell, keys[0]);
|
||||
|
||||
// Remove the manifest so that the uri will point to nothing.
|
||||
await handle.cell.removeManifests(keys);
|
||||
const noop = () => {};
|
||||
await handle.cell.removeManifests(keys, noop);
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -149,7 +150,8 @@ describe('OfflineManifestParser', function() {
|
||||
|
||||
// Remove the manifest after we have parsed it so that the
|
||||
// update won't find it. Oh, we are sneaky.
|
||||
await handle.cell.removeManifests(keys);
|
||||
const noop = () => {};
|
||||
await handle.cell.removeManifests(keys, noop);
|
||||
await parser.onExpirationUpdated(sessionId, newExpiration);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -753,7 +753,9 @@ describe('Storage', function() {
|
||||
// There should be way more than one segment.
|
||||
let keys = stream.segments.map((segment) => segment.dataKey);
|
||||
expect(keys.length).toBeGreaterThan(0);
|
||||
await cell.removeSegments(keys);
|
||||
|
||||
const noop = () => {};
|
||||
await cell.removeSegments(keys, noop);
|
||||
});
|
||||
|
||||
await storage.remove(uri.toString());
|
||||
|
||||
@@ -170,8 +170,9 @@ describe('V1IndexeddbStorageCell', function() {
|
||||
expect(segmentKeys.length).toBe(6);
|
||||
|
||||
// Remove all the segments.
|
||||
await cell.removeManifests(manifestKeys);
|
||||
await cell.removeSegments(segmentKeys);
|
||||
const noop = () => {};
|
||||
await cell.removeManifests(manifestKeys, noop);
|
||||
await cell.removeSegments(segmentKeys, noop);
|
||||
|
||||
let checkMissingSegment = async (key) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user