Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/common/chrome_paths_linux.cc

Issue 5123004: chrome_paths: refactor and sanitize cache directory handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more win Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/chrome_paths_internal.h ('k') | chrome/common/chrome_paths_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
10 #include "base/nix/xdg_util.h" 11 #include "base/nix/xdg_util.h"
11 12
12 namespace chrome { 13 namespace chrome {
13 14
14 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html 15 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
15 // for a spec on where config files go. The net effect for most 16 // for a spec on where config files go. The net effect for most
16 // systems is we use ~/.config/chromium/ for Chromium and 17 // systems is we use ~/.config/chromium/ for Chromium and
17 // ~/.config/google-chrome/ for official builds. 18 // ~/.config/google-chrome/ for official builds.
18 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .) 19 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .)
19 bool GetDefaultUserDataDirectory(FilePath* result) { 20 bool GetDefaultUserDataDirectory(FilePath* result) {
20 scoped_ptr<base::Environment> env(base::Environment::Create()); 21 scoped_ptr<base::Environment> env(base::Environment::Create());
21 FilePath config_dir( 22 FilePath config_dir(
22 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); 23 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
23 #if defined(GOOGLE_CHROME_BUILD) 24 #if defined(GOOGLE_CHROME_BUILD)
24 *result = config_dir.Append("google-chrome"); 25 *result = config_dir.Append("google-chrome");
25 #else 26 #else
26 *result = config_dir.Append("chromium"); 27 *result = config_dir.Append("chromium");
27 #endif 28 #endif
28 return true; 29 return true;
29 } 30 }
30 31
32 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) {
33 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
34 // for a spec on where cache files go. Our rule is:
35 // - if the user-data-dir in the standard place,
36 // use same subdirectory of the cache directory.
37 // (this maps ~/.config/google-chrome to ~/.cache/google-chrome as well
38 // as the same thing for ~/.config/chromium)
39 // - otherwise, use the profile dir directly.
40
41 // Default value in cases where any of the following fails.
42 *result = profile_dir;
43
44 scoped_ptr<base::Environment> env(base::Environment::Create());
45
46 FilePath cache_dir;
47 if (!PathService::Get(base::DIR_CACHE, &cache_dir))
48 return;
49 FilePath config_dir(
50 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
51
52 if (!config_dir.AppendRelativePath(profile_dir, &cache_dir))
53 return;
54
55 *result = cache_dir;
56 }
57
31 bool GetChromeFrameUserDataDirectory(FilePath* result) { 58 bool GetChromeFrameUserDataDirectory(FilePath* result) {
32 scoped_ptr<base::Environment> env(base::Environment::Create()); 59 scoped_ptr<base::Environment> env(base::Environment::Create());
33 FilePath config_dir( 60 FilePath config_dir(
34 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); 61 base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
35 #if defined(GOOGLE_CHROME_BUILD) 62 #if defined(GOOGLE_CHROME_BUILD)
36 *result = config_dir.Append("google-chrome-frame"); 63 *result = config_dir.Append("google-chrome-frame");
37 #else 64 #else
38 *result = config_dir.Append("chrome-frame"); 65 *result = config_dir.Append("chrome-frame");
39 #endif 66 #endif
40 return true; 67 return true;
(...skipping 26 matching lines...) Expand all
67 return true; 94 return true;
68 } 95 }
69 96
70 bool GetUserDesktop(FilePath* result) { 97 bool GetUserDesktop(FilePath* result) {
71 scoped_ptr<base::Environment> env(base::Environment::Create()); 98 scoped_ptr<base::Environment> env(base::Environment::Create());
72 *result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); 99 *result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop");
73 return true; 100 return true;
74 } 101 }
75 102
76 } // namespace chrome 103 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/common/chrome_paths_internal.h ('k') | chrome/common/chrome_paths_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698