From fd901f964f820b7a24549b4fc82e7fc743949317 Mon Sep 17 00:00:00 2001 From: "kinaba@google.com" Date: Fri, 28 Mar 2014 08:54:03 +0000 Subject: [PATCH] Files.app multi-profile: add back migration to old path format. This CL adds Download folder path migration from /home/chronos/u-hash/Downloads to /home/chronos/user/Downloads when in the current running environment the profile path is set as the latter. It can happen when (1) the user enabled and then disabled the multi-profile flag, or (2) performed restart from about:flags. In such situations we need back migration not to break configurations. In addition, inserted path convertion to public functions in open_util so that paths stored in download history (during flipped path due to about:flags) can be correctly handled. BUG=356322,329744 R=hirono@chromium.org Review URL: https://codereview.chromium.org/216053002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260092 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chromeos/file_manager/open_util.cc | 23 ++++++++++--- chrome/browser/chromeos/file_manager/path_util.cc | 42 +++++++++++++++-------- chrome/browser/chromeos/file_manager/path_util.h | 12 ++++--- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/chrome/browser/chromeos/file_manager/open_util.cc b/chrome/browser/chromeos/file_manager/open_util.cc index 14cebb39d11e..45d107d5f132 100644 --- a/chrome/browser/chromeos/file_manager/open_util.cc +++ b/chrome/browser/chromeos/file_manager/open_util.cc @@ -14,6 +14,7 @@ #include "chrome/browser/chromeos/file_manager/file_tasks.h" #include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "chrome/browser/chromeos/file_manager/mime_util.h" +#include "chrome/browser/chromeos/file_manager/path_util.h" #include "chrome/browser/chromeos/file_manager/url_util.h" #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" #include "chrome/browser/extensions/extension_service.h" @@ -207,11 +208,18 @@ void OpenRemovableDrive(Profile* profile, const base::FilePath& file_path) { void OpenItem(Profile* profile, const base::FilePath& file_path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + // 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. + base::FilePath path; + if (!util::MigratePathFromOldFormat(profile, file_path, &path)) + path = file_path; + GURL url; if (!ConvertAbsoluteFilePathToFileSystemUrl( - profile, file_path, kFileManagerAppId, &url) || + profile, path, kFileManagerAppId, &url) || !GrantFileSystemAccessToFileBrowser(profile)) { - ShowWarningMessageBox(profile, file_path); + ShowWarningMessageBox(profile, path); return; } @@ -220,12 +228,19 @@ void OpenItem(Profile* profile, const base::FilePath& file_path) { profile, kFileManagerAppId); CheckIfDirectoryExists(file_system_context, url, - base::Bind(&ContinueOpenItem, profile, file_path)); + base::Bind(&ContinueOpenItem, profile, path)); } void ShowItemInFolder(Profile* profile, const base::FilePath& file_path) { + // 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. + base::FilePath path; + if (!util::MigratePathFromOldFormat(profile, file_path, &path)) + path = file_path; + // This action changes the selection so we do not reuse existing tabs. - OpenFileManagerWithInternalActionId(profile, file_path, "select"); + OpenFileManagerWithInternalActionId(profile, path, "select"); } } // namespace util diff --git a/chrome/browser/chromeos/file_manager/path_util.cc b/chrome/browser/chromeos/file_manager/path_util.cc index 91ef187378e2..7f5f35de6dc8 100644 --- a/chrome/browser/chromeos/file_manager/path_util.cc +++ b/chrome/browser/chromeos/file_manager/path_util.cc @@ -11,6 +11,7 @@ #include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/profiles/profile.h" #include "net/base/escape.h" @@ -25,8 +26,6 @@ const base::FilePath::CharType kOldDownloadsFolderPath[] = FILE_PATH_LITERAL("/home/chronos/user/Downloads"); const base::FilePath::CharType kOldDriveFolderPath[] = FILE_PATH_LITERAL("/special/drive"); -const base::FilePath::CharType kNoHashDriveFolderPath[] = - FILE_PATH_LITERAL("/special/drive-"); } // namespace @@ -60,19 +59,32 @@ bool MigratePathFromOldFormat(Profile* profile, const base::FilePath downloads = GetDownloadsFolderForProfile(profile); const base::FilePath drive = drive::util::GetDriveMountPointPath(profile); - const base::FilePath bases[][2] = { - {base::FilePath(kOldDownloadsFolderPath), downloads}, - {DownloadPrefs::GetDefaultDownloadDirectory(), downloads}, - {base::FilePath(kOldDriveFolderPath), drive}, - // TODO(kinaba): http://crbug.com/341284 Remove after M34 branching. - // For a short period we incorrectly set "/special/drive-" as the Drive path - // that needs to be fixed. - {base::FilePath(kNoHashDriveFolderPath), drive}, - }; - - for (size_t i = 0; i < arraysize(bases); ++i) { - const base::FilePath& old_base = bases[i][0]; - const base::FilePath& new_base = bases[i][1]; + + std::vector > bases; + bases.push_back(std::make_pair(base::FilePath(kOldDownloadsFolderPath), + downloads)); + bases.push_back(std::make_pair(DownloadPrefs::GetDefaultDownloadDirectory(), + downloads)); + bases.push_back(std::make_pair(base::FilePath(kOldDriveFolderPath), drive)); + + // Trying migrating u-/Downloads to the current download path. This is + // no-op when multi-profile is enabled. This is necessary for (1) back + // migration when multi-profile flag is enabled and then disabled, or (2) in + // some edge cases (crbug.com/356322) that u- path is temporarily used. + if (chromeos::UserManager::IsInitialized()) { + const chromeos::User* const user = + chromeos::UserManager::Get()->GetUserByProfile(profile); + if (user) { + const base::FilePath hashed_downloads = + chromeos::ProfileHelper::GetProfilePathByUserIdHash( + user->username_hash()).AppendASCII(kDownloadsFolderName); + bases.push_back(std::make_pair(hashed_downloads, downloads)); + } + } + + for (size_t i = 0; i < bases.size(); ++i) { + const base::FilePath& old_base = bases[i].first; + const base::FilePath& new_base = bases[i].second; base::FilePath relative; if (old_path == old_base || old_base.AppendRelativePath(old_path, &relative)) { diff --git a/chrome/browser/chromeos/file_manager/path_util.h b/chrome/browser/chromeos/file_manager/path_util.h index ac1b75b08428..3aee1b891396 100644 --- a/chrome/browser/chromeos/file_manager/path_util.h +++ b/chrome/browser/chromeos/file_manager/path_util.h @@ -33,18 +33,20 @@ base::FilePath GetDownloadsFolderForProfile(Profile* profile); // // M34: crbug.com/313539 // The "Downloads" folder is changed from /home/chronos/user/Downloads to -// /home/chronos/u-/Downloads to support multi profiles. +// /home/chronos/u-/Downloads when multi-profile is enabled. // // The path "/home/chronos/user" is a hard link to the u- directory of // the primary profile of the current session. The two paths always meant the // same directory before multi-profiles. However, for secondary profiles in // a multi-profile session, the "user" path cannot be used to mean "its own" // Download folder anymore. Thus we are switching to always use "u-" -// that consistently works whether or not multi-profile is enabled. +// that consistently works whether or not it is primary. // -// M34: crbug.com/336123 -// The "Google Drive" folder is changed from /special/drive to -// /special/drive- to support multi profiles. +// M35: crbug.com/356322 +// It turned out even if multi-profile is disabled, u- style profile +// can be used in some situations. To address the cases, we add a migration +// from /home/chronos/u-/Downloads to current Download path. +// This just results in no-op when multi-profile is enabled. bool MigratePathFromOldFormat(Profile* profile, const base::FilePath& old_path, base::FilePath* new_path); -- 2.11.4.GIT