summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-05 19:46:31 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-05 19:46:31 +0000
commitac510e1f4a322381d1e82c9669bfd3c05113d6e6 (patch)
treef88fa9f412405d33f08755171503dac2c77d5e0b
parent6d55c2fbc384e3f02a89b69e29fd8934ba2f0966 (diff)
downloadchromium_src-ac510e1f4a322381d1e82c9669bfd3c05113d6e6.zip
chromium_src-ac510e1f4a322381d1e82c9669bfd3c05113d6e6.tar.gz
chromium_src-ac510e1f4a322381d1e82c9669bfd3c05113d6e6.tar.bz2
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
-rw-r--r--base/base_paths.cc86
-rw-r--r--base/base_paths.h22
-rw-r--r--base/base_paths_win.cc131
-rw-r--r--base/base_paths_win.h64
-rw-r--r--base/build/base.vcproj8
-rw-r--r--base/path_service.cc23
6 files changed, 232 insertions, 102 deletions
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 @@ bool PathProvider(int key, std::wstring* result) {
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;
}
diff --git a/base/base_paths.h b/base/base_paths.h
index 60a59ca..ba844b8 100644
--- a/base/base_paths.h
+++ b/base/base_paths.h
@@ -33,6 +33,11 @@
// This file declares path keys for the base module. These can be used with
// the PathService to access various special directories and files.
+#include "base/basictypes.h"
+#ifdef OS_WIN
+#include "base/base_paths_win.h"
+#endif
+
namespace base {
enum {
@@ -41,27 +46,10 @@ enum {
DIR_CURRENT, // current directory
DIR_EXE, // directory containing FILE_EXE
DIR_MODULE, // directory containing FILE_MODULE
- FILE_EXE, // path and filename of the current executable
- FILE_MODULE, // path and filename of the module containing the code for the
- // PathService (which could differ from FILE_EXE if the
- // PathService were compiled into a DLL, for example)
DIR_TEMP, // temporary directory
- DIR_WINDOWS, // Windows directory, usually "c:\windows"
- DIR_SYSTEM, // Usually c:\windows\system32"
- DIR_PROGRAM_FILES, // Usually c:\program files
-
DIR_SOURCE_ROOT, // Returns the root of the source tree. This key is useful
// for tests that need to locate various resources. It
// should not be used outside of test code.
- DIR_APP_DATA, // Application Data directory under the user profile.
- DIR_LOCAL_APP_DATA_LOW, // Local AppData directory for low integrity level.
- DIR_LOCAL_APP_DATA, // "Local Settings\Application Data" directory under the
- // user profile.
- DIR_IE_INTERNET_CACHE, // Temporary Internet Files directory.
- DIR_COMMON_START_MENU, // Usually "C:\Documents and Settings\All Users\
- // Start Menu\Programs"
- DIR_START_MENU, // Usually "C:\Documents and Settings\<user>\
- // Start Menu\Programs"
PATH_END
};
diff --git a/base/base_paths_win.cc b/base/base_paths_win.cc
new file mode 100644
index 0000000..9afd875
--- /dev/null
+++ b/base/base_paths_win.cc
@@ -0,0 +1,131 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "base/base_paths_win.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 PathProviderWin(int key, std::wstring* result) {
+
+ // 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_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_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;
+ 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;
+ default:
+ return false;
+ }
+
+ result->swap(cur);
+ return true;
+}
+
+} // namespace base
diff --git a/base/base_paths_win.h b/base/base_paths_win.h
new file mode 100644
index 0000000..6905ac6
--- /dev/null
+++ b/base/base_paths_win.h
@@ -0,0 +1,64 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef BASE_BASE_PATHS_WIN_H__
+#define BASE_BASE_PATHS_WIN_H__
+
+// This file declares windows-specific path keys for the base module.
+// These can be used with the PathService to access various special
+// directories and files.
+
+namespace base {
+
+enum {
+ PATH_WIN_START = 100,
+
+ FILE_EXE, // path and filename of the current executable
+ FILE_MODULE, // path and filename of the module containing the code for the
+ // PathService (which could differ from FILE_EXE if the
+ // PathService were compiled into a DLL, for example)
+ DIR_WINDOWS, // Windows directory, usually "c:\windows"
+ DIR_SYSTEM, // Usually c:\windows\system32"
+ DIR_PROGRAM_FILES, // Usually c:\program files
+
+ DIR_IE_INTERNET_CACHE, // Temporary Internet Files directory.
+ DIR_COMMON_START_MENU, // Usually "C:\Documents and Settings\All Users\
+ // Start Menu\Programs"
+ DIR_START_MENU, // Usually "C:\Documents and Settings\<user>\
+ // Start Menu\Programs"
+ DIR_APP_DATA, // Application Data directory under the user profile.
+ DIR_LOCAL_APP_DATA_LOW, // Local AppData directory for low integrity level.
+ DIR_LOCAL_APP_DATA, // "Local Settings\Application Data" directory under the
+ // user profile.
+ PATH_WIN_END
+};
+
+} // namespace base
+
+#endif // BASE_BASE_PATHS_WIN_H__
diff --git a/base/build/base.vcproj b/base/build/base.vcproj
index 68dbce3..5dc844e 100644
--- a/base/build/base.vcproj
+++ b/base/build/base.vcproj
@@ -158,6 +158,14 @@
>
</File>
<File
+ RelativePath="..\base_paths_win.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\base_paths_win.h"
+ >
+ </File>
+ <File
RelativePath="..\base_switches.cc"
>
</File>
diff --git a/base/path_service.cc b/base/path_service.cc
index f4b3a83..b3d413f 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -42,6 +42,9 @@
namespace base {
bool PathProvider(int key, std::wstring* result);
+#if OS_WIN
+ bool PathProviderWin(int key, std::wstring* result);
+#endif
}
namespace {
@@ -69,13 +72,31 @@ static Provider base_provider = {
#endif
};
+#ifdef OS_WIN
+static Provider base_provider_win = {
+ base::PathProviderWin,
+ &base_provider,
+#ifndef NDEBUG
+ base::PATH_WIN_START,
+ base::PATH_WIN_END
+#endif
+};
+#endif
+
struct PathData {
Lock lock;
PathMap cache; // Track mappings from path key to path value.
PathSet overrides; // Track whether a path has been overridden.
Provider* providers; // Linked list of path service providers.
- PathData() : providers(&base_provider) {
+ PathData() {
+#if defined(OS_WIN)
+ providers = &base_provider_win;
+#elif defined(OS_MACOSX)
+ providers = &base_provider;
+#elif defined(OS_LINUX)
+ providers = &base_provider;
+#endif
}
};