| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file simulates a typical background process of an offline-capable | 5 // This file simulates a typical background process of an offline-capable |
| 6 // authoring application. When in an "online" state it receives chunks of | 6 // authoring application. When in an "online" state it receives chunks of |
| 7 // data updates from a simulated server and stores them in a temporary IDB | 7 // data updates from a simulated server and stores them in a temporary IDB |
| 8 // data store. On a different timer, the chunks are drained from the | 8 // data store. On a different timer, the chunks are drained from the |
| 9 // temporary store and combined into larger records in a permanent store. | 9 // temporary store and combined into larger records in a permanent store. |
| 10 // When in an "offline" state, nothing else happens. | 10 // When in an "offline" state, nothing else happens. |
| 11 | 11 |
| 12 self.indexedDB = self.indexedDB || self.webkitIndexedDB || | |
| 13 self.mozIndexedDB; | |
| 14 self.IDBKeyRange = self.IDBKeyRange || self.webkitIDBKeyRange; | |
| 15 | |
| 16 function unexpectedErrorCallback(e) { | 12 function unexpectedErrorCallback(e) { |
| 17 self.postMessage({type: 'ERROR', error: { name: e.target.error.name }, | 13 self.postMessage({type: 'ERROR', error: { |
| 18 webkitErrorMessage: e.target.webkitErrorMessage}); | 14 name: e.target.error.name, |
| 15 message: e.target.error.message |
| 16 }}); |
| 19 } | 17 } |
| 20 | 18 |
| 21 function unexpectedAbortCallback(e) { | 19 function unexpectedAbortCallback(e) { |
| 22 self.postMessage({type: 'ABORT', error: { name: e.target.error.name }, | 20 self.postMessage({type: 'ABORT', error: { |
| 23 webkitErrorMessage: e.target.webkitErrorMessage}); | 21 name: e.target.error.name, |
| 22 message: e.target.error.message |
| 23 }}); |
| 24 } | 24 } |
| 25 | 25 |
| 26 function log(message) { | 26 function log(message) { |
| 27 self.postMessage({type: 'LOG', message: message}); | 27 self.postMessage({type: 'LOG', message: message}); |
| 28 } | 28 } |
| 29 | 29 |
| 30 function error(message) { | 30 function error(message) { |
| 31 self.postMessage({type: 'ERROR', message: message}); | 31 self.postMessage({type: 'ERROR', message: message}); |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 }; | 215 }; |
| 216 transaction.onabort = unexpectedAbortCallback; | 216 transaction.onabort = unexpectedAbortCallback; |
| 217 transaction.oncomplete = function () { | 217 transaction.oncomplete = function () { |
| 218 log('combine ' + combine_id + | 218 log('combine ' + combine_id + |
| 219 ' finished, processed ' + combine_chunk_count + ' chunks'); | 219 ' finished, processed ' + combine_chunk_count + ' chunks'); |
| 220 db.close(); | 220 db.close(); |
| 221 combineTimeoutId = setTimeout(combine, COMBINE_TIMEOUT); | 221 combineTimeoutId = setTimeout(combine, COMBINE_TIMEOUT); |
| 222 }; | 222 }; |
| 223 }; | 223 }; |
| 224 } | 224 } |
| OLD | NEW |