refactor base_paths so that windows-specific paths are pulled out into their own file. Note that some of the same path key names will exist in other platform-specific files. For example, base_paths_mac.mm will have FILE_EXE and DIR_APP_DATA (among others).
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@389 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: ac510e1f4a322381d1e82c9669bfd3c05113d6e6
diff --git a/base/base_paths.cc b/base/base_paths.cc
index 389b0bb..ed0a489 100644
--- a/base/base_paths.cc
+++ b/base/base_paths.cc
@@ -29,71 +29,28 @@
#include "base/base_paths.h"
-#include <shlobj.h>
-
#include "base/file_util.h"
#include "base/path_service.h"
-// This is here for the sole purpose of looking up the corresponding HMODULE.
-static int handle_lookup = 0;
-
namespace base {
bool PathProvider(int key, std::wstring* result) {
// NOTE: DIR_CURRENT is a special cased in PathService::Get
- // We need to go compute the value. It would be nice to support paths with
- // names longer than MAX_PATH, but the system functions don't seem to be
- // designed for it either, with the exception of GetTempPath (but other
- // things will surely break if the temp path is too long, so we don't bother
- // handling it.
- wchar_t system_buffer[MAX_PATH];
- system_buffer[0] = 0;
-
std::wstring cur;
switch (key) {
- case base::FILE_EXE:
- GetModuleFileName(NULL, system_buffer, MAX_PATH);
- cur = system_buffer;
- break;
- case base::FILE_MODULE: {
- // the resource containing module is assumed to be the one that
- // this code lives in, whether that's a dll or exe
- MEMORY_BASIC_INFORMATION info = { 0 };
- VirtualQuery(reinterpret_cast<void*>(&handle_lookup),
- &info, sizeof(info));
- // Module handles are just the allocation base address of the module.
- HMODULE this_module = reinterpret_cast<HMODULE>(info.AllocationBase);
- GetModuleFileName(this_module, system_buffer, MAX_PATH);
- cur = system_buffer;
- break;
- }
case base::DIR_EXE:
- PathProvider(base::FILE_EXE, &cur);
+ PathService::Get(base::FILE_EXE, &cur);
file_util::TrimFilename(&cur);
break;
case base::DIR_MODULE:
- PathProvider(base::FILE_MODULE, &cur);
+ PathService::Get(base::FILE_MODULE, &cur);
file_util::TrimFilename(&cur);
break;
case base::DIR_TEMP:
if (!file_util::GetTempDir(&cur))
return false;
break;
- case base::DIR_WINDOWS:
- GetWindowsDirectory(system_buffer, MAX_PATH);
- cur = system_buffer;
- break;
- case base::DIR_SYSTEM:
- GetSystemDirectory(system_buffer, MAX_PATH);
- cur = system_buffer;
- break;
- case base::DIR_PROGRAM_FILES:
- if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
- SHGFP_TYPE_CURRENT, system_buffer)))
- return false;
- cur = system_buffer;
- break;
case base::DIR_SOURCE_ROOT:
// By default, unit tests execute two levels deep from the source root.
// For example: chrome/{Debug|Release}/ui_tests.exe
@@ -101,45 +58,6 @@
file_util::UpOneDirectory(&cur);
file_util::UpOneDirectory(&cur);
break;
- case base::DIR_APP_DATA:
- if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
- system_buffer)))
- return false;
- cur = system_buffer;
- break;
- case base::DIR_LOCAL_APP_DATA_LOW:
- // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
- if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
- system_buffer)))
- return false;
- cur = system_buffer;
- file_util::UpOneDirectory(&cur);
- file_util::AppendToPath(&cur, L"LocalLow");
- break;
- case base::DIR_LOCAL_APP_DATA:
- if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL,
- SHGFP_TYPE_CURRENT, system_buffer)))
- return false;
- cur = system_buffer;
- break;
- case base::DIR_IE_INTERNET_CACHE:
- if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL,
- SHGFP_TYPE_CURRENT, system_buffer)))
- return false;
- cur = system_buffer;
- break;
- case base::DIR_COMMON_START_MENU:
- if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL,
- SHGFP_TYPE_CURRENT, system_buffer)))
- return false;
- cur = system_buffer;
- break;
- case base::DIR_START_MENU:
- if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL,
- SHGFP_TYPE_CURRENT, system_buffer)))
- return false;
- cur = system_buffer;
- break;
default:
return false;
}