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