Chromium Code Reviews| 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 kDotConfig[] = ".config"; | |
|
viettrungluu
2011/02/16 16:34:25
These already have internal linkage, so the anonym
Lei Zhang
2011/02/17 03:19:46
Done.
| |
| 16 const char kDownloads[] = "Downloads"; | |
| 17 const char kXdgConfigHome[] = "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( |
| 23 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); | 31 base::nix::GetXDGDirectory(env.get(), kXdgConfigHome, kDotConfig)); |
| 24 #if defined(GOOGLE_CHROME_BUILD) | 32 #if defined(GOOGLE_CHROME_BUILD) |
| 25 *result = config_dir.Append("google-chrome"); | 33 *result = config_dir.Append("google-chrome"); |
| 26 #else | 34 #else |
| 27 *result = config_dir.Append("chromium"); | 35 *result = config_dir.Append("chromium"); |
| 28 #endif | 36 #endif |
| 29 return true; | 37 return true; |
| 30 } | 38 } |
| 31 | 39 |
| 32 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { | 40 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { |
| 33 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 41 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 34 // for a spec on where cache files go. Our rule is: | 42 // for a spec on where cache files go. Our rule is: |
| 35 // - if the user-data-dir in the standard place, | 43 // - if the user-data-dir in the standard place, |
| 36 // use same subdirectory of the cache directory. | 44 // use same subdirectory of the cache directory. |
| 37 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well | 45 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well |
| 38 // as the same thing for ~/.config/chromium) | 46 // as the same thing for ~/.config/chromium) |
| 39 // - otherwise, use the profile dir directly. | 47 // - otherwise, use the profile dir directly. |
| 40 | 48 |
| 41 // Default value in cases where any of the following fails. | 49 // Default value in cases where any of the following fails. |
| 42 *result = profile_dir; | 50 *result = profile_dir; |
| 43 | 51 |
| 44 scoped_ptr<base::Environment> env(base::Environment::Create()); | 52 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 45 | 53 |
| 46 FilePath cache_dir; | 54 FilePath cache_dir; |
| 47 if (!PathService::Get(base::DIR_CACHE, &cache_dir)) | 55 if (!PathService::Get(base::DIR_CACHE, &cache_dir)) |
| 48 return; | 56 return; |
| 49 FilePath config_dir( | 57 FilePath config_dir( |
| 50 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); | 58 base::nix::GetXDGDirectory(env.get(), kXdgConfigHome, kDotConfig)); |
| 51 | 59 |
| 52 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir)) | 60 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir)) |
| 53 return; | 61 return; |
| 54 | 62 |
| 55 *result = cache_dir; | 63 *result = cache_dir; |
| 56 } | 64 } |
| 57 | 65 |
| 58 bool GetChromeFrameUserDataDirectory(FilePath* result) { | 66 bool GetChromeFrameUserDataDirectory(FilePath* result) { |
| 59 scoped_ptr<base::Environment> env(base::Environment::Create()); | 67 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 60 FilePath config_dir( | 68 FilePath config_dir( |
| 61 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); | 69 base::nix::GetXDGDirectory(env.get(), kXdgConfigHome, kDotConfig)); |
| 62 #if defined(GOOGLE_CHROME_BUILD) | 70 #if defined(GOOGLE_CHROME_BUILD) |
| 63 *result = config_dir.Append("google-chrome-frame"); | 71 *result = config_dir.Append("google-chrome-frame"); |
| 64 #else | 72 #else |
| 65 *result = config_dir.Append("chrome-frame"); | 73 *result = config_dir.Append("chrome-frame"); |
| 66 #endif | 74 #endif |
| 67 return true; | 75 return true; |
| 68 } | 76 } |
| 69 | 77 |
| 70 bool GetUserDocumentsDirectory(FilePath* result) { | 78 bool GetUserDocumentsDirectory(FilePath* result) { |
| 71 scoped_ptr<base::Environment> env(base::Environment::Create()); | 79 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 72 *result = base::nix::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents"); | 80 *result = base::nix::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents"); |
| 73 return true; | 81 return true; |
| 74 } | 82 } |
| 75 | 83 |
| 76 // We respect the user's preferred download location, unless it is | 84 // We respect the user's preferred download location, unless it is |
| 77 // ~ or their desktop directory, in which case we default to ~/Downloads. | 85 // ~ or their desktop directory, in which case we default to ~/Downloads. |
| 78 bool GetUserDownloadsDirectory(FilePath* result) { | 86 bool GetUserDownloadsDirectory(FilePath* result) { |
| 79 scoped_ptr<base::Environment> env(base::Environment::Create()); | 87 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 80 *result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD", "Downloads"); | 88 *result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD", kDownloads); |
| 81 | 89 |
| 82 FilePath home = file_util::GetHomeDir(); | 90 FilePath home = file_util::GetHomeDir(); |
| 83 if (*result == home) { | 91 if (*result == home) { |
| 84 *result = home.Append("Downloads"); | 92 *result = home.Append(kDownloads); |
| 85 return true; | 93 return true; |
| 86 } | 94 } |
| 87 | 95 |
| 88 FilePath desktop; | 96 FilePath desktop; |
| 89 GetUserDesktop(&desktop); | 97 GetUserDesktop(&desktop); |
| 90 if (*result == desktop) { | 98 if (*result == desktop) { |
| 91 *result = home.Append("Downloads"); | 99 *result = home.Append(kDownloads); |
| 92 } | 100 } |
| 93 | 101 |
| 94 return true; | 102 return true; |
| 95 } | 103 } |
| 96 | 104 |
| 97 bool GetUserDesktop(FilePath* result) { | 105 bool GetUserDesktop(FilePath* result) { |
| 98 scoped_ptr<base::Environment> env(base::Environment::Create()); | 106 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 99 *result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); | 107 *result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); |
| 100 return true; | 108 return true; |
| 101 } | 109 } |
| 102 | 110 |
| 103 } // namespace chrome | 111 } // namespace chrome |
| OLD | NEW |