Commit 21210ad1 authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

[CCA] Remove legacy migration logic

We have legacy migration logic since M69 to migrate photos/videos from
CCA internal storage to "MyFiles/Downloads" folder.

Since we are going to change the default camera folder from
"MyFiles/Downloads" to "MyFiles/Camera" and show a dialog/notification
to indicate user, it is preferable to remove such migration logic to
avoid increasing complexity and too many notifications when launching
app.

Bug: 1127587
Test: None
Change-Id: I6a576cfda3f3ea4d1b97f441710ad45687cf1b3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2407733
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809197}
parent edf06a33
...@@ -193,31 +193,11 @@ export class App { ...@@ -193,31 +193,11 @@ export class App {
try { try {
await filesystem.initialize(); await filesystem.initialize();
const promptMigrate = async () => {
// Prompt to migrate pictures if needed.
const message = browserProxy.getI18nMessage('migrate_pictures_msg');
const acked = await nav.open(
ViewName.MESSAGE_DIALOG, {message, cancellable: false});
if (!acked) {
throw new Error('no-migrate');
}
};
// Migrate pictures might take some time. Since it won't affect other
// camera functions, we don't await here to avoid harming UX.
filesystem.checkMigration(promptMigrate).then((ackMigrate) => {
metrics.sendLaunchEvent({ackMigrate});
});
const cameraDir = filesystem.getCameraDirectory(); const cameraDir = filesystem.getCameraDirectory();
assert(cameraDir !== null); assert(cameraDir !== null);
this.galleryButton_.initialize(cameraDir); this.galleryButton_.initialize(cameraDir);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
if (error && error.message === 'no-migrate') {
window.close();
return;
}
nav.open(ViewName.WARNING, 'filesystem-failure'); nav.open(ViewName.WARNING, 'filesystem-failure');
} }
...@@ -232,6 +212,8 @@ export class App { ...@@ -232,6 +212,8 @@ export class App {
nav.open(ViewName.CAMERA); nav.open(ViewName.CAMERA);
this.backgroundOps_.getPerfLogger().stopLaunch({hasError: !isSuccess}); this.backgroundOps_.getPerfLogger().stopLaunch({hasError: !isSuccess});
})(); })();
metrics.sendLaunchEvent({ackMigrate: false});
return Promise.all([showWindow, startCamera]); return Promise.all([showWindow, startCamera]);
} }
......
...@@ -11,12 +11,6 @@ import { ...@@ -11,12 +11,6 @@ import {
AbstractFileEntry, // eslint-disable-line no-unused-vars AbstractFileEntry, // eslint-disable-line no-unused-vars
} from './file_system_entry.js'; } from './file_system_entry.js';
/**
* The prefix of thumbnail files.
* @type {string}
*/
const THUMBNAIL_PREFIX = 'thumb-';
/** /**
* Checks if the entry's name has the video prefix. * Checks if the entry's name has the video prefix.
* @param {!AbstractFileEntry} entry File entry. * @param {!AbstractFileEntry} entry File entry.
...@@ -93,47 +87,6 @@ async function initCameraDirectory() { ...@@ -93,47 +87,6 @@ async function initCameraDirectory() {
return browserProxy.getCameraDirectory(); return browserProxy.getCameraDirectory();
} }
/**
* Regulates the picture name to the desired format if it's in legacy formats.
* @param {!AbstractFileEntry} entry Picture entry whose name to be regulated.
* @return {string} Name in the desired format.
*/
function regulatePictureName(entry) {
if (hasVideoPrefix(entry) || hasImagePrefix(entry)) {
const match = entry.name.match(/(\w{3}_\d{8}_\d{6})(?:_(\d+))?(\..+)?$/);
if (match) {
const idx = match[2] ? ' (' + match[2] + ')' : '';
const ext = match[3] ? match[3].replace(/\.webm$/, '.mkv') : '';
return match[1] + idx + ext;
}
} else {
// Early pictures are in legacy file name format (crrev.com/c/310064).
const match = entry.name.match(/(\d+).(?:\d+)/);
if (match) {
return (new Filenamer(parseInt(match[1], 10))).newImageName();
}
}
return entry.name;
}
/**
* Migrates all picture-files except thumbnails from internal storage to
* external storage. For thumbnails, we just remove them.
* @return {!Promise} Promise for the operation.
*/
async function migratePictures() {
assert(cameraDir !== null);
const internalEntries = await internalDir.getFiles();
for (const entry of internalEntries) {
if (entry.name.startsWith(THUMBNAIL_PREFIX)) {
await entry.remove();
continue;
}
const name = regulatePictureName(entry);
await entry.moveTo(cameraDir, name);
}
}
/** /**
* Initializes file systems. This function should be called only once in the * Initializes file systems. This function should be called only once in the
* beginning of the app. * beginning of the app.
...@@ -150,47 +103,6 @@ export async function initialize() { ...@@ -150,47 +103,6 @@ export async function initialize() {
assert(cameraDir !== null); assert(cameraDir !== null);
} }
/**
* Checks and performs migration if it's needed.
* @param {function(): !Promise} promptMigrate Callback to instantiate a promise
* that prompts users to migrate pictures if no acknowledgement yet.
* @return {!Promise<boolean>} Return a promise that will be resolved to a
* boolean indicates if the user ackes the migration dialog once the
* migration is skipped or completed.
*/
export async function checkMigration(promptMigrate) {
const isDoneMigration =
(await browserProxy.localStorageGet({doneMigration: 0}))['doneMigration'];
if (isDoneMigration) {
return false;
}
const doneMigrate = () => browserProxy.localStorageSet({doneMigration: 1});
const ackMigrate = () =>
browserProxy.localStorageSet({ackMigratePictures: 1});
const internalEntries = await internalDir.getFiles();
const migrationNeeded = internalEntries.length > 0;
if (!migrationNeeded) {
// If there is already no picture in the internal file system, it implies
// done migration and then doesn't need acknowledge-prompt.
await ackMigrate();
await doneMigrate();
return false;
}
const isAckedMigration = (await browserProxy.localStorageGet(
{ackMigratePictures: 0}))['ackMigratePictures'];
if (!isAckedMigration) {
await promptMigrate();
await ackMigrate();
}
await migratePictures();
await doneMigrate();
return !isAckedMigration;
}
/** /**
* Saves photo blob or metadata blob into predefined default location. * Saves photo blob or metadata blob into predefined default location.
* @param {!Blob} blob Data of the photo to be saved. * @param {!Blob} blob Data of the photo to be saved.
......
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