1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * The model class for audio player.
9 function AudioPlayerModel() {}
11 AudioPlayerModel.prototype.initialize = function(callback) {
15 * List of values to be stored into the model.
21 * They will be used as properties of AudioPlayerModel.
22 * @lends {AudioPlayerModel.prototype}
32 * Prefix of the stored values in the storage.
35 var STORAGE_PREFIX = 'audioplayer-';
38 * Save the values in the model into the storage.
39 * @param {AudioPlayerModel} model The model.
41 function saveModel(model) {
42 var objectToBeSaved = {};
43 for (var key in VALUES) {
44 objectToBeSaved[STORAGE_PREFIX + key] = model[key];
47 chrome.storage.local.set(objectToBeSaved);
51 * Load the values in the model from the storage.
52 * @param {AudioPlayerModel} model The model.
53 * @param {function()} inCallback Called when the load is completed.
55 function loadModel(model, inCallback) {
56 // Restores the values from the storage
57 var objectsToBeRead = Object.keys(VALUES).
59 return STORAGE_PREFIX + a;
62 chrome.storage.local.get(objectsToBeRead, function(result) {
63 for (var key in result) {
65 model[key.substr(STORAGE_PREFIX.length)] = result[key];
71 // Initializes values.
72 for (var key in VALUES) {
73 this[key] = VALUES[key];
77 // Restores the values from the storage
79 loadModel(target, function() {
80 // Installs observer to watch changes of the values.
81 Object.observe(target, function(changes) {