cache-service.js
5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
/* globals Promise */
define('screens/player/firmware/cache/impl/cache-service', [
'underscore',
'screens/player/shared/serviceadmin',
'screens/player/firmware/core/firmware/firmware',
'screens/player/firmware/cache/cache',
'screens/player/firmware/cache/spi/cache',
'screens/player/store/store',
'module'
], function(_, ServiceAdmin, Firmware, Cache, CacheSPI, Store, mod) {
'use strict';
function _stopBridge() {
// workaround to stop the bridge until we have a proper service
var firmwareSvc = ServiceAdmin.getService(Firmware.serviceName);
return firmwareSvc.getPlayer().bridge.stop();
}
function _reboot() {
var firmwareSvc = ServiceAdmin.getService(Firmware.serviceName);
firmwareSvc.reboot();
}
function reportError(err) {
console.error(err);
}
function dispatchDone() {
this._store.dispatch({ type: Cache.ACTIONS.CLEAR_DONE });
}
/**
* Implements the cache service
*
* @class CacheService
* @implements {Player.Cache}
*/
var CacheService = function() {};
CacheService.serviceName = Cache.serviceName;
CacheService.prototype = _.assign({}, Cache, {
serviceId: mod.id,
/**
* @function CacheService#activate
* @inheritdoc
*/
activate: function() {
var self = this;
// wait for the store and device cache service to start.
return new Promise(function(resolve) {
ServiceAdmin.onServiceHighestRankedStart(Store.serviceName, function(store) {
self._store = store;
resolve(store);
});
})
.then(function(store) {
return new Promise(function(resolve) {
ServiceAdmin.onServiceHighestRankedStart(CacheSPI.serviceName, function(spi) {
self._spi = spi;
resolve();
});
});
});
},
/**
* @function CacheService#deactivate
* @inheritdoc
*/
deactivate: function() {
delete this._store;
delete this._spi;
},
/**
* @function CacheService#resetFirmware
* @inheritdoc
*/
resetFirmware: function(flags) {
flags = flags || {};
this._store.dispatch({ type: Cache.ACTIONS.RESET_FIRMWARE });
_stopBridge()
.then(function() { return this._spi.resetFirmware(); }.bind(this))
.catch(reportError)
.then(dispatchDone.bind(this))
.then(function() {
if (flags[Cache.FLAGS.REBOOT_ON_COMPLETE]) {
_reboot();
}
});
},
/**
* @function CacheService#clearChannelsData
* @inheritdoc
*/
clearChannelsData: function(flags) {
flags = flags || {};
this._store.dispatch({ type: Cache.ACTIONS.CLEAR_CHANNELS_DATA });
_stopBridge()
.then(function() { return this._spi.clearChannelsData(); }.bind(this))
.catch(reportError)
.then(dispatchDone.bind(this))
.then(function() {
if (flags[Cache.FLAGS.REBOOT_ON_COMPLETE]) {
_reboot();
}
});
},
/**
* @function CacheService#clearAppCache
* @inheritdoc
*/
clearAppCache: function(flags) {
flags = flags || {};
this._store.dispatch({ type: Cache.ACTIONS.CLEAR_APP_CACHE });
_stopBridge()
.then(function() { return this._spi.clearAppCache(); }.bind(this))
.catch(reportError)
.then(dispatchDone.bind(this))
.then(function() { this._store.reset(); }.bind(this))
.then(function() {
if (flags[Cache.FLAGS.REBOOT_ON_COMPLETE]) {
_reboot();
}
});
},
/**
* @function CacheService#clearAll
* @inheritdoc
*/
clearAll: function(flags) {
flags = flags || {};
this._store.dispatch({ type: Cache.ACTIONS.CLEAR_ALL });
_stopBridge()
.then(function() { return this._spi.clearChannelsData(); }.bind(this))
.then(function() { return this._spi.clearAppCache(); }.bind(this))
.catch(reportError)
.then(dispatchDone.bind(this))
.then(function() { return this._store.reset(); }.bind(this))
.then(function() {
if (flags[Cache.FLAGS.REBOOT_ON_COMPLETE]) {
_reboot();
}
});
}
});
return CacheService;
});
/* istanbul ignore next */
require([
'screens/player/firmware/cache/impl/cache-service',
'screens/player/shared/serviceadmin'
], function(Service, ServiceAdmin) {
'use strict';
ServiceAdmin.register(new Service());
});