| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/file_manager/path_util.h" | 5 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 12 #include "chrome/browser/download/download_prefs.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 | 14 |
| 14 namespace file_manager { | 15 namespace file_manager { |
| 15 namespace util { | 16 namespace util { |
| 16 | 17 |
| 17 const char kDownloadsFolderName[] = "Downloads"; | 18 const char kDownloadsFolderName[] = "Downloads"; |
| 18 const base::FilePath::CharType kOldDownloadsFolderPath[] = | 19 const base::FilePath::CharType kOldDownloadsFolderPath[] = |
| 19 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); | 20 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); |
| 20 | 21 |
| 21 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { | 22 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 bool MigratePathFromOldFormat(Profile* profile, | 34 bool MigratePathFromOldFormat(Profile* profile, |
| 34 const base::FilePath& old_path, | 35 const base::FilePath& old_path, |
| 35 base::FilePath* new_path) { | 36 base::FilePath* new_path) { |
| 36 // /special/drive/xxx => /special/drive/root/xxx | 37 // /special/drive/xxx => /special/drive/root/xxx |
| 37 if (drive::util::NeedsNamespaceMigration(old_path)) { | 38 if (drive::util::NeedsNamespaceMigration(old_path)) { |
| 38 *new_path = drive::util::ConvertToMyDriveNamespace(old_path); | 39 *new_path = drive::util::ConvertToMyDriveNamespace(old_path); |
| 39 return true; | 40 return true; |
| 40 } | 41 } |
| 41 | 42 |
| 42 // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx | 43 // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx |
| 43 const base::FilePath old_base(kOldDownloadsFolderPath); | 44 // |
| 44 base::FilePath relative; | 45 // Old path format comes either from stored old settings or from the initial |
| 45 if (old_path == old_base || | 46 // default value set in DownloadPrefs::RegisterProfilePrefs in profile-unaware |
| 46 old_base.AppendRelativePath(old_path, &relative)) { | 47 // code location. In the former case it is "/home/chronos/user/Downloads", |
| 47 const base::FilePath new_base = GetDownloadsFolderForProfile(profile); | 48 // and in the latter case it is DownloadPrefs::GetDefaultDownloadDirectory(). |
| 48 *new_path = new_base.Append(relative); | 49 // Those two paths coincides as long as $HOME=/home/chronos/user, but the |
| 49 return old_path != *new_path; | 50 // environment variable is phasing out (crbug.com/333031) so we care both. |
| 51 const base::FilePath old_bases[] = { |
| 52 base::FilePath(kOldDownloadsFolderPath), |
| 53 DownloadPrefs::GetDefaultDownloadDirectory(), |
| 54 }; |
| 55 for (size_t i = 0; i < arraysize(old_bases); ++i) { |
| 56 const base::FilePath& old_base = old_bases[i]; |
| 57 base::FilePath relative; |
| 58 if (old_path == old_base || |
| 59 old_base.AppendRelativePath(old_path, &relative)) { |
| 60 const base::FilePath new_base = GetDownloadsFolderForProfile(profile); |
| 61 *new_path = new_base.Append(relative); |
| 62 return old_path != *new_path; |
| 63 } |
| 50 } | 64 } |
| 51 | 65 |
| 52 return false; | 66 return false; |
| 53 } | 67 } |
| 54 | 68 |
| 55 | |
| 56 } // namespace util | 69 } // namespace util |
| 57 } // namespace file_manager | 70 } // namespace file_manager |
| OLD | NEW |