Fix a leak in wm::AnimateOnChildWindowVisibilityChanged().
[chromium-blink-merge.git] / chrome / common / chrome_paths_linux.cc
blob95dd08697187ec06a4225e28701b9fabc8f5b271
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/base_paths.h"
8 #include "base/environment.h"
9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/nix/xdg_util.h"
12 #include "base/path_service.h"
13 #include "chrome/common/chrome_paths.h"
15 namespace chrome {
17 using base::nix::GetXDGDirectory;
18 using base::nix::GetXDGUserDirectory;
19 using base::nix::kDotConfigDir;
20 using base::nix::kXdgConfigHomeEnvVar;
22 namespace {
24 const char kDownloadsDir[] = "Downloads";
25 const char kMusicDir[] = "Music";
26 const char kPicturesDir[] = "Pictures";
27 const char kVideosDir[] = "Videos";
29 // Generic function for GetUser{Music,Pictures,Video}Directory.
30 bool GetUserMediaDirectory(const std::string& xdg_name,
31 const std::string& fallback_name,
32 base::FilePath* result) {
33 #if defined(OS_CHROMEOS)
34 // No local media directories on CrOS.
35 return false;
36 #else
37 *result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str());
39 base::FilePath home;
40 PathService::Get(base::DIR_HOME, &home);
41 if (*result != home) {
42 base::FilePath desktop;
43 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop))
44 return false;
45 if (*result != desktop) {
46 return true;
50 *result = home.Append(fallback_name);
51 return true;
52 #endif
55 } // namespace
57 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
58 // for a spec on where config files go. The net effect for most
59 // systems is we use ~/.config/chromium/ for Chromium and
60 // ~/.config/google-chrome/ for official builds.
61 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .)
62 bool GetDefaultUserDataDirectory(base::FilePath* result) {
63 scoped_ptr<base::Environment> env(base::Environment::Create());
64 base::FilePath config_dir(GetXDGDirectory(env.get(),
65 kXdgConfigHomeEnvVar,
66 kDotConfigDir));
67 #if defined(GOOGLE_CHROME_BUILD)
68 *result = config_dir.Append("google-chrome");
69 #else
70 *result = config_dir.Append("chromium");
71 #endif
72 return true;
75 void GetUserCacheDirectory(const base::FilePath& profile_dir,
76 base::FilePath* result) {
77 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
78 // for a spec on where cache files go. Our rule is:
79 // - if the user-data-dir in the standard place,
80 // use same subdirectory of the cache directory.
81 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well
82 // as the same thing for ~/.config/chromium)
83 // - otherwise, use the profile dir directly.
85 // Default value in cases where any of the following fails.
86 *result = profile_dir;
88 scoped_ptr<base::Environment> env(base::Environment::Create());
90 base::FilePath cache_dir;
91 if (!PathService::Get(base::DIR_CACHE, &cache_dir))
92 return;
93 base::FilePath config_dir(GetXDGDirectory(env.get(),
94 kXdgConfigHomeEnvVar,
95 kDotConfigDir));
97 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir))
98 return;
100 *result = cache_dir;
103 bool GetUserDocumentsDirectory(base::FilePath* result) {
104 *result = GetXDGUserDirectory("DOCUMENTS", "Documents");
105 return true;
108 bool GetUserDownloadsDirectorySafe(base::FilePath* result) {
109 base::FilePath home;
110 PathService::Get(base::DIR_HOME, &home);
111 *result = home.Append(kDownloadsDir);
112 return true;
115 bool GetUserDownloadsDirectory(base::FilePath* result) {
116 *result = GetXDGUserDirectory("DOWNLOAD", kDownloadsDir);
117 return true;
120 // We respect the user's preferred pictures location, unless it is
121 // ~ or their desktop directory, in which case we default to ~/Music.
122 bool GetUserMusicDirectory(base::FilePath* result) {
123 return GetUserMediaDirectory("MUSIC", kMusicDir, result);
126 // We respect the user's preferred pictures location, unless it is
127 // ~ or their desktop directory, in which case we default to ~/Pictures.
128 bool GetUserPicturesDirectory(base::FilePath* result) {
129 return GetUserMediaDirectory("PICTURES", kPicturesDir, result);
132 // We respect the user's preferred pictures location, unless it is
133 // ~ or their desktop directory, in which case we default to ~/Videos.
134 bool GetUserVideosDirectory(base::FilePath* result) {
135 return GetUserMediaDirectory("VIDEOS", kVideosDir, result);
138 bool ProcessNeedsProfileDir(const std::string& process_type) {
139 // For now we have no reason to forbid this on Linux as we don't
140 // have the roaming profile troubles there. Moreover the Linux breakpad needs
141 // profile dir access in all process if enabled on Linux.
142 return true;
145 } // namespace chrome