| 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" | |
| 10 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 12 #include "chrome/browser/chromeos/login/users/user.h" | 11 #include "chrome/browser/chromeos/login/users/user.h" |
| 13 #include "chrome/browser/chromeos/login/users/user_manager.h" | 12 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 15 #include "chrome/browser/download/download_prefs.h" | 14 #include "chrome/browser/download/download_prefs.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 18 | 17 |
| 19 namespace file_manager { | 18 namespace file_manager { |
| 20 namespace util { | 19 namespace util { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 const char kDownloadsFolderName[] = "Downloads"; | 23 const char kDownloadsFolderName[] = "Downloads"; |
| 25 const base::FilePath::CharType kOldDownloadsFolderPath[] = | 24 const base::FilePath::CharType kOldDownloadsFolderPath[] = |
| 26 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); | 25 FILE_PATH_LITERAL("/home/chronos/user/Downloads"); |
| 27 const base::FilePath::CharType kOldDriveFolderPath[] = | 26 const base::FilePath::CharType kOldDriveFolderPath[] = |
| 28 FILE_PATH_LITERAL("/special/drive"); | 27 FILE_PATH_LITERAL("/special/drive"); |
| 29 // Unintended path introduced in crbug.com/363026. | 28 // Unintended path introduced in crbug.com/363026. |
| 30 const base::FilePath::CharType kBuggyDriveFolderPath[] = | 29 const base::FilePath::CharType kBuggyDriveFolderPath[] = |
| 31 FILE_PATH_LITERAL("/special/drive-user"); | 30 FILE_PATH_LITERAL("/special/drive-user"); |
| 32 | 31 |
| 33 } // namespace | 32 } // namespace |
| 34 | 33 |
| 35 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { | 34 base::FilePath GetDownloadsFolderForProfile(Profile* profile) { |
| 36 if (!base::SysInfo::IsRunningOnChromeOS()) { | 35 // On non-ChromeOS system (test+development), the primary profile uses |
| 37 // On the developer run on Linux desktop build, use $HOME/Downloads for ease | 36 // $HOME/Downloads for ease for accessing local files for debugging. |
| 38 // for accessing local files for debugging. | 37 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 39 base::FilePath path; | 38 chromeos::UserManager::IsInitialized()) { |
| 40 CHECK(PathService::Get(base::DIR_HOME, &path)); | 39 const chromeos::User* const user = |
| 41 return path.AppendASCII(kDownloadsFolderName); | 40 chromeos::UserManager::Get()->GetUserByProfile( |
| 41 profile->GetOriginalProfile()); |
| 42 const chromeos::User* const primary_user = |
| 43 chromeos::UserManager::Get()->GetPrimaryUser(); |
| 44 if (user == primary_user) |
| 45 return DownloadPrefs::GetDefaultDownloadDirectory(); |
| 42 } | 46 } |
| 43 return profile->GetPath().AppendASCII(kDownloadsFolderName); | 47 return profile->GetPath().AppendASCII(kDownloadsFolderName); |
| 44 } | 48 } |
| 45 | 49 |
| 46 bool MigratePathFromOldFormat(Profile* profile, | 50 bool MigratePathFromOldFormat(Profile* profile, |
| 47 const base::FilePath& old_path, | 51 const base::FilePath& old_path, |
| 48 base::FilePath* new_path) { | 52 base::FilePath* new_path) { |
| 49 // M34: | 53 // M34: |
| 50 // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx | 54 // /home/chronos/user/Downloads/xxx => /home/chronos/u-hash/Downloads/xxx |
| 51 // /special/drive => /special/drive-xxx | 55 // /special/drive => /special/drive-xxx |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 chromeos::User* const user = | 109 chromeos::User* const user = |
| 106 chromeos::UserManager::IsInitialized() ? | 110 chromeos::UserManager::IsInitialized() ? |
| 107 chromeos::UserManager::Get()->GetUserByProfile( | 111 chromeos::UserManager::Get()->GetUserByProfile( |
| 108 profile->GetOriginalProfile()) : NULL; | 112 profile->GetOriginalProfile()) : NULL; |
| 109 const std::string id = user ? "-" + user->username_hash() : ""; | 113 const std::string id = user ? "-" + user->username_hash() : ""; |
| 110 return net::EscapePath(kDownloadsFolderName + id); | 114 return net::EscapePath(kDownloadsFolderName + id); |
| 111 } | 115 } |
| 112 | 116 |
| 113 } // namespace util | 117 } // namespace util |
| 114 } // namespace file_manager | 118 } // namespace file_manager |
| OLD | NEW |