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

Side by Side Diff: base/base_paths_win.cc

Issue 10910209: Add new PathService paths for Windows' All Users Desktop and Quick Launch folders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile post-merge Created 8 years, 3 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/base_paths_win.h"
6 5
7 #include <windows.h> 6 #include <windows.h>
8 #include <shlobj.h> 7 #include <shlobj.h>
9 8
9 #include "base/base_paths.h"
10 #include "base/base_paths_win.h"
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/win/scoped_co_mem.h" 14 #include "base/win/scoped_co_mem.h"
14 #include "base/win/windows_version.h" 15 #include "base/win/windows_version.h"
15 16
16 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx 17 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
17 extern "C" IMAGE_DOS_HEADER __ImageBase; 18 extern "C" IMAGE_DOS_HEADER __ImageBase;
18 19
20 namespace {
21
22 bool GetQuickLaunchPath(bool default_user, FilePath* result) {
23 if (default_user) {
24 wchar_t system_buffer[MAX_PATH];
25 system_buffer[0] = 0;
26 // As per MSDN (http://goo.gl/U8Wcp) passing -1 for |hToken| indicates the
27 // Default user.
28 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA,
29 reinterpret_cast<HANDLE>(-1), SHGFP_TYPE_CURRENT,
30 system_buffer))) {
31 return false;
32 }
33 *result = FilePath(system_buffer);
34 } else if (!PathService::Get(base::DIR_APP_DATA, result)) {
35 // For the current user, grab the APPDATA directory directly from the
36 // PathService cache.
37 return false;
38 }
39 // According to various sources (http://goo.gl/3MFtg and http://goo.gl/GxLRL):
40 // appending "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the
41 // only reliable way to get the quick launch folder across all versions of
42 // Windows.
43 *result = result->AppendASCII("Microsoft");
44 *result = result->AppendASCII("Internet Explorer");
45 *result = result->AppendASCII("Quick Launch");
46 return true;
47 }
48
49 } // namespace
50
19 namespace base { 51 namespace base {
20 52
21 bool PathProviderWin(int key, FilePath* result) { 53 bool PathProviderWin(int key, FilePath* result) {
22 54
23 // We need to go compute the value. It would be nice to support paths with 55 // We need to go compute the value. It would be nice to support paths with
24 // names longer than MAX_PATH, but the system functions don't seem to be 56 // names longer than MAX_PATH, but the system functions don't seem to be
25 // designed for it either, with the exception of GetTempPath (but other 57 // designed for it either, with the exception of GetTempPath (but other
26 // things will surely break if the temp path is too long, so we don't bother 58 // things will surely break if the temp path is too long, so we don't bother
27 // handling it. 59 // handling it.
28 wchar_t system_buffer[MAX_PATH]; 60 wchar_t system_buffer[MAX_PATH];
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return false; 163 return false;
132 164
133 base::win::ScopedCoMem<wchar_t> path_buf; 165 base::win::ScopedCoMem<wchar_t> path_buf;
134 if (FAILED(SHGetKnownFolderPath(FOLDERID_ApplicationShortcuts, 0, NULL, 166 if (FAILED(SHGetKnownFolderPath(FOLDERID_ApplicationShortcuts, 0, NULL,
135 &path_buf))) 167 &path_buf)))
136 return false; 168 return false;
137 169
138 cur = FilePath(string16(path_buf)); 170 cur = FilePath(string16(path_buf));
139 break; 171 break;
140 } 172 }
173 case base::DIR_USER_DESKTOP: {
174 if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
175 SHGFP_TYPE_CURRENT, system_buffer))) {
176 return false;
177 }
178 cur = FilePath(system_buffer);
179 break;
180 }
181 case base::DIR_COMMON_DESKTOP: {
182 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL,
183 SHGFP_TYPE_CURRENT, system_buffer))) {
184 return false;
185 }
186 cur = FilePath(system_buffer);
187 break;
188 }
189 case base::DIR_USER_QUICK_LAUNCH: {
190 if (!GetQuickLaunchPath(false, &cur))
191 return false;
192 break;
193 }
194 case base::DIR_DEFAULT_USER_QUICK_LAUNCH: {
195 if (!GetQuickLaunchPath(true, &cur))
196 return false;
197 break;
198 }
141 default: 199 default:
142 return false; 200 return false;
143 } 201 }
144 202
145 *result = cur; 203 *result = cur;
146 return true; 204 return true;
147 } 205 }
148 206
149 } // namespace base 207 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698