OLD | NEW |
1 // Copyright (c) 2011 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 /** | 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 if (!opt_workerPath) { | 14 if (!opt_workerPath) { |
15 var path = document.location.pathname; | 15 var path = document.location.pathname; |
16 opt_workerPath = document.location.origin + | 16 opt_workerPath = document.location.origin + |
17 path.substring(0, path.lastIndexOf('/') + 1) + | 17 path.substring(0, path.lastIndexOf('/') + 1) + |
18 'js/metadata_dispatcher.js'; | 18 'js/metadata/metadata_dispatcher.js'; |
19 } | 19 } |
20 | 20 |
21 this.dispatcher_ = new Worker(opt_workerPath); | 21 this.dispatcher_ = new Worker(opt_workerPath); |
22 this.dispatcher_.onmessage = this.onMessage_.bind(this); | 22 this.dispatcher_.onmessage = this.onMessage_.bind(this); |
23 this.dispatcher_.postMessage({verb: 'init'}); | 23 this.dispatcher_.postMessage({verb: 'init'}); |
24 // Initialization is not complete until the Worker sends back the | 24 // Initialization is not complete until the Worker sends back the |
25 // 'initialized' message. See below. | 25 // 'initialized' message. See below. |
26 } | 26 } |
27 | 27 |
28 MetadataProvider.prototype.fetch = function(url, callback) { | 28 MetadataProvider.prototype.fetch = function(url, callback) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 }; | 106 }; |
107 | 107 |
108 MetadataProvider.prototype.onError_ = function(url, step, error, metadata) { | 108 MetadataProvider.prototype.onError_ = function(url, step, error, metadata) { |
109 console.warn('metadata: ' + url + ': ' + step + ': ' + error); | 109 console.warn('metadata: ' + url + ': ' + step + ': ' + error); |
110 this.onResult_(url, metadata || {}); | 110 this.onResult_(url, metadata || {}); |
111 }; | 111 }; |
112 | 112 |
113 MetadataProvider.prototype.onLog_ = function(arglist) { | 113 MetadataProvider.prototype.onLog_ = function(arglist) { |
114 console.log.apply(console, ['metadata:'].concat(arglist)); | 114 console.log.apply(console, ['metadata:'].concat(arglist)); |
115 }; | 115 }; |
OLD | NEW |