Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shlobj.h> | 6 #include <shlobj.h> |
| 7 | 7 |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/environment.h" | |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "base/win/scoped_co_mem.h" | 13 #include "base/win/scoped_co_mem.h" |
| 12 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
| 13 | 15 |
| 14 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 16 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
| 15 extern "C" IMAGE_DOS_HEADER __ImageBase; | 17 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 16 | 18 |
| 17 using base::FilePath; | 19 using base::FilePath; |
| 18 | 20 |
| 19 namespace base { | 21 namespace base { |
| 20 | 22 |
| 21 bool PathProviderWin(int key, FilePath* result) { | 23 bool PathProviderWin(int key, FilePath* result) { |
| 22 // We need to go compute the value. It would be nice to support paths with | 24 // We need to go compute the value. It would be nice to support paths with |
| 23 // names longer than MAX_PATH, but the system functions don't seem to be | 25 // names longer than MAX_PATH, but the system functions don't seem to be |
| 24 // designed for it either, with the exception of GetTempPath (but other | 26 // designed for it either, with the exception of GetTempPath (but other |
| 25 // things will surely break if the temp path is too long, so we don't bother | 27 // things will surely break if the temp path is too long, so we don't bother |
| 26 // handling it. | 28 // handling it. |
| 27 wchar_t system_buffer[MAX_PATH]; | 29 wchar_t system_buffer[MAX_PATH]; |
| 28 system_buffer[0] = 0; | 30 system_buffer[0] = 0; |
| 31 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 32 std::string programfiles_w6432; | |
|
cpu_(ooo_6.6-7.5)
2015/03/12 00:38:15
I think the construct of line 31 is on the expensi
Will Harris
2015/03/12 01:18:36
I checked and Environment is very lightweight, the
| |
| 29 | 33 |
| 30 FilePath cur; | 34 FilePath cur; |
| 31 switch (key) { | 35 switch (key) { |
| 32 case base::FILE_EXE: | 36 case base::FILE_EXE: |
| 33 GetModuleFileName(NULL, system_buffer, MAX_PATH); | 37 GetModuleFileName(NULL, system_buffer, MAX_PATH); |
| 34 cur = FilePath(system_buffer); | 38 cur = FilePath(system_buffer); |
| 35 break; | 39 break; |
| 36 case base::FILE_MODULE: { | 40 case base::FILE_MODULE: { |
| 37 // the resource containing module is assumed to be the one that | 41 // the resource containing module is assumed to be the one that |
| 38 // this code lives in, whether that's a dll or exe | 42 // this code lives in, whether that's a dll or exe |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 58 cur = FilePath(system_buffer); | 62 cur = FilePath(system_buffer); |
| 59 break; | 63 break; |
| 60 } | 64 } |
| 61 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. | 65 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. |
| 62 case base::DIR_PROGRAM_FILES: | 66 case base::DIR_PROGRAM_FILES: |
| 63 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, | 67 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
| 64 SHGFP_TYPE_CURRENT, system_buffer))) | 68 SHGFP_TYPE_CURRENT, system_buffer))) |
| 65 return false; | 69 return false; |
| 66 cur = FilePath(system_buffer); | 70 cur = FilePath(system_buffer); |
| 67 break; | 71 break; |
| 72 case base::DIR_PROGRAM_FILES6432: | |
| 73 #if defined(_WIN64) | |
| 74 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, | |
| 75 SHGFP_TYPE_CURRENT, system_buffer))) | |
| 76 return false; | |
| 77 cur = FilePath(system_buffer); | |
| 78 #else | |
| 79 if (!env->GetVar("ProgramW6432", &programfiles_w6432)) | |
| 80 return false; | |
| 81 // GetVar returns UTF8 - convert back to Wide. | |
| 82 cur = FilePath(UTF8ToWide(programfiles_w6432)); | |
| 83 #endif | |
| 84 break; | |
| 68 case base::DIR_IE_INTERNET_CACHE: | 85 case base::DIR_IE_INTERNET_CACHE: |
| 69 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, | 86 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, |
| 70 SHGFP_TYPE_CURRENT, system_buffer))) | 87 SHGFP_TYPE_CURRENT, system_buffer))) |
| 71 return false; | 88 return false; |
| 72 cur = FilePath(system_buffer); | 89 cur = FilePath(system_buffer); |
| 73 break; | 90 break; |
| 74 case base::DIR_COMMON_START_MENU: | 91 case base::DIR_COMMON_START_MENU: |
| 75 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, | 92 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, |
| 76 SHGFP_TYPE_CURRENT, system_buffer))) | 93 SHGFP_TYPE_CURRENT, system_buffer))) |
| 77 return false; | 94 return false; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 break; | 180 break; |
| 164 default: | 181 default: |
| 165 return false; | 182 return false; |
| 166 } | 183 } |
| 167 | 184 |
| 168 *result = cur; | 185 *result = cur; |
| 169 return true; | 186 return true; |
| 170 } | 187 } |
| 171 | 188 |
| 172 } // namespace base | 189 } // namespace base |
| OLD | NEW |