OLD | NEW |
1 // Copyright (c) 2006-2008 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/env_var.h" |
7 #include "base/linux_util.h" | 8 #include "base/linux_util.h" |
8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
9 | 10 |
10 namespace chrome { | 11 namespace chrome { |
11 | 12 |
12 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html | 13 // See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html |
13 // for a spec on where config files go. The net effect for most | 14 // for a spec on where config files go. The net effect for most |
14 // systems is we use ~/.config/chromium/ for Chromium and | 15 // systems is we use ~/.config/chromium/ for Chromium and |
15 // ~/.config/google-chrome/ for official builds. | 16 // ~/.config/google-chrome/ for official builds. |
16 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .) | 17 // (This also helps us sidestep issues with other apps grabbing ~/.chromium .) |
17 bool GetDefaultUserDataDirectory(FilePath* result) { | 18 bool GetDefaultUserDataDirectory(FilePath* result) { |
18 scoped_ptr<base::EnvironmentVariableGetter> env( | 19 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
19 base::EnvironmentVariableGetter::Create()); | |
20 FilePath config_dir( | 20 FilePath config_dir( |
21 base::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); | 21 base::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); |
22 #if defined(GOOGLE_CHROME_BUILD) | 22 #if defined(GOOGLE_CHROME_BUILD) |
23 *result = config_dir.Append("google-chrome"); | 23 *result = config_dir.Append("google-chrome"); |
24 #else | 24 #else |
25 *result = config_dir.Append("chromium"); | 25 *result = config_dir.Append("chromium"); |
26 #endif | 26 #endif |
27 return true; | 27 return true; |
28 } | 28 } |
29 | 29 |
30 bool GetChromeFrameUserDataDirectory(FilePath* result) { | 30 bool GetChromeFrameUserDataDirectory(FilePath* result) { |
31 scoped_ptr<base::EnvironmentVariableGetter> env( | 31 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
32 base::EnvironmentVariableGetter::Create()); | |
33 FilePath config_dir( | 32 FilePath config_dir( |
34 base::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); | 33 base::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config")); |
35 #if defined(GOOGLE_CHROME_BUILD) | 34 #if defined(GOOGLE_CHROME_BUILD) |
36 *result = config_dir.Append("google-chrome-frame"); | 35 *result = config_dir.Append("google-chrome-frame"); |
37 #else | 36 #else |
38 *result = config_dir.Append("chrome-frame"); | 37 *result = config_dir.Append("chrome-frame"); |
39 #endif | 38 #endif |
40 return true; | 39 return true; |
41 } | 40 } |
42 | 41 |
43 bool GetUserDocumentsDirectory(FilePath* result) { | 42 bool GetUserDocumentsDirectory(FilePath* result) { |
44 scoped_ptr<base::EnvironmentVariableGetter> env( | 43 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
45 base::EnvironmentVariableGetter::Create()); | |
46 *result = base::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents"); | 44 *result = base::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents"); |
47 return true; | 45 return true; |
48 } | 46 } |
49 | 47 |
50 // We respect the user's preferred download location, unless it is | 48 // We respect the user's preferred download location, unless it is |
51 // ~ or their desktop directory, in which case we default to ~/Downloads. | 49 // ~ or their desktop directory, in which case we default to ~/Downloads. |
52 bool GetUserDownloadsDirectory(FilePath* result) { | 50 bool GetUserDownloadsDirectory(FilePath* result) { |
53 scoped_ptr<base::EnvironmentVariableGetter> env( | 51 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
54 base::EnvironmentVariableGetter::Create()); | |
55 *result = base::GetXDGUserDirectory(env.get(), "DOWNLOAD", "Downloads"); | 52 *result = base::GetXDGUserDirectory(env.get(), "DOWNLOAD", "Downloads"); |
56 | 53 |
57 FilePath home = base::GetHomeDir(env.get()); | 54 FilePath home = base::GetHomeDir(env.get()); |
58 if (*result == home) { | 55 if (*result == home) { |
59 *result = home.Append("Downloads"); | 56 *result = home.Append("Downloads"); |
60 return true; | 57 return true; |
61 } | 58 } |
62 | 59 |
63 FilePath desktop; | 60 FilePath desktop; |
64 GetUserDesktop(&desktop); | 61 GetUserDesktop(&desktop); |
65 if (*result == desktop) { | 62 if (*result == desktop) { |
66 *result = home.Append("Downloads"); | 63 *result = home.Append("Downloads"); |
67 } | 64 } |
68 | 65 |
69 return true; | 66 return true; |
70 } | 67 } |
71 | 68 |
72 bool GetUserDesktop(FilePath* result) { | 69 bool GetUserDesktop(FilePath* result) { |
73 scoped_ptr<base::EnvironmentVariableGetter> env( | 70 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); |
74 base::EnvironmentVariableGetter::Create()); | |
75 *result = base::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); | 71 *result = base::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); |
76 return true; | 72 return true; |
77 } | 73 } |
78 | 74 |
79 } // namespace chrome | 75 } // namespace chrome |
OLD | NEW |