mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-19 16:47:01 +03:00
1cf0a38843
Added a DB Upgrade path for converting content from version 1 to the version 2 format. Issue #1047 Change-Id: Id8dc626d8289b08ca300c40b137173c0c6ec9d35
88 lines
2.2 KiB
JavaScript
88 lines
2.2 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
goog.provide('shaka.offline.DBUtils');
|
|
|
|
|
|
/**
|
|
* @enum {string}
|
|
*/
|
|
shaka.offline.DBUtils.Mode = {
|
|
READ_ONLY: 'readonly',
|
|
READ_WRITE: 'readwrite'
|
|
};
|
|
|
|
|
|
/**
|
|
* The name for the stores that are used in the version 2 of our
|
|
* indexed db storage.
|
|
*
|
|
* @enum {string}
|
|
*/
|
|
shaka.offline.DBUtils.StoreV2 = {
|
|
MANIFEST: 'manifest-v2',
|
|
SEGMENT: 'segment-v2'
|
|
};
|
|
|
|
|
|
/**
|
|
* The name for the stores that are used in the version 1 of our
|
|
* indexed db storage.
|
|
*
|
|
* @enum {string}
|
|
*/
|
|
shaka.offline.DBUtils.StoreV1 = {
|
|
MANIFEST: 'manifest',
|
|
SEGMENT: 'segment'
|
|
};
|
|
|
|
|
|
/**
|
|
* @param {IDBObjectStore} store
|
|
* @param {function(number, Object)} callback
|
|
*/
|
|
shaka.offline.DBUtils.forEach = function(store, callback) {
|
|
/** @type {IDBRequest} */
|
|
var request = store.openCursor();
|
|
|
|
request.onsuccess = function(event) {
|
|
/** @type {IDBCursor} */
|
|
var cursor = event.target.result;
|
|
|
|
if (!cursor) {
|
|
// When we reach the end of the data that the cursor is iterating
|
|
// over, |event.target.result| will be null to signal the end of the
|
|
// iteration.
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor/continue
|
|
return;
|
|
}
|
|
|
|
// Save the key and value so that we can still access them even if the
|
|
// database's state changes because of the callback.
|
|
/** @type {number} */
|
|
var key = /** @type {number} */ (cursor.key);
|
|
/** @type {Object} */
|
|
var value = /** @type {Object} */ (cursor.value);
|
|
|
|
// Advance the cursor before calling the callback so that it will work
|
|
// even if the database's state changes because of the callback.
|
|
cursor.continue();
|
|
|
|
callback(key, value);
|
|
};
|
|
};
|