| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/chrome_paths_internal.h" | 5 #include "chrome/common/chrome_paths_internal.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" |
| 7 #include "base/environment.h" | 8 #include "base/environment.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/nix/xdg_util.h" | 11 #include "base/nix/xdg_util.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "chrome/common/chrome_paths.h" |
| 12 | 14 |
| 13 namespace chrome { | 15 namespace chrome { |
| 14 | 16 |
| 15 using base::nix::GetXDGDirectory; | 17 using base::nix::GetXDGDirectory; |
| 16 using base::nix::GetXDGUserDirectory; | 18 using base::nix::GetXDGUserDirectory; |
| 17 using base::nix::kDotConfigDir; | 19 using base::nix::kDotConfigDir; |
| 18 using base::nix::kXdgConfigHomeEnvVar; | 20 using base::nix::kXdgConfigHomeEnvVar; |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 const char kDownloadsDir[] = "Downloads"; | 24 const char kDownloadsDir[] = "Downloads"; |
| 23 const char kMusicDir[] = "Music"; | 25 const char kMusicDir[] = "Music"; |
| 24 const char kPicturesDir[] = "Pictures"; | 26 const char kPicturesDir[] = "Pictures"; |
| 25 const char kVideosDir[] = "Videos"; | 27 const char kVideosDir[] = "Videos"; |
| 26 | 28 |
| 27 // Generic function for GetUser{Music,Pictures,Video}Directory. | 29 // Generic function for GetUser{Music,Pictures,Video}Directory. |
| 28 bool GetUserMediaDirectory(const std::string& xdg_name, | 30 bool GetUserMediaDirectory(const std::string& xdg_name, |
| 29 const std::string& fallback_name, | 31 const std::string& fallback_name, |
| 30 base::FilePath* result) { | 32 base::FilePath* result) { |
| 31 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 32 // No local media directories on CrOS. | 34 // No local media directories on CrOS. |
| 33 return false; | 35 return false; |
| 34 #else | 36 #else |
| 35 *result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str()); | 37 *result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str()); |
| 36 | 38 |
| 37 base::FilePath home = base::GetHomeDir(); | 39 base::FilePath home; |
| 40 PathService::Get(base::DIR_HOME, &home); |
| 38 if (*result != home) { | 41 if (*result != home) { |
| 39 base::FilePath desktop; | 42 base::FilePath desktop; |
| 40 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop)) | 43 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop)) |
| 41 return false; | 44 return false; |
| 42 if (*result != desktop) { | 45 if (*result != desktop) { |
| 43 return true; | 46 return true; |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 | 49 |
| 47 *result = home.Append(fallback_name); | 50 *result = home.Append(fallback_name); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 99 |
| 97 *result = cache_dir; | 100 *result = cache_dir; |
| 98 } | 101 } |
| 99 | 102 |
| 100 bool GetUserDocumentsDirectory(base::FilePath* result) { | 103 bool GetUserDocumentsDirectory(base::FilePath* result) { |
| 101 *result = GetXDGUserDirectory("DOCUMENTS", "Documents"); | 104 *result = GetXDGUserDirectory("DOCUMENTS", "Documents"); |
| 102 return true; | 105 return true; |
| 103 } | 106 } |
| 104 | 107 |
| 105 bool GetUserDownloadsDirectorySafe(base::FilePath* result) { | 108 bool GetUserDownloadsDirectorySafe(base::FilePath* result) { |
| 106 base::FilePath home = base::GetHomeDir(); | 109 base::FilePath home; |
| 110 PathService::Get(base::DIR_HOME, &home); |
| 107 *result = home.Append(kDownloadsDir); | 111 *result = home.Append(kDownloadsDir); |
| 108 return true; | 112 return true; |
| 109 } | 113 } |
| 110 | 114 |
| 111 bool GetUserDownloadsDirectory(base::FilePath* result) { | 115 bool GetUserDownloadsDirectory(base::FilePath* result) { |
| 112 *result = GetXDGUserDirectory("DOWNLOAD", kDownloadsDir); | 116 *result = GetXDGUserDirectory("DOWNLOAD", kDownloadsDir); |
| 113 return true; | 117 return true; |
| 114 } | 118 } |
| 115 | 119 |
| 116 // We respect the user's preferred pictures location, unless it is | 120 // We respect the user's preferred pictures location, unless it is |
| (...skipping 15 matching lines...) Expand all Loading... |
| 132 } | 136 } |
| 133 | 137 |
| 134 bool ProcessNeedsProfileDir(const std::string& process_type) { | 138 bool ProcessNeedsProfileDir(const std::string& process_type) { |
| 135 // For now we have no reason to forbid this on Linux as we don't | 139 // For now we have no reason to forbid this on Linux as we don't |
| 136 // have the roaming profile troubles there. Moreover the Linux breakpad needs | 140 // have the roaming profile troubles there. Moreover the Linux breakpad needs |
| 137 // profile dir access in all process if enabled on Linux. | 141 // profile dir access in all process if enabled on Linux. |
| 138 return true; | 142 return true; |
| 139 } | 143 } |
| 140 | 144 |
| 141 } // namespace chrome | 145 } // namespace chrome |
| OLD | NEW |