This source file includes following definitions.
- GetDownloadsFolderForProfile
- MigratePathFromOldFormat
- GetDownloadsMountPointName
#include "chrome/browser/chromeos/file_manager/path_util.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/sys_info.h"
#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"
namespace file_manager {
namespace util {
namespace {
const char kDownloadsFolderName[] = "Downloads";
const base::FilePath::CharType kOldDownloadsFolderPath[] =
FILE_PATH_LITERAL("/home/chronos/user/Downloads");
const base::FilePath::CharType kOldDriveFolderPath[] =
FILE_PATH_LITERAL("/special/drive");
}
base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
if (!base::SysInfo::IsRunningOnChromeOS() &&
!chromeos::UserManager::IsMultipleProfilesAllowed()) {
base::FilePath path;
CHECK(PathService::Get(base::DIR_HOME, &path));
return path.AppendASCII(kDownloadsFolderName);
}
return profile->GetPath().AppendASCII(kDownloadsFolderName);
}
bool MigratePathFromOldFormat(Profile* profile,
const base::FilePath& old_path,
base::FilePath* new_path) {
const base::FilePath downloads = GetDownloadsFolderForProfile(profile);
const base::FilePath drive = drive::util::GetDriveMountPointPath(profile);
std::vector<std::pair<base::FilePath, base::FilePath> > 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));
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)) {
*new_path = new_base.Append(relative);
return old_path != *new_path;
}
}
return false;
}
std::string GetDownloadsMountPointName(Profile* profile) {
chromeos::User* const user =
chromeos::UserManager::IsInitialized() ?
chromeos::UserManager::Get()->GetUserByProfile(
profile->GetOriginalProfile()) : NULL;
const std::string id = user ? "-" + user->username_hash() : "";
return net::EscapePath(kDownloadsFolderName + id);
}
}
}