| 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/environment.h" | 7 #include "base/environment.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const char kDotConfigDir[] = ".config"; | |
| 16 const char kDownloadsDir[] = "Downloads"; | 15 const char kDownloadsDir[] = "Downloads"; |
| 17 const char kPicturesDir[] = "Pictures"; | 16 const char kPicturesDir[] = "Pictures"; |
| 18 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME"; | |
| 19 | 17 |
| 20 } // namespace | 18 } // namespace |
| 21 | 19 |
| 22 namespace chrome { | 20 namespace chrome { |
| 23 | 21 |
| 22 using base::nix::GetXDGDirectory; |
| 23 using base::nix::GetXDGUserDirectory; |
| 24 using base::nix::kDotConfigDir; |
| 25 using base::nix::kXdgConfigHomeEnvVar; |
| 26 |
| 24 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 27 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 25 // for a spec on where config files go. The net effect for most | 28 // for a spec on where config files go. The net effect for most |
| 26 // systems is we use ~/.config/chromium/ for Chromium and | 29 // systems is we use ~/.config/chromium/ for Chromium and |
| 27 // ~/.config/google-chrome/ for official builds. | 30 // ~/.config/google-chrome/ for official builds. |
| 28 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .) | 31 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .) |
| 29 bool GetDefaultUserDataDirectory(FilePath* result) { | 32 bool GetDefaultUserDataDirectory(FilePath* result) { |
| 30 scoped_ptr<base::Environment> env(base::Environment::Create()); | 33 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 31 FilePath config_dir(base::nix::GetXDGDirectory(env.get(), | 34 FilePath config_dir(GetXDGDirectory(env.get(), |
| 32 kXdgConfigHomeEnvVar, | 35 kXdgConfigHomeEnvVar, |
| 33 kDotConfigDir)); | 36 kDotConfigDir)); |
| 34 #if defined(GOOGLE_CHROME_BUILD) | 37 #if defined(GOOGLE_CHROME_BUILD) |
| 35 *result = config_dir.Append("google-chrome"); | 38 *result = config_dir.Append("google-chrome"); |
| 36 #else | 39 #else |
| 37 *result = config_dir.Append("chromium"); | 40 *result = config_dir.Append("chromium"); |
| 38 #endif | 41 #endif |
| 39 return true; | 42 return true; |
| 40 } | 43 } |
| 41 | 44 |
| 42 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { | 45 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { |
| 43 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 46 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 44 // for a spec on where cache files go. Our rule is: | 47 // for a spec on where cache files go. Our rule is: |
| 45 // - if the user-data-dir in the standard place, | 48 // - if the user-data-dir in the standard place, |
| 46 // use same subdirectory of the cache directory. | 49 // use same subdirectory of the cache directory. |
| 47 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well | 50 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well |
| 48 // as the same thing for ~/.config/chromium) | 51 // as the same thing for ~/.config/chromium) |
| 49 // - otherwise, use the profile dir directly. | 52 // - otherwise, use the profile dir directly. |
| 50 | 53 |
| 51 // Default value in cases where any of the following fails. | 54 // Default value in cases where any of the following fails. |
| 52 *result = profile_dir; | 55 *result = profile_dir; |
| 53 | 56 |
| 54 scoped_ptr<base::Environment> env(base::Environment::Create()); | 57 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 55 | 58 |
| 56 FilePath cache_dir; | 59 FilePath cache_dir; |
| 57 if (!PathService::Get(base::DIR_CACHE, &cache_dir)) | 60 if (!PathService::Get(base::DIR_CACHE, &cache_dir)) |
| 58 return; | 61 return; |
| 59 FilePath config_dir(base::nix::GetXDGDirectory(env.get(), | 62 FilePath config_dir(GetXDGDirectory(env.get(), |
| 60 kXdgConfigHomeEnvVar, | 63 kXdgConfigHomeEnvVar, |
| 61 kDotConfigDir)); | 64 kDotConfigDir)); |
| 62 | 65 |
| 63 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir)) | 66 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir)) |
| 64 return; | 67 return; |
| 65 | 68 |
| 66 *result = cache_dir; | 69 *result = cache_dir; |
| 67 } | 70 } |
| 68 | 71 |
| 69 bool GetChromeFrameUserDataDirectory(FilePath* result) { | 72 bool GetChromeFrameUserDataDirectory(FilePath* result) { |
| 70 scoped_ptr<base::Environment> env(base::Environment::Create()); | 73 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 71 FilePath config_dir(base::nix::GetXDGDirectory(env.get(), | 74 FilePath config_dir(GetXDGDirectory(env.get(), |
| 72 kXdgConfigHomeEnvVar, | 75 kXdgConfigHomeEnvVar, |
| 73 kDotConfigDir)); | 76 kDotConfigDir)); |
| 74 #if defined(GOOGLE_CHROME_BUILD) | 77 #if defined(GOOGLE_CHROME_BUILD) |
| 75 *result = config_dir.Append("google-chrome-frame"); | 78 *result = config_dir.Append("google-chrome-frame"); |
| 76 #else | 79 #else |
| 77 *result = config_dir.Append("chrome-frame"); | 80 *result = config_dir.Append("chrome-frame"); |
| 78 #endif | 81 #endif |
| 79 return true; | 82 return true; |
| 80 } | 83 } |
| 81 | 84 |
| 82 bool GetUserDocumentsDirectory(FilePath* result) { | 85 bool GetUserDocumentsDirectory(FilePath* result) { |
| 83 *result = base::nix::GetXDGUserDirectory("DOCUMENTS", "Documents"); | 86 *result = GetXDGUserDirectory("DOCUMENTS", "Documents"); |
| 84 return true; | 87 return true; |
| 85 } | 88 } |
| 86 | 89 |
| 87 bool GetUserDownloadsDirectorySafe(FilePath* result) { | 90 bool GetUserDownloadsDirectorySafe(FilePath* result) { |
| 88 FilePath home = file_util::GetHomeDir(); | 91 FilePath home = file_util::GetHomeDir(); |
| 89 *result = home.Append(kDownloadsDir); | 92 *result = home.Append(kDownloadsDir); |
| 90 return true; | 93 return true; |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool GetUserDownloadsDirectory(FilePath* result) { | 96 bool GetUserDownloadsDirectory(FilePath* result) { |
| 94 *result = base::nix::GetXDGUserDirectory("DOWNLOAD", kDownloadsDir); | 97 *result = base::nix::GetXDGUserDirectory("DOWNLOAD", kDownloadsDir); |
| 95 return true; | 98 return true; |
| 96 } | 99 } |
| 97 | 100 |
| 98 // We respect the user's preferred pictures location, unless it is | 101 // We respect the user's preferred pictures location, unless it is |
| 99 // ~ or their desktop directory, in which case we default to ~/Pictures. | 102 // ~ or their desktop directory, in which case we default to ~/Pictures. |
| 100 bool GetUserPicturesDirectory(FilePath* result) { | 103 bool GetUserPicturesDirectory(FilePath* result) { |
| 101 *result = base::nix::GetXDGUserDirectory("PICTURES", kPicturesDir); | 104 *result = GetXDGUserDirectory("PICTURES", kPicturesDir); |
| 102 | 105 |
| 103 FilePath home = file_util::GetHomeDir(); | 106 FilePath home = file_util::GetHomeDir(); |
| 104 if (*result != home) { | 107 if (*result != home) { |
| 105 FilePath desktop; | 108 FilePath desktop; |
| 106 GetUserDesktop(&desktop); | 109 GetUserDesktop(&desktop); |
| 107 if (*result != desktop) { | 110 if (*result != desktop) { |
| 108 return true; | 111 return true; |
| 109 } | 112 } |
| 110 } | 113 } |
| 111 | 114 |
| 112 *result = home.Append(kPicturesDir); | 115 *result = home.Append(kPicturesDir); |
| 113 return true; | 116 return true; |
| 114 } | 117 } |
| 115 | 118 |
| 116 bool GetUserDesktop(FilePath* result) { | 119 bool GetUserDesktop(FilePath* result) { |
| 117 *result = base::nix::GetXDGUserDirectory("DESKTOP", "Desktop"); | 120 *result = GetXDGUserDirectory("DESKTOP", "Desktop"); |
| 118 return true; | 121 return true; |
| 119 } | 122 } |
| 120 | 123 |
| 121 bool ProcessNeedsProfileDir(const std::string& process_type) { | 124 bool ProcessNeedsProfileDir(const std::string& process_type) { |
| 122 // For now we have no reason to forbid this on Linux as we don't | 125 // For now we have no reason to forbid this on Linux as we don't |
| 123 // have the roaming profile troubles there. Moreover the Linux breakpad needs | 126 // have the roaming profile troubles there. Moreover the Linux breakpad needs |
| 124 // profile dir access in all process if enabled on Linux. | 127 // profile dir access in all process if enabled on Linux. |
| 125 return true; | 128 return true; |
| 126 } | 129 } |
| 127 | 130 |
| 128 } // namespace chrome | 131 } // namespace chrome |
| OLD | NEW |