download = async (toDownload, updateDRM) => {
      for (const download of toDownload) {
        ensureNotAbortedOrDestroyed();
        const request = download.makeSegmentRequest(config);
        const estimateId = download.estimateId;
        const isInitSegment = download.isInitSegment;

        const onDownloaded = async (data) => {
          const ref = /** @type {!shaka.media.SegmentReference} */ (
            download.ref);
          const segmentData =
              ref.getSegmentData(/* allowDeleteOnSingleUse= */ false);
          if (ref.aesKey && !segmentData) {
            data = await shaka.media.SegmentUtils.aesDecrypt(
                data, ref.aesKey, download.refPosition);
          }
          const id = shaka.offline.DownloadInfo.idForSegmentRef(ref);
          // Store the data.
          const dataKeys = await storage.addSegments([{data}]);
          ensureNotAbortedOrDestroyed();

          // Store the necessary update to the manifest, to be processed later.
          pendingManifestUpdates[id] = dataKeys[0];
          pendingDataSize += data.byteLength;
        };

        const ref = /** @type {!shaka.media.SegmentReference} */ (
          download.ref);
        const segmentData =
            ref.getSegmentData(/* allowDeleteOnSingleUse= */ false);
        if (segmentData) {
          downloader.queueData(download.groupId,
              segmentData, estimateId, isInitSegment, onDownloaded);
        } else {
          downloader.queue(download.groupId,
              request, estimateId, isInitSegment, onDownloaded);
        }
      }
      await downloader.waitToFinish();
      ensureNotAbortedOrDestroyed();

      if (updateDRM && !downloader.isAborted()) {
        // Re-store the manifest, to attach session IDs.
        // These were (maybe) discovered inside the downloader; we can only add
        // them now, at the end, since the manifestDB is in flux during the
        // process of downloading and storing, and assignSegmentsToManifest
        // does not know about the DRM engine.
        this.setManifestDrmFields_(
            manifest, manifestDB, drmEngine, usePersistentLicense);
        await storage.updateManifest(manifestId, manifestDB);
      }
    }
@param {!Array<!shaka.offline.DownloadInfo>} toDownload
@param {boolean} updateDRM