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

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

Issue 8059: Port parts of chrome/common to Linux.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 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 | « no previous file | chrome/common/common.scons » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h"
6
7 #if defined(OS_WIN)
5 #include <windows.h> 8 #include <windows.h>
6 #include <shellapi.h> 9 #include <shellapi.h>
7 #include <shlobj.h> 10 #include <shlobj.h>
11 #endif
8 12
9 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
10 14
11 #include "base/command_line.h" 15 #include "base/command_line.h"
12 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/logging.h"
13 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/sys_info.h"
14 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
16 22
17 namespace chrome { 23 namespace chrome {
18 24
19 bool GetUserDirectory(int directory_type, std::wstring* result) {
20 wchar_t path_buf[MAX_PATH];
21 if (FAILED(SHGetFolderPath(NULL, directory_type, NULL,
22 SHGFP_TYPE_CURRENT, path_buf)))
23 return false;
24 result->assign(path_buf);
25 return true;
26 }
27
28 // Gets the default user data directory, regardless of whether 25 // Gets the default user data directory, regardless of whether
29 // DIR_USER_DATA has been overridden by a command-line option. 26 // DIR_USER_DATA has been overridden by a command-line option.
30 bool GetDefaultUserDataDirectory(std::wstring* result) { 27 bool GetDefaultUserDataDirectory(std::wstring* result) {
28 #if defined(OS_WIN)
31 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, result)) 29 if (!PathService::Get(base::DIR_LOCAL_APP_DATA, result))
32 return false; 30 return false;
33 #if defined(GOOGLE_CHROME_BUILD) 31 #if defined(GOOGLE_CHROME_BUILD)
34 file_util::AppendToPath(result, L"Google"); 32 file_util::AppendToPath(result, L"Google");
35 #endif 33 #endif
36 file_util::AppendToPath(result, chrome::kBrowserAppName); 34 file_util::AppendToPath(result, chrome::kBrowserAppName);
37 file_util::AppendToPath(result, chrome::kUserDataDirname); 35 file_util::AppendToPath(result, chrome::kUserDataDirname);
38 return true; 36 return true;
37 #else // defined(OS_WIN)
38 // TODO(port): Decide what to do on other platforms.
39 NOTIMPLEMENTED();
40 return false;
41 #endif // defined(OS_WIN)
39 } 42 }
40 43
41 bool GetGearsPluginPathFromCommandLine(std::wstring *path) { 44 bool GetGearsPluginPathFromCommandLine(std::wstring *path) {
42 #ifndef NDEBUG 45 #ifndef NDEBUG
43 // for debugging, support a cmd line based override 46 // for debugging, support a cmd line based override
44 CommandLine command_line; 47 CommandLine command_line;
45 *path = command_line.GetSwitchValue(switches::kGearsPluginPathOverride); 48 *path = command_line.GetSwitchValue(switches::kGearsPluginPathOverride);
46 return !path->empty(); 49 return !path->empty();
47 #else 50 #else
48 return false; 51 return false;
49 #endif 52 #endif
50 } 53 }
51 54
52 bool PathProvider(int key, std::wstring* result) { 55 bool PathProvider(int key, std::wstring* result) {
53 // Some keys are just aliases... 56 // Some keys are just aliases...
54 switch (key) { 57 switch (key) {
55 case chrome::DIR_APP: 58 case chrome::DIR_APP:
56 return PathService::Get(base::DIR_MODULE, result); 59 return PathService::Get(base::DIR_MODULE, result);
57 case chrome::DIR_LOGS: 60 case chrome::DIR_LOGS:
58 #ifndef NDEBUG 61 #ifndef NDEBUG
59 return PathService::Get(chrome::DIR_USER_DATA, result); 62 return PathService::Get(chrome::DIR_USER_DATA, result);
60 #else 63 #else
61 return PathService::Get(base::DIR_EXE, result); 64 return PathService::Get(base::DIR_EXE, result);
62 #endif 65 #endif
63 case chrome::FILE_RESOURCE_MODULE: 66 case chrome::FILE_RESOURCE_MODULE:
64 return PathService::Get(base::FILE_MODULE, result); 67 return PathService::Get(base::FILE_MODULE, result);
65 } 68 }
66 69
67 // We need to go compute the value. It would be nice to support paths with
68 // names longer than MAX_PATH, but the system functions don't seem to be
69 // designed for it either, with the exception of GetTempPath (but other
70 // things will surely break if the temp path is too long, so we don't bother
71 // handling it.
72 wchar_t system_buffer[MAX_PATH];
73 system_buffer[0] = 0;
74
75 // Assume that we will need to create the directory if it does not already 70 // Assume that we will need to create the directory if it does not already
76 // exist. This flag can be set to true to prevent checking. 71 // exist. This flag can be set to true to prevent checking.
77 bool exists = false; 72 bool exists = false;
78 73
79 std::wstring cur; 74 std::wstring cur;
80 switch (key) { 75 switch (key) {
81 case chrome::DIR_USER_DATA: 76 case chrome::DIR_USER_DATA:
82 if (!GetDefaultUserDataDirectory(&cur)) 77 if (!GetDefaultUserDataDirectory(&cur))
83 return false; 78 return false;
84 break; 79 break;
85 case chrome::DIR_USER_DOCUMENTS: 80 case chrome::DIR_USER_DOCUMENTS:
86 if (!GetUserDirectory(CSIDL_MYDOCUMENTS, &cur)) 81 #if defined(OS_WIN)
87 return false; 82 {
83 wchar_t path_buf[MAX_PATH];
84 if (FAILED(SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL,
85 SHGFP_TYPE_CURRENT, path_buf)))
86 return false;
87 cur.assign(path_buf);
88 }
89 #else
90 // TODO(port): Get the path (possibly using xdg-user-dirs)
91 // or decide we don't need it on other platforms.
92 NOTIMPLEMENTED();
93 return false;
94 #endif
88 break; 95 break;
89 case chrome::DIR_DEFAULT_DOWNLOADS: 96 case chrome::DIR_DEFAULT_DOWNLOADS:
90 // On Vista, we can get the download path using a Win API 97 // On Vista, we can get the download path using a Win API
91 // (http://msdn.microsoft.com/en-us/library/bb762584(VS.85).aspx), 98 // (http://msdn.microsoft.com/en-us/library/bb762584(VS.85).aspx),
92 // but it can be set to Desktop, which is dangerous. Instead, 99 // but it can be set to Desktop, which is dangerous. Instead,
93 // we just use 'Downloads' under DIR_USER_DOCUMENTS. Localizing 100 // we just use 'Downloads' under DIR_USER_DOCUMENTS. Localizing
94 // 'downloads' is not a good idea because Chrome's UI language 101 // 'downloads' is not a good idea because Chrome's UI language
95 // can be changed. 102 // can be changed.
96 if (!PathService::Get(chrome::DIR_USER_DOCUMENTS, &cur)) 103 if (!PathService::Get(chrome::DIR_USER_DOCUMENTS, &cur))
97 return false; 104 return false;
98 file_util::AppendToPath(&cur, L"Downloads"); 105 file_util::AppendToPath(&cur, L"Downloads");
99 // TODO(port): This will fail on other platforms unless we 106 // TODO(port): This will fail on other platforms unless we
100 // implement DIR_USER_DOCUMENTS or use xdg-user-dirs to 107 // implement DIR_USER_DOCUMENTS or use xdg-user-dirs to
101 // get the download directory independently of DIR_USER_DOCUMENTS. 108 // get the download directory independently of DIR_USER_DOCUMENTS.
102 break; 109 break;
103 case chrome::DIR_CRASH_DUMPS: 110 case chrome::DIR_CRASH_DUMPS:
104 // The crash reports are always stored relative to the default user data 111 // The crash reports are always stored relative to the default user data
105 // directory. This avoids the problem of having to re-initialize the 112 // directory. This avoids the problem of having to re-initialize the
106 // exception handler after parsing command line options, which may 113 // exception handler after parsing command line options, which may
107 // override the location of the app's profile directory. 114 // override the location of the app's profile directory.
108 if (!GetDefaultUserDataDirectory(&cur)) 115 if (!GetDefaultUserDataDirectory(&cur))
109 return false; 116 return false;
110 file_util::AppendToPath(&cur, L"Crash Reports"); 117 file_util::AppendToPath(&cur, L"Crash Reports");
111 break; 118 break;
112 case chrome::DIR_USER_DESKTOP: 119 case chrome::DIR_USER_DESKTOP:
113 if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 120 #if defined(OS_WIN)
114 SHGFP_TYPE_CURRENT, system_buffer))) 121 {
115 return false; 122 // We need to go compute the value. It would be nice to support paths
116 cur = system_buffer; 123 // with names longer than MAX_PATH, but the system functions don't seem
124 // to be designed for it either, with the exception of GetTempPath
125 // (but other things will surely break if the temp path is too long,
126 // so we don't bother handling it.
127 wchar_t system_buffer[MAX_PATH];
128 system_buffer[0] = 0;
129 if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
130 SHGFP_TYPE_CURRENT, system_buffer)))
131 return false;
132 cur.assign(system_buffer);
133 }
134 #else
135 // TODO(port): Get the path (possibly using xdg-user-dirs)
136 // or decide we don't need it on other platforms.
137 NOTIMPLEMENTED();
138 return false;
139 #endif
117 exists = true; 140 exists = true;
118 break; 141 break;
119 case chrome::DIR_RESOURCES: 142 case chrome::DIR_RESOURCES:
120 if (!PathService::Get(chrome::DIR_APP, &cur)) 143 if (!PathService::Get(chrome::DIR_APP, &cur))
121 return false; 144 return false;
122 file_util::AppendToPath(&cur, L"resources"); 145 file_util::AppendToPath(&cur, L"resources");
123 break; 146 break;
124 case chrome::DIR_INSPECTOR: 147 case chrome::DIR_INSPECTOR:
125 if (!PathService::Get(chrome::DIR_APP, &cur)) 148 if (!PathService::Get(chrome::DIR_APP, &cur))
126 return false; 149 return false;
(...skipping 11 matching lines...) Expand all
138 return false; 161 return false;
139 file_util::AppendToPath(&cur, L"locales"); 162 file_util::AppendToPath(&cur, L"locales");
140 break; 163 break;
141 case chrome::DIR_APP_DICTIONARIES: 164 case chrome::DIR_APP_DICTIONARIES:
142 if (!PathService::Get(base::DIR_EXE, &cur)) 165 if (!PathService::Get(base::DIR_EXE, &cur))
143 return false; 166 return false;
144 file_util::AppendToPath(&cur, L"Dictionaries"); 167 file_util::AppendToPath(&cur, L"Dictionaries");
145 break; 168 break;
146 case chrome::DIR_USER_SCRIPTS: 169 case chrome::DIR_USER_SCRIPTS:
147 // TODO(aa): Figure out where the script directory should live. 170 // TODO(aa): Figure out where the script directory should live.
171 #if defined(OS_WIN)
148 cur = L"C:\\SCRIPTS\\"; 172 cur = L"C:\\SCRIPTS\\";
173 #else
174 NOTIMPLEMENTED();
175 return false;
176 #endif
149 exists = true; // don't trigger directory creation code 177 exists = true; // don't trigger directory creation code
150 break; 178 break;
151 case chrome::FILE_LOCAL_STATE: 179 case chrome::FILE_LOCAL_STATE:
152 if (!PathService::Get(chrome::DIR_USER_DATA, &cur)) 180 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
153 return false; 181 return false;
154 file_util::AppendToPath(&cur, chrome::kLocalStateFilename); 182 file_util::AppendToPath(&cur, chrome::kLocalStateFilename);
155 exists = true; // don't trigger directory creation code 183 exists = true; // don't trigger directory creation code
156 break; 184 break;
157 case chrome::FILE_RECORDED_SCRIPT: 185 case chrome::FILE_RECORDED_SCRIPT:
158 if (!PathService::Get(chrome::DIR_USER_DATA, &cur)) 186 if (!PathService::Get(chrome::DIR_USER_DATA, &cur))
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 266 }
239 267
240 // This cannot be done as a static initializer sadly since Visual Studio will 268 // This cannot be done as a static initializer sadly since Visual Studio will
241 // eliminate this object file if there is no direct entry point into it. 269 // eliminate this object file if there is no direct entry point into it.
242 void RegisterPathProvider() { 270 void RegisterPathProvider() {
243 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); 271 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
244 } 272 }
245 273
246 } // namespace chrome 274 } // namespace chrome
247 275
OLDNEW
« no previous file with comments | « no previous file | chrome/common/common.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698