+// Converts the |given_path| passed from external callers to the form that the
+// file manager can correctly handle. It first migrates old Drive/Download
+// folder path to the new formats, and then converts path to filesystem URL.
+//
+// When conversion fails, it shows a warning dialog UI and returns false.
+bool ConvertPath(Profile* profile,
+ const base::FilePath& given_path,
+ base::FilePath* path,
+ GURL* url) {
+ // The path may have been stored in preferences in old versions.
+ // We need migration here.
+ // TODO(kinaba): crbug.com/313539 remove it in the future.
+ if (!util::MigratePathFromOldFormat(profile, given_path, path))
+ *path = given_path;
+
+ if (!ConvertAbsoluteFilePathToFileSystemUrl(
+ profile, *path, kFileManagerAppId, url)) {
+ ShowWarningMessageBox(profile, *path,
+ IDS_FILE_BROWSER_ERROR_UNRESOLVABLE_FILE);
+ return false;
+ }
+ return true;
+}
+