Commit 58af8f4d authored by yawano's avatar yawano Committed by Commit bot

Add type annotations to metadata_dispatcher.js.

BUG=444510
TEST=GYP_GENERATORS=ninja tools/gyp/gyp --depth . ui/file_manager/file_manager/foreground/js/metadata/compiled_resources.gyp && ninja -C out/Default

Review URL: https://codereview.chromium.org/824003004

Cr-Commit-Position: refs/heads/master@{#309625}
parent c5278d7b
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Externs which are common for all worker of chrome packaged apps.
/**
* @param {string} url
* @param {function(!Entry)} successCallback
* @param {function(!FileError)=} opt_errorCallback
*/
function webkitResolveLocalFileSystemURL(
url, successCallback, opt_errorCallback) {}
......@@ -199,26 +199,6 @@ util.bytesToString = function(bytes) {
return fmt(STEPS[i], UNITS[i]);
};
/**
* Utility function to read specified range of bytes from file
* @param {File} file The file to read.
* @param {number} begin Starting byte(included).
* @param {number} end Last byte(excluded).
* @param {function(File, ByteReader)} callback Callback to invoke.
* @param {function(string)} onError Error handler.
*/
util.readFileBytes = function(file, begin, end, callback, onError) {
var fileReader = new FileReader();
fileReader.onerror = function(event) {
onError(event.type);
};
fileReader.onloadend = function() {
callback(file, new ByteReader(
/** @type {ArrayBuffer} */ (fileReader.result)));
};
fileReader.readAsArrayBuffer(file.slice(begin, end));
};
/**
* Returns a string '[Ctrl-][Alt-][Shift-][Meta-]' depending on the event
* modifiers. Convenient for writing out conditions in keyboard handlers.
......
......@@ -13,8 +13,10 @@
'image_parsers.js',
'mpeg_parser.js',
'id3_parser.js',
'../../../common/js/util.js',
],
'externs': [
'../../../../externs/platform_worker.js',
]
},
'includes': [
'../../../../../../third_party/closure_compiler/compile_js.gypi'
......
......@@ -267,7 +267,7 @@ Id3Parser.prototype.parse = function(file, metadata, callback, onError) {
* @param {File} file File which bytes to read.
*/
function readTail(file) {
util.readFileBytes(file, file.size - 128, file.size,
MetadataParser.readFileBytes(file, file.size - 128, file.size,
this.nextStep, this.onError);
},
......@@ -311,7 +311,8 @@ Id3Parser.prototype.parse = function(file, metadata, callback, onError) {
'id3v2parser',
[
function readHead(file) {
util.readFileBytes(file, 0, 10, this.nextStep, this.onError);
MetadataParser.readFileBytes(file, 0, 10, this.nextStep,
this.onError);
},
/**
......@@ -329,8 +330,8 @@ Id3Parser.prototype.parse = function(file, metadata, callback, onError) {
id3v2.flags = reader.readScalar(1, false);
id3v2.size = Id3Parser.readSynchSafe_(reader, 4);
util.readFileBytes(file, 10, 10 + id3v2.size, this.nextStep,
this.onError);
MetadataParser.readFileBytes(file, 10, 10 + id3v2.size,
this.nextStep, this.onError);
} else {
this.finish();
}
......
......@@ -20,7 +20,7 @@ SimpleImageParser.prototype = {__proto__: ImageParser.prototype};
SimpleImageParser.prototype.parse = function(
file, metadata, callback, errorCallback) {
var self = this;
util.readFileBytes(
MetadataParser.readFileBytes(
file, 0, this.headerSize,
function(file, br) {
try {
......
......@@ -14,16 +14,13 @@ var FILE_MANAGER_HOST = 'chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj';
// line.
importScripts(FILE_MANAGER_HOST + '/foreground/js/metadata/metadata_parser.js');
importScripts(FILE_MANAGER_HOST + '/foreground/js/metadata/byte_reader.js');
// TODO(yawano): common/js/util.js seems to be imported only for
// util.readFileBytes. Investigate this, and move util.readFileBytes to this
// file, and remove this import.
importScripts(FILE_MANAGER_HOST + '/common/js/util.js');
/**
* Dispatches metadata requests to the correct parser.
*
* @param {Object} port Worker port.
* @constructor
* @struct
*/
function MetadataDispatcher(port) {
this.port_ = port;
......@@ -61,7 +58,8 @@ function MetadataDispatcher(port) {
MetadataDispatcher.parserClasses_ = [];
/**
* @param {function} parserClass Parser constructor function.
* @param {function(!MetadataDispatcher)} parserClass Parser constructor
* function.
*/
MetadataDispatcher.registerParserClass = function(parserClass) {
MetadataDispatcher.parserClasses_.push(parserClass);
......@@ -104,7 +102,7 @@ MetadataDispatcher.prototype.request_ = function(fileURL) {
* Indicate to the caller that an operation has failed.
*
* No other messages relating to the failed operation should be sent.
* @param {...Object} var_args Arguments.
* @param {...(Object|string)} var_args Arguments.
*/
MetadataDispatcher.prototype.error = function(var_args) {
var ary = Array.apply(null, arguments);
......@@ -115,7 +113,7 @@ MetadataDispatcher.prototype.error = function(var_args) {
* Send a log message to the caller.
*
* Callers must not parse log messages for control flow.
* @param {...Object} var_args Arguments.
* @param {...(Object|string)} var_args Arguments.
*/
MetadataDispatcher.prototype.log = function(var_args) {
var ary = Array.apply(null, arguments);
......@@ -124,7 +122,7 @@ MetadataDispatcher.prototype.log = function(var_args) {
/**
* Send a log message to the caller only if this.verbose is true.
* @param {...Object} var_args Arguments.
* @param {...(Object|string)} var_args Arguments.
*/
MetadataDispatcher.prototype.vlog = function(var_args) {
if (this.verbose)
......@@ -162,6 +160,9 @@ MetadataDispatcher.prototype.processOneFile = function(fileURL, callback) {
var self = this;
var currentStep = -1;
/**
* @param {...} var_args Arguments.
*/
function nextStep(var_args) {
self.vlog('nextStep: ' + steps[currentStep + 1].name);
steps[++currentStep].apply(self, arguments);
......@@ -169,8 +170,12 @@ MetadataDispatcher.prototype.processOneFile = function(fileURL, callback) {
var metadata;
function onError(err, stepName) {
self.error(fileURL, stepName || steps[currentStep].name, err.toString(),
/**
* @param {*} err An error.
* @param {string=} opt_stepName Step name.
*/
function onError(err, opt_stepName) {
self.error(fileURL, opt_stepName || steps[currentStep].name, err.toString(),
metadata);
}
......
......@@ -51,6 +51,26 @@ MetadataParser.prototype.createDefaultMetadata = function() {
};
};
/**
* Utility function to read specified range of bytes from file
* @param {File} file The file to read.
* @param {number} begin Starting byte(included).
* @param {number} end Last byte(excluded).
* @param {function(File, ByteReader)} callback Callback to invoke.
* @param {function(string)} onError Error handler.
*/
MetadataParser.readFileBytes = function(file, begin, end, callback, onError) {
var fileReader = new FileReader();
fileReader.onerror = function(event) {
onError(event.type);
};
fileReader.onloadend = function() {
callback(file, new ByteReader(
/** @type {ArrayBuffer} */ (fileReader.result)));
};
fileReader.readAsArrayBuffer(file.slice(begin, end));
};
/* Base class for image metadata parsers */
function ImageParser(parent, type, urlFilter) {
MetadataParser.apply(this, arguments);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment