Test for golden version-7 safe-browsing file.
[chromium-blink-merge.git] / chrome / common / chrome_paths_linux.cc
blobeeb1b9ac635e39cae14fc272f2b4cc1e7d70d416
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"
13 namespace chrome {
15 using base::nix::GetXDGDirectory;
16 using base::nix::GetXDGUserDirectory;
17 using base::nix::kDotConfigDir;
18 using base::nix::kXdgConfigHomeEnvVar;
20 namespace {
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,
30 base::FilePath* result) {
31 #if defined(OS_CHROMEOS)
32 // No local media directories on CrOS.
33 return false;
34 #else
35 *result = GetXDGUserDirectory(xdg_name.c_str(), fallback_name.c_str());
37 base::FilePath home = base::GetHomeDir();
38 if (*result != home) {
39 base::FilePath desktop;
40 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop))
41 return false;
42 if (*result != desktop) {
43 return true;
47 *result = home.Append(fallback_name);
48 return true;
49 #endif
52 } // namespace
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(base::FilePath* result) {
60 scoped_ptr<base::Environment> env(base::Environment::Create());
61 base::FilePath config_dir(GetXDGDirectory(env.get(),
62 kXdgConfigHomeEnvVar,
63 kDotConfigDir));
64 #if defined(GOOGLE_CHROME_BUILD)
65 *result = config_dir.Append("google-chrome");
66 #else
67 *result = config_dir.Append("chromium");
68 #endif
69 return true;
72 void GetUserCacheDirectory(const base::FilePath& profile_dir,
73 base::FilePath* result) {
74 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
75 // for a spec on where cache files go. Our rule is:
76 // - if the user-data-dir in the standard place,
77 // use same subdirectory of the cache directory.
78 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well
79 // as the same thing for ~/.config/chromium)
80 // - otherwise, use the profile dir directly.
82 // Default value in cases where any of the following fails.
83 *result = profile_dir;
85 scoped_ptr<base::Environment> env(base::Environment::Create());
87 base::FilePath cache_dir;
88 if (!PathService::Get(base::DIR_CACHE, &cache_dir))
89 return;
90 base::FilePath config_dir(GetXDGDirectory(env.get(),
91 kXdgConfigHomeEnvVar,
92 kDotConfigDir));
94 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir))
95 return;
97 *result = cache_dir;
100 bool GetUserDocumentsDirectory(base::FilePath* result) {
101 *result = GetXDGUserDirectory("DOCUMENTS", "Documents");
102 return true;
105 bool GetUserDownloadsDirectorySafe(base::FilePath* result) {
106 base::FilePath home = base::GetHomeDir();
107 *result = home.Append(kDownloadsDir);
108 return true;
111 bool GetUserDownloadsDirectory(base::FilePath* result) {
112 *result = GetXDGUserDirectory("DOWNLOAD", kDownloadsDir);
113 return true;
116 // We respect the user's preferred pictures location, unless it is
117 // ~ or their desktop directory, in which case we default to ~/Music.
118 bool GetUserMusicDirectory(base::FilePath* result) {
119 return GetUserMediaDirectory("MUSIC", kMusicDir, result);
122 // We respect the user's preferred pictures location, unless it is
123 // ~ or their desktop directory, in which case we default to ~/Pictures.
124 bool GetUserPicturesDirectory(base::FilePath* result) {
125 return GetUserMediaDirectory("PICTURES", kPicturesDir, result);
128 // We respect the user's preferred pictures location, unless it is
129 // ~ or their desktop directory, in which case we default to ~/Videos.
130 bool GetUserVideosDirectory(base::FilePath* result) {
131 return GetUserMediaDirectory("VIDEOS", kVideosDir, result);
134 bool ProcessNeedsProfileDir(const std::string& process_type) {
135 // For now we have no reason to forbid this on Linux as we don't
136 // have the roaming profile troubles there. Moreover the Linux breakpad needs
137 // profile dir access in all process if enabled on Linux.
138 return true;
141 } // namespace chrome