Commit aa54948f authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Add closure compiler check to camera view.

Bug: b/141518780
Test: Pass closure compiler check, tast run <DUT> 'camera.CCAUI*' and
validate all function of CCA on HALv1/v3 device works correctly.

Change-Id: Ia03c36bc0e92345f45a7b1d9c73c5ee0ca2418e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1926091
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718048}
parent db479fec
......@@ -214,7 +214,6 @@ cca.device.DeviceInfoUpdater = class {
* Gets MediaDeviceInfo of specific video device.
* @param {string} deviceId Device id of video device to get information from.
* @return {!Promise<?MediaDeviceInfo>}
* @private
*/
async getDeviceInfo(deviceId) {
const /** !Array<!MediaDeviceInfo> */ infos = await this.getDevicesInfo();
......
......@@ -80,6 +80,17 @@ var Resolution = class {
}
};
/**
* Capture modes.
* @enum {string}
*/
var Mode = {
PHOTO: 'photo-mode',
VIDEO: 'video-mode',
SQUARE: 'square-mode',
PORTRAIT: 'portrait-mode',
};
/**
* @typedef {{
* width: number,
......
......@@ -13,11 +13,36 @@ group("closure_compile") {
js_type_check("compile_resources") {
deps = [
":camera",
":camera_intent",
":settings",
":view",
]
}
js_library("camera") {
deps = [
"..:chrome_util",
"..:metrics",
"..:type",
"../models:result_saver",
"camera:layout",
"camera:modes",
"camera:options",
"camera:preview",
"camera:timertick",
]
}
js_library("camera_intent") {
deps = [
":camera",
"..:chrome_util",
"../models:video_saver",
"camera:review_result",
]
}
js_library("settings") {
deps = [
":view",
......
......@@ -18,6 +18,7 @@ js_type_check("compile_resources") {
":preview",
":recordtime",
":review_result",
":timertick",
"../../mojo:device_operator",
]
}
......@@ -74,3 +75,6 @@ js_library("review_result") {
"../..:util",
]
}
js_library("timertick") {
}
......@@ -19,6 +19,11 @@ cca.views = cca.views || {};
*/
cca.views.camera = cca.views.camera || {};
/**
* import {Mode} from '../chrome_util.js';
*/
var Mode = Mode || {};
/* eslint-disable no-unused-vars */
/**
......@@ -79,17 +84,6 @@ cca.views.camera.PlayShutterEffect;
/* eslint-enable no-unused-vars */
/**
* Capture modes.
* @enum {string}
*/
cca.views.camera.Mode = {
PHOTO: 'photo-mode',
VIDEO: 'video-mode',
SQUARE: 'square-mode',
PORTRAIT: 'portrait-mode',
};
/**
* The abstract interface for the mode configuration.
* @interface
......@@ -129,7 +123,7 @@ cca.views.camera.ModeConfig = class {
/**
* Mode to be fallbacked to when fail to configure this mode.
* @return {!cca.views.camera.Mode}
* @return {!Mode}
* @abstract
*/
get nextMode() {}
......@@ -149,7 +143,7 @@ cca.views.camera.ModeConfig = class {
*/
cca.views.camera.Modes = class {
/**
* @param {!cca.views.camera.Mode} defaultMode Default mode to be switched to.
* @param {!Mode} defaultMode Default mode to be switched to.
* @param {!cca.device.PhotoConstraintsPreferrer} photoPreferrer
* @param {!cca.device.VideoConstraintsPreferrer} videoPreferrer
* @param {!cca.views.camera.DoSwitchMode} doSwitchMode
......@@ -230,11 +224,11 @@ cca.views.camera.Modes = class {
/**
* Mode classname and related functions and attributes.
* @type {!Object<!cca.views.camera.Mode, !cca.views.camera.ModeConfig>}
* @type {!Object<!Mode, !cca.views.camera.ModeConfig>}
* @private
*/
this.allModes_ = {
[cca.views.camera.Mode.VIDEO]: {
[Mode.VIDEO]: {
captureFactory: () => new cca.views.camera.Video(
/** @type {!MediaStream} */ (this.stream_), createVideoSaver,
doSaveVideo),
......@@ -244,7 +238,7 @@ cca.views.camera.Modes = class {
nextMode: 'photo-mode',
captureIntent: cros.mojom.CaptureIntent.VIDEO_RECORD,
},
[cca.views.camera.Mode.PHOTO]: {
[Mode.PHOTO]: {
captureFactory: () => new cca.views.camera.Photo(
/** @type {!MediaStream} */ (this.stream_), doSavePhoto,
this.captureResolution_, playShutterEffect),
......@@ -254,7 +248,7 @@ cca.views.camera.Modes = class {
nextMode: 'square-mode',
captureIntent: cros.mojom.CaptureIntent.STILL_CAPTURE,
},
[cca.views.camera.Mode.SQUARE]: {
[Mode.SQUARE]: {
captureFactory: () => new cca.views.camera.Square(
/** @type {!MediaStream} */ (this.stream_), doSavePhoto,
this.captureResolution_, playShutterEffect),
......@@ -264,7 +258,7 @@ cca.views.camera.Modes = class {
nextMode: 'portrait-mode',
captureIntent: cros.mojom.CaptureIntent.STILL_CAPTURE,
},
[cca.views.camera.Mode.PORTRAIT]: {
[Mode.PORTRAIT]: {
captureFactory: () => new cca.views.camera.Portrait(
/** @type {!MediaStream} */ (this.stream_), doSavePhoto,
this.captureResolution_, playShutterEffect),
......@@ -312,7 +306,7 @@ cca.views.camera.Modes = class {
/**
* Updates state of mode related UI to the target mode.
* @param {!cca.views.camera.Mode} mode Mode to be toggled.
* @param {!Mode} mode Mode to be toggled.
* @private
*/
updateModeUI_(mode) {
......@@ -338,13 +332,13 @@ cca.views.camera.Modes = class {
/**
* Gets all mode candidates. Desired trying sequence of candidate modes is
* reflected in the order of the returned array.
* @return {!Array<string>} Mode candidates to be tried out.
* @return {!Array<!Mode>} Mode candidates to be tried out.
*/
getModeCandidates() {
const tried = {};
const results = [];
let mode = /** @type {!cca.views.camera.Mode} */ (
Object.keys(this.allModes_).find(cca.state.get));
let mode =
/** @type {!Mode} */ (Object.keys(this.allModes_).find(cca.state.get));
while (!tried[mode]) {
tried[mode] = true;
results.push(mode);
......@@ -356,7 +350,7 @@ cca.views.camera.Modes = class {
/**
* Gets all available capture resolution and its corresponding preview
* constraints for the given mode.
* @param {!cca.views.camera.Mode} mode
* @param {!Mode} mode
* @param {string} deviceId
* @param {!ResolutionList} previewResolutions
* @return {!Array<!CaptureCandidate>}
......@@ -369,7 +363,7 @@ cca.views.camera.Modes = class {
/**
* Gets capture resolution and its corresponding preview constraints for the
* given mode on camera HALv1 device.
* @param {!cca.views.camera.Mode} mode
* @param {!Mode} mode
* @param {?string} deviceId
* @return {!Promise<!Array<!CaptureCandidate>>}
*/
......@@ -381,7 +375,7 @@ cca.views.camera.Modes = class {
/**
* Gets capture intent for the given mode.
* @param {!cca.views.camera.Mode} mode
* @param {!Mode} mode
* @return {cros.mojom.CaptureIntent} Capture intent for the given mode.
*/
getCaptureIntent(mode) {
......@@ -391,7 +385,7 @@ cca.views.camera.Modes = class {
/**
* Gets supported modes for video device of given device id.
* @param {?string} deviceId Device id of the video device.
* @return {!Promise<!Array<!cca.views.camera.Mode>>} All supported mode for
* @return {!Promise<!Array<!Mode>>} All supported mode for
* the video device.
*/
async getSupportedModes(deviceId) {
......@@ -422,7 +416,7 @@ cca.views.camera.Modes = class {
/**
* Creates and updates new current mode object.
* @param {!cca.views.camera.Mode} mode Classname of mode to be updated.
* @param {!Mode} mode Classname of mode to be updated.
* @param {!MediaStream} stream Stream of the new switching mode.
* @param {?string} deviceId Device id of currently working video device.
* @param {?Resolution} captureResolution Capturing resolution width and
......
......@@ -23,9 +23,14 @@ cca.views.camera = cca.views.camera || {};
*/
cca.views.camera.timertick = cca.views.camera.timertick || {};
/**
* import {assertInstanceof} from '../chrome_util.js';
*/
var assertInstanceof = assertInstanceof || {};
/**
* Handler to cancel the active running timer-ticks.
* @type {function()}
* @type {?function()}
* @private
*/
cca.views.camera.timertick.cancel_ = null;
......@@ -40,8 +45,9 @@ cca.views.camera.timertick.start = function() {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
var tickTimeout = null;
var tickMsg = document.querySelector('#timer-tick-msg');
let tickTimeout = null;
const tickMsg = assertInstanceof(
document.querySelector('#timer-tick-msg'), HTMLElement);
cca.views.camera.timertick.cancel_ = () => {
if (tickTimeout) {
clearTimeout(tickTimeout);
......@@ -59,7 +65,7 @@ cca.views.camera.timertick.start = function() {
[tickCounter]: '#sound-tick-start',
};
var onTimerTick = () => {
if (tickCounter == 0) {
if (tickCounter === 0) {
resolve();
} else {
if (sounds[tickCounter] !== undefined) {
......
......@@ -14,6 +14,11 @@ var cca = cca || {};
*/
cca.views = cca.views || {};
/**
* import {assert, assertNotReached} from '../chrome_util.js';
*/
var {assert, assertNotReached} = {assert, assertNotReached};
/**
* The maximum number of pixels in the downscaled intent photo result. Reference
* from GCA: https://goto.google.com/gca-inline-bitmap-max-pixel-num
......@@ -33,7 +38,7 @@ cca.views.CameraIntent = class extends cca.views.Camera {
* @param {!cca.device.VideoConstraintsPreferrer} videoPreferrer
*/
constructor(intent, infoUpdater, photoPreferrer, videoPreferrer) {
const resultSaver = {
const resultSaver = /** @type {!cca.models.ResultSaver} */ ({
savePhoto: async (blob) => {
if (intent.shouldDownScale) {
const image = await cca.util.blobToImage(blob);
......@@ -53,7 +58,7 @@ cca.views.CameraIntent = class extends cca.views.Camera {
finishSaveVideo: async (video, savedName) => {
this.videoResultFile_ = await video.endWrite();
},
};
});
super(resultSaver, infoUpdater, photoPreferrer, videoPreferrer);
/**
......@@ -117,9 +122,7 @@ cca.views.CameraIntent = class extends cca.views.Camera {
* @override
*/
beginTake_() {
if (this.photoResult_ !== null) {
URL.revokeObjectURL(this.photoResult_.blob);
}
// TODO(inker): Clean unused photo result blob properly.
this.photoResult_ = null;
this.videoResult_ = null;
......@@ -130,16 +133,17 @@ cca.views.CameraIntent = class extends cca.views.Camera {
return (async () => {
await take;
if (this.photoResult_ === null && this.videoResult_ === null) {
console.warn('End take without intent result.');
return;
}
cca.state.set('suspend', true);
await this.restart();
const confirmed = await (
this.photoResult_ !== null ?
this.reviewResult_.openPhoto(this.photoResult_.blob) :
this.reviewResult_.openVideo(this.videoResultFile_));
const confirmed = await (() => {
if (this.photoResult_ !== null) {
return this.reviewResult_.openPhoto(this.photoResult_.blob);
} else if (this.videoResultFile_ !== null) {
return this.reviewResult_.openVideo(this.videoResultFile_);
} else {
assertNotReached('End take without intent result.');
}
})();
const result = this.photoResult_ || this.videoResult_;
cca.metrics.log(
cca.metrics.Type.CAPTURE, this.facingMode_, result.duration || 0,
......@@ -162,6 +166,6 @@ cca.views.CameraIntent = class extends cca.views.Camera {
* @override
*/
async startWithDevice_(deviceId) {
return this.startWithMode_(deviceId, this.defaultMode);
return this.startWithMode_(deviceId, this.defaultMode_);
}
};
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