OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 /** | 5 /** |
6 * @param {string} opt_workerPath path to the worker source JS file. | 6 * @param {string} opt_workerPath path to the worker source JS file. |
7 */ | 7 */ |
8 function MetadataProvider(opt_workerPath) { | 8 function MetadataProvider(opt_workerPath) { |
9 this.cache_ = {}; | 9 this.cache_ = {}; |
10 | 10 |
11 // Pass all URLs to the metadata reader until we have a correct filter. | 11 // Pass all URLs to the metadata reader until we have a correct filter. |
12 this.urlFilter = /.*/; | 12 this.urlFilter = /.*/; |
13 | 13 |
14 this.dispatcher_ = new Worker(opt_workerPath || 'js/metadata_dispatcher.js'); | 14 this.dispatcher_ = new Worker(opt_workerPath || |
| 15 document.location.origin + '/js/metadata_dispatcher.js'); |
15 this.dispatcher_.onmessage = this.onMessage_.bind(this); | 16 this.dispatcher_.onmessage = this.onMessage_.bind(this); |
16 this.dispatcher_.postMessage({verb: 'init'}); | 17 this.dispatcher_.postMessage({verb: 'init'}); |
17 // Initialization is not complete until the Worker sends back the | 18 // Initialization is not complete until the Worker sends back the |
18 // 'initialized' message. See below. | 19 // 'initialized' message. See below. |
19 } | 20 } |
20 | 21 |
21 MetadataProvider.prototype.fetch = function(url, callback) { | 22 MetadataProvider.prototype.fetch = function(url, callback) { |
22 var cacheValue = this.cache_[url]; | 23 var cacheValue = this.cache_[url]; |
23 | 24 |
24 if (!cacheValue) { | 25 if (!cacheValue) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 this.cache_[url] = metadata; | 99 this.cache_[url] = metadata; |
99 }; | 100 }; |
100 | 101 |
101 MetadataProvider.prototype.onError_ = function(url, step, error, metadata) { | 102 MetadataProvider.prototype.onError_ = function(url, step, error, metadata) { |
102 console.warn('metadata: ' + url + ': ' + step + ': ' + error); | 103 console.warn('metadata: ' + url + ': ' + step + ': ' + error); |
103 this.onResult_(url, metadata || {}); | 104 this.onResult_(url, metadata || {}); |
104 }; | 105 }; |
105 | 106 |
106 MetadataProvider.prototype.onLog_ = function(arglist) { | 107 MetadataProvider.prototype.onLog_ = function(arglist) { |
107 console.log.apply(console, ['metadata:'].concat(arglist)); | 108 console.log.apply(console, ['metadata:'].concat(arglist)); |
108 }; | 109 }; |
OLD | NEW |