@@ -521,12 +521,22 @@ shaka.offline.Storage = class {
521
521
let pendingManifestUpdates = { } ;
522
522
let pendingDataSize = 0 ;
523
523
524
+ const ensureNotAbortedOrDestroyed = ( ) => {
525
+ if ( this . destroyer_ . destroyed ( ) || downloader . isAborted ( ) ) {
526
+ throw new shaka . util . Error (
527
+ shaka . util . Error . Severity . CRITICAL ,
528
+ shaka . util . Error . Category . STORAGE ,
529
+ shaka . util . Error . Code . OPERATION_ABORTED ) ;
530
+ }
531
+ } ;
532
+
524
533
/**
525
534
* @param {!Array.<!shaka.offline.DownloadInfo> } toDownload
526
535
* @param {boolean } updateDRM
527
536
*/
528
537
const download = async ( toDownload , updateDRM ) => {
529
538
for ( const download of toDownload ) {
539
+ ensureNotAbortedOrDestroyed ( ) ;
530
540
const request = download . makeSegmentRequest ( config ) ;
531
541
const estimateId = download . estimateId ;
532
542
const isInitSegment = download . isInitSegment ;
@@ -541,7 +551,7 @@ shaka.offline.Storage = class {
541
551
}
542
552
// Store the data.
543
553
const dataKeys = await storage . addSegments ( [ { data} ] ) ;
544
- this . ensureNotDestroyed_ ( ) ;
554
+ ensureNotAbortedOrDestroyed ( ) ;
545
555
546
556
// Store the necessary update to the manifest, to be processed later.
547
557
pendingManifestUpdates [ id ] = dataKeys [ 0 ] ;
@@ -560,14 +570,14 @@ shaka.offline.Storage = class {
560
570
}
561
571
}
562
572
await downloader . waitToFinish ( ) ;
573
+ ensureNotAbortedOrDestroyed ( ) ;
563
574
564
- if ( updateDRM ) {
575
+ if ( updateDRM && ! downloader . isAborted ( ) ) {
565
576
// Re-store the manifest, to attach session IDs.
566
577
// These were (maybe) discovered inside the downloader; we can only add
567
578
// them now, at the end, since the manifestDB is in flux during the
568
579
// process of downloading and storing, and assignSegmentsToManifest
569
580
// does not know about the DRM engine.
570
- this . ensureNotDestroyed_ ( ) ;
571
581
this . setManifestDrmFields_ (
572
582
manifest , manifestDB , drmEngine , usePersistentLicense ) ;
573
583
await storage . updateManifest ( manifestId , manifestDB ) ;
@@ -583,7 +593,7 @@ shaka.offline.Storage = class {
583
593
// init data from the init segments, download those first before
584
594
// anything else.
585
595
await download ( toDownload . filter ( ( info ) => info . isInitSegment ) , true ) ;
586
- this . ensureNotDestroyed_ ( ) ;
596
+ ensureNotAbortedOrDestroyed ( ) ;
587
597
toDownload = toDownload . filter ( ( info ) => ! info . isInitSegment ) ;
588
598
589
599
// Copy these and reset them now, before calling await.
@@ -595,12 +605,12 @@ shaka.offline.Storage = class {
595
605
await shaka . offline . Storage . assignSegmentsToManifest (
596
606
storage , manifestId , manifestDB , manifestUpdates , dataSize ,
597
607
( ) => this . ensureNotDestroyed_ ( ) ) ;
598
- this . ensureNotDestroyed_ ( ) ;
608
+ ensureNotAbortedOrDestroyed ( ) ;
599
609
}
600
610
601
611
if ( ! usingBgFetch ) {
602
612
await download ( toDownload , false ) ;
603
- this . ensureNotDestroyed_ ( ) ;
613
+ ensureNotAbortedOrDestroyed ( ) ;
604
614
605
615
// Copy these and reset them now, before calling await.
606
616
const manifestUpdates = pendingManifestUpdates ;
@@ -610,8 +620,8 @@ shaka.offline.Storage = class {
610
620
611
621
await shaka . offline . Storage . assignSegmentsToManifest (
612
622
storage , manifestId , manifestDB , manifestUpdates , dataSize ,
613
- ( ) => this . ensureNotDestroyed_ ( ) ) ;
614
- this . ensureNotDestroyed_ ( ) ;
623
+ ( ) => ensureNotAbortedOrDestroyed ( ) ) ;
624
+ ensureNotAbortedOrDestroyed ( ) ;
615
625
616
626
goog . asserts . assert (
617
627
! manifestDB . isIncomplete , 'The manifest should be complete by now' ) ;
0 commit comments