summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/file_manager/path_util.cc
blob: 2ca8d44ccbdacabc73b3bae9c3f55cf6e768397f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 "chrome/browser/chromeos/drive/file_system_util.h"

namespace file_manager {
namespace util {

const char kDownloadsFolderName[] = "Downloads";
const base::FilePath::CharType kOldDownloadsFolderPath[] =
    FILE_PATH_LITERAL("/home/chronos/user/Downloads");

base::FilePath GetDownloadsFolderForProfile(Profile* profile) {
  // TODO(kinaba) crbug/309556: "Downloads" directory should be per-profile.
  //
  // For this to be per-profile, a unique directory path from profile->GetPath()
  // should be used rather than the HOME directory. We'll switch to the new path
  // once we have upgraded all code locations assuming the old path.
  base::FilePath path;
  CHECK(PathService::Get(base::DIR_HOME, &path));
  return path.AppendASCII(kDownloadsFolderName);
}

bool MigratePathFromOldFormat(Profile* profile,
                              const base::FilePath& old_path,
                              base::FilePath* new_path) {
  // /special/drive/xxx => /special/drive/root/xxx
  if (drive::util::NeedsNamespaceMigration(old_path)) {
    *new_path = drive::util::ConvertToMyDriveNamespace(old_path);
    return true;
  }

  // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx
  const base::FilePath old_base(kOldDownloadsFolderPath);
  base::FilePath relative;
  if (old_path == old_base ||
      old_base.AppendRelativePath(old_path, &relative)) {
    const base::FilePath new_base = GetDownloadsFolderForProfile(profile);
    *new_path = new_base.Append(relative);
    return old_path != *new_path;
  }

  return false;
}


}  // namespace util
}  // namespace file_manager