• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/chromeos/file_manager/path_util.h"
6 
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h"
11 
12 namespace file_manager {
13 namespace util {
14 
15 const char kDownloadsFolderName[] = "Downloads";
16 const base::FilePath::CharType kOldDownloadsFolderPath[] =
17     FILE_PATH_LITERAL("/home/chronos/user/Downloads");
18 
GetDownloadsFolderForProfile(Profile * profile)19 base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
20   // TODO(kinaba) crbug/309556: "Downloads" directory should be per-profile.
21   //
22   // For this to be per-profile, a unique directory path from profile->GetPath()
23   // should be used rather than the HOME directory. We'll switch to the new path
24   // once we have upgraded all code locations assuming the old path.
25   base::FilePath path;
26   CHECK(PathService::Get(base::DIR_HOME, &path));
27   return path.AppendASCII(kDownloadsFolderName);
28 }
29 
MigratePathFromOldFormat(Profile * profile,const base::FilePath & old_path,base::FilePath * new_path)30 bool MigratePathFromOldFormat(Profile* profile,
31                               const base::FilePath& old_path,
32                               base::FilePath* new_path) {
33   // /special/drive/xxx => /special/drive/root/xxx
34   if (drive::util::NeedsNamespaceMigration(old_path)) {
35     *new_path = drive::util::ConvertToMyDriveNamespace(old_path);
36     return true;
37   }
38 
39   // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx
40   const base::FilePath old_base(kOldDownloadsFolderPath);
41   base::FilePath relative;
42   if (old_path == old_base ||
43       old_base.AppendRelativePath(old_path, &relative)) {
44     const base::FilePath new_base = GetDownloadsFolderForProfile(profile);
45     *new_path = new_base.Append(relative);
46     return old_path != *new_path;
47   }
48 
49   return false;
50 }
51 
52 
53 }  // namespace util
54 }  // namespace file_manager
55