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
3 // found in the LICENSE file.
5 #include "chrome/common/chrome_paths_internal.h"
7 #include "base/environment.h"
8 #include "base/file_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/nix/xdg_util.h"
11 #include "base/path_service.h"
15 using base::nix::GetXDGDirectory
;
16 using base::nix::GetXDGUserDirectory
;
17 using base::nix::kDotConfigDir
;
18 using base::nix::kXdgConfigHomeEnvVar
;
22 const char kDownloadsDir
[] = "Downloads";
23 const char kMusicDir
[] = "Music";
24 const char kPicturesDir
[] = "Pictures";
25 const char kVideosDir
[] = "Videos";
27 // Generic function for GetUser{Music,Pictures,Video}Directory.
28 bool GetUserMediaDirectory(const std::string
& xdg_name
,
29 const std::string
& fallback_name
,
31 #if defined(OS_CHROMEOS)
32 // No local media directories on CrOS.
35 *result
= GetXDGUserDirectory(xdg_name
.c_str(), fallback_name
.c_str());
37 FilePath home
= file_util::GetHomeDir();
38 if (*result
!= home
) {
40 if (!PathService::Get(base::DIR_USER_DESKTOP
, &desktop
))
42 if (*result
!= desktop
) {
47 *result
= home
.Append(fallback_name
);
54 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
55 // for a spec on where config files go. The net effect for most
56 // systems is we use ~/.config/chromium/ for Chromium and
57 // ~/.config/google-chrome/ for official builds.
58 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .)
59 bool GetDefaultUserDataDirectory(FilePath
* result
) {
60 scoped_ptr
<base::Environment
> env(base::Environment::Create());
61 FilePath
config_dir(GetXDGDirectory(env
.get(),
64 #if defined(GOOGLE_CHROME_BUILD)
65 *result
= config_dir
.Append("google-chrome");
67 *result
= config_dir
.Append("chromium");
72 void GetUserCacheDirectory(const FilePath
& profile_dir
, FilePath
* result
) {
73 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
74 // for a spec on where cache files go. Our rule is:
75 // - if the user-data-dir in the standard place,
76 // use same subdirectory of the cache directory.
77 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well
78 // as the same thing for ~/.config/chromium)
79 // - otherwise, use the profile dir directly.
81 // Default value in cases where any of the following fails.
82 *result
= profile_dir
;
84 scoped_ptr
<base::Environment
> env(base::Environment::Create());
87 if (!PathService::Get(base::DIR_CACHE
, &cache_dir
))
89 FilePath
config_dir(GetXDGDirectory(env
.get(),
93 if (!config_dir
.AppendRelativePath(profile_dir
, &cache_dir
))
99 bool GetChromeFrameUserDataDirectory(FilePath
* result
) {
100 scoped_ptr
<base::Environment
> env(base::Environment::Create());
101 FilePath
config_dir(GetXDGDirectory(env
.get(),
102 kXdgConfigHomeEnvVar
,
104 #if defined(GOOGLE_CHROME_BUILD)
105 *result
= config_dir
.Append("google-chrome-frame");
107 *result
= config_dir
.Append("chrome-frame");
112 bool GetUserDocumentsDirectory(FilePath
* result
) {
113 *result
= GetXDGUserDirectory("DOCUMENTS", "Documents");
117 bool GetUserDownloadsDirectorySafe(FilePath
* result
) {
118 FilePath home
= file_util::GetHomeDir();
119 *result
= home
.Append(kDownloadsDir
);
123 bool GetUserDownloadsDirectory(FilePath
* result
) {
124 *result
= base::nix::GetXDGUserDirectory("DOWNLOAD", kDownloadsDir
);
128 // We respect the user's preferred pictures location, unless it is
129 // ~ or their desktop directory, in which case we default to ~/Music.
130 bool GetUserMusicDirectory(FilePath
* result
) {
131 return GetUserMediaDirectory("MUSIC", kMusicDir
, result
);
134 // We respect the user's preferred pictures location, unless it is
135 // ~ or their desktop directory, in which case we default to ~/Pictures.
136 bool GetUserPicturesDirectory(FilePath
* result
) {
137 return GetUserMediaDirectory("PICTURES", kPicturesDir
, result
);
140 // We respect the user's preferred pictures location, unless it is
141 // ~ or their desktop directory, in which case we default to ~/Videos.
142 bool GetUserVideosDirectory(FilePath
* result
) {
143 return GetUserMediaDirectory("VIDEOS", kVideosDir
, result
);
146 bool ProcessNeedsProfileDir(const std::string
& process_type
) {
147 // For now we have no reason to forbid this on Linux as we don't
148 // have the roaming profile troubles there. Moreover the Linux breakpad needs
149 // profile dir access in all process if enabled on Linux.
153 } // namespace chrome