summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-06 16:01:25 +0000
committeravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-06 16:01:25 +0000
commit355cc27400bd3d128314f7203232cbb04c501cf2 (patch)
treed2cda0f887d0eb3d9c44717e702babda132576c0 /base
parentabb9d0ca091ed62a1ff77efca594932b31dce975 (diff)
downloadchromium_src-355cc27400bd3d128314f7203232cbb04c501cf2.zip
chromium_src-355cc27400bd3d128314f7203232cbb04c501cf2.tar.gz
chromium_src-355cc27400bd3d128314f7203232cbb04c501cf2.tar.bz2
Mac changes to the path service.
Review URL: http://chrome-reviews.prom.corp.google.com/1107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.xcodeproj/project.pbxproj20
-rw-r--r--base/path_service.cc44
2 files changed, 45 insertions, 19 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index c1c6fbd..75041cc 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -101,7 +101,7 @@
ABF4B9AF0DC2BC6200A6E319 /* json_reader.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254031B0D92D1F40006B936 /* json_reader.cc */; };
ABF4B9B00DC2BC6500A6E319 /* json_writer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254031D0D92D1F40006B936 /* json_writer.cc */; };
ABF4B9B20DC2BC8300A6E319 /* memory_debug.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8254032B0D92D2090006B936 /* memory_debug.cc */; };
- ABF4B9B50DC2BC9F00A6E319 /* path_service_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B9B40DC2BC9F00A6E319 /* path_service_mac.cc */; };
+ ABF4B9B50DC2BC9F00A6E319 /* path_service.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B9B40DC2BC9F00A6E319 /* path_service.cc */; };
ABF4B9B90DC2BCE300A6E319 /* platform_thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 82E23FCC0D9C219600F8B40A /* platform_thread.cc */; };
ABF4B9BC0DC2BD1000A6E319 /* sha2.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403620D92D27C0006B936 /* sha2.cc */; };
ABF4B9BE0DC2BD1500A6E319 /* sha512.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403700D92D2840006B936 /* sha512.cc */; };
@@ -253,42 +253,42 @@
isa = PBXContainerItemProxy;
containerPortal = E45A2C680E47AEFF00DB1196 /* gtest.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = D2AAC045055464E500DB518D /* gtest */;
+ remoteGlobalIDString = D2AAC045055464E500DB518D;
remoteInfo = gtest;
};
E49115D90E47B397001EE8C3 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD5408A0D6F743F003CD41E /* icudata_stub */;
+ remoteGlobalIDString = 7BD5408A0D6F743F003CD41E;
remoteInfo = icudata_stub;
};
E49115DB0E47B397001EE8C3 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD53AAA0D6F6671003CD41E /* icuuc */;
+ remoteGlobalIDString = 7BD53AAA0D6F6671003CD41E;
remoteInfo = icuuc;
};
E49115DD0E47B397001EE8C3 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD53EA50D6F6FC7003CD41E /* icui18n */;
+ remoteGlobalIDString = 7BD53EA50D6F6FC7003CD41E;
remoteInfo = icui18n;
};
E49115DF0E47B397001EE8C3 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 7BD540250D6F727B003CD41E /* icutu */;
+ remoteGlobalIDString = 7BD540250D6F727B003CD41E;
remoteInfo = icutu;
};
E49115E10E47B39E001EE8C3 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E4562AF30E27E428005E4685 /* icu.xcodeproj */;
proxyType = 1;
- remoteGlobalIDString = 82C262C30DCF9411005CFE91 /* icudatastatic */;
+ remoteGlobalIDString = 82C262C30DCF9411005CFE91;
remoteInfo = icudatastatic;
};
/* End PBXContainerItemProxy section */
@@ -453,7 +453,7 @@
ABF4B99D0DC2BB6000A6E319 /* clipboard.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard.mm; sourceTree = "<group>"; };
ABF4B9A90DC2BC2A00A6E319 /* file_util_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_mac.cc; sourceTree = "<group>"; };
ABF4B9AC0DC2BC4800A6E319 /* file_version_info.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = file_version_info.mm; sourceTree = "<group>"; };
- ABF4B9B40DC2BC9F00A6E319 /* path_service_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service_mac.cc; sourceTree = "<group>"; };
+ ABF4B9B40DC2BC9F00A6E319 /* path_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service.cc; sourceTree = "<group>"; };
E45629D60E27BF9A005E4685 /* Tests.gtest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.gtest; sourceTree = BUILT_PRODUCTS_DIR; };
E45629E40E27C058005E4685 /* rect_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rect_unittest.cc; sourceTree = "<group>"; };
E4562A200E27C8C1005E4685 /* png_codec_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = png_codec_unittest.cc; sourceTree = "<group>"; };
@@ -604,7 +604,7 @@
825403390D92D2210006B936 /* observer_list.h */,
E4562AD60E27E27E005E4685 /* path_service_unittest.cc */,
8254033B0D92D2210006B936 /* path_service.h */,
- ABF4B9B40DC2BC9F00A6E319 /* path_service_mac.cc */,
+ ABF4B9B40DC2BC9F00A6E319 /* path_service.cc */,
E4562C680E2803C3005E4685 /* pickle_unittest.cc */,
8254033E0D92D2210006B936 /* pickle.cc */,
8254033F0D92D2210006B936 /* pickle.h */,
@@ -1104,7 +1104,7 @@
ABF4B9AF0DC2BC6200A6E319 /* json_reader.cc in Sources */,
ABF4B9B00DC2BC6500A6E319 /* json_writer.cc in Sources */,
ABF4B9B20DC2BC8300A6E319 /* memory_debug.cc in Sources */,
- ABF4B9B50DC2BC9F00A6E319 /* path_service_mac.cc in Sources */,
+ ABF4B9B50DC2BC9F00A6E319 /* path_service.cc in Sources */,
ABF4B9B90DC2BCE300A6E319 /* platform_thread.cc in Sources */,
ABF4B9BC0DC2BD1000A6E319 /* sha2.cc in Sources */,
ABF4B9BE0DC2BD1500A6E319 /* sha512.cc in Sources */,
diff --git a/base/path_service.cc b/base/path_service.cc
index b3d413f..8b0db17 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -27,30 +27,33 @@
// (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 "build/build_config.h"
+
+#ifdef OS_WIN
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
+#endif
-#include <hash_map>
-#include <hash_set>
-
+#include "base/hash_tables.h"
#include "base/path_service.h"
#include "base/lock.h"
#include "base/logging.h"
#include "base/file_util.h"
+#include "base/string_util.h"
namespace base {
bool PathProvider(int key, std::wstring* result);
-#if OS_WIN
+#ifdef OS_WIN
bool PathProviderWin(int key, std::wstring* result);
#endif
}
namespace {
-typedef stdext::hash_map<int,std::wstring> PathMap;
-typedef stdext::hash_set<int> PathSet;
+typedef base::hash_map<int, std::wstring> PathMap;
+typedef base::hash_set<int> PathSet;
// We keep a linked list of providers. In a debug build we ensure that no two
// providers claim overlapping keys.
@@ -92,9 +95,7 @@ struct PathData {
PathData() {
#if defined(OS_WIN)
providers = &base_provider_win;
-#elif defined(OS_MACOSX)
- providers = &base_provider;
-#elif defined(OS_LINUX)
+#elif defined(OS_POSIX)
providers = &base_provider;
#endif
}
@@ -117,6 +118,7 @@ bool PathService::Get(int key, std::wstring* result) {
// special case the current directory because it can never be cached
if (key == base::DIR_CURRENT) {
+#if defined(OS_WIN)
wchar_t system_buffer[MAX_PATH];
system_buffer[0] = 0;
DWORD len = GetCurrentDirectory(MAX_PATH, system_buffer);
@@ -125,6 +127,13 @@ bool PathService::Get(int key, std::wstring* result) {
*result = system_buffer;
file_util::TrimTrailingSeparator(result);
return true;
+#elif defined(OS_POSIX)
+ char system_buffer[PATH_MAX];
+ system_buffer[0] = 0;
+ getcwd(system_buffer, sizeof(system_buffer));
+ *result = NativeMBToWide(system_buffer);
+ return true;
+#endif
}
// TODO(darin): it would be nice to avoid holding this lock while calling out
@@ -170,10 +179,22 @@ bool PathService::Override(int key, const std::wstring& path) {
DCHECK(path_data);
DCHECK(key > base::DIR_CURRENT) << "invalid path key";
+#if defined(OS_WIN)
wchar_t file_path_buf[MAX_PATH];
if (!_wfullpath(file_path_buf, path.c_str(), MAX_PATH))
return false;
std::wstring file_path(file_path_buf);
+#elif defined(OS_POSIX)
+ // The other (posix-like) platforms don't use wide strings for paths. On the
+ // Mac it's NFD UTF-8, and we have to assume that whatever other platforms
+ // we end up on the native encoding is correct.
+ // TODO: refactor all of the path code throughout the project to use a
+ // per-platform path type
+ char file_path_buf[PATH_MAX];
+ if (!realpath(WideToNativeMB(path).c_str(), file_path_buf))
+ return false;
+ std::wstring file_path(NativeMBToWide(file_path_buf));
+#endif
// make sure the directory exists:
if (!file_util::PathExists(file_path) &&
@@ -190,8 +211,13 @@ bool PathService::Override(int key, const std::wstring& path) {
}
bool PathService::SetCurrentDirectory(const std::wstring& current_directory) {
+#if defined(OS_WIN)
BOOL ret = ::SetCurrentDirectory(current_directory.c_str());
return (ret ? true : false);
+#elif defined(OS_POSIX)
+ int ret = chdir(WideToNativeMB(current_directory).c_str());
+ return (ret == 0);
+#endif
}
void PathService::RegisterProvider(ProviderFunc func, int key_start,