summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.xcodeproj/project.pbxproj10
-rw-r--r--base/base_lib.scons1
-rw-r--r--base/base_paths_mac.mm22
-rw-r--r--base/base_unittests.scons1
-rw-r--r--base/mac_util.h19
-rw-r--r--base/mac_util.mm26
-rw-r--r--base/mac_util_unittest.cc20
7 files changed, 88 insertions, 11 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index 85bd3df..2c54bea 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -114,6 +114,8 @@
820EB4FA0E3A6178009668FC /* string_util_icu.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4F90E3A6178009668FC /* string_util_icu.cc */; };
820EB5020E3A618B009668FC /* tracked.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4FE0E3A618B009668FC /* tracked.cc */; };
820EB5480E3A64D2009668FC /* tracked_objects.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4FB0E3A618B009668FC /* tracked_objects.cc */; };
+ 8216794D0EEDC1D8004E561E /* mac_util.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8216794B0EEDC1D8004E561E /* mac_util.mm */; };
+ 8216795B0EEDC5EB004E561E /* mac_util_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8216795A0EEDC5EB004E561E /* mac_util_unittest.cc */; };
8216A5060E34DBDD00EE374C /* icu_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403110D92D1E80006B936 /* icu_util.cc */; };
824653450DC1230B007C2BAA /* lock.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403250D92D2090006B936 /* lock.cc */; };
824653680DC12CEC007C2BAA /* condition_variable_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 824653670DC12CEC007C2BAA /* condition_variable_posix.cc */; };
@@ -464,6 +466,9 @@
820EB4FE0E3A618B009668FC /* tracked.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tracked.cc; sourceTree = "<group>"; };
820EB5030E3A61A1009668FC /* watchdog.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = watchdog.cc; sourceTree = "<group>"; };
820EB5040E3A61A1009668FC /* watchdog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = watchdog.h; sourceTree = "<group>"; };
+ 8216794B0EEDC1D8004E561E /* mac_util.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mac_util.mm; sourceTree = "<group>"; };
+ 8216794C0EEDC1D8004E561E /* mac_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mac_util.h; sourceTree = "<group>"; };
+ 8216795A0EEDC5EB004E561E /* mac_util_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mac_util_unittest.cc; sourceTree = "<group>"; };
821B91680DAABD7F00F350D7 /* string16.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = string16.h; sourceTree = "<group>"; };
824652C00DC12044007C2BAA /* hash_tables.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hash_tables.h; sourceTree = "<group>"; };
824653670DC12CEC007C2BAA /* condition_variable_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = condition_variable_posix.cc; sourceTree = "<group>"; };
@@ -886,6 +891,9 @@
7BEFC29D0D99832D000829AD /* lock_impl_posix.cc */,
825403270D92D2090006B936 /* logging.cc */,
7BAF4F7B0E50A3BD00CA8A07 /* logging.h */,
+ 8216794C0EEDC1D8004E561E /* mac_util.h */,
+ 8216794B0EEDC1D8004E561E /* mac_util.mm */,
+ 8216795A0EEDC5EB004E561E /* mac_util_unittest.cc */,
825403290D92D2090006B936 /* md5.cc */,
8254032A0D92D2090006B936 /* md5.h */,
8254032B0D92D2090006B936 /* memory_debug.cc */,
@@ -1349,6 +1357,7 @@
824653450DC1230B007C2BAA /* lock.cc in Sources */,
829E35DA0DC0DD0400819EBF /* lock_impl_posix.cc in Sources */,
829E35D50DC0DC9400819EBF /* logging.cc in Sources */,
+ 8216794D0EEDC1D8004E561E /* mac_util.mm in Sources */,
ABFBD3E60DC793C600E164CB /* md5.cc in Sources */,
ABF4B9B20DC2BC8300A6E319 /* memory_debug.cc in Sources */,
93611AE10E5A7FE200F9405D /* message_loop.cc in Sources */,
@@ -1434,6 +1443,7 @@
7B78D3930E54FE0100609465 /* json_writer_unittest.cc in Sources */,
7BF892E00E758883000BAF8A /* lazy_instance_unittest.cc in Sources */,
7B78D3940E54FE0100609465 /* linked_ptr_unittest.cc in Sources */,
+ 8216795B0EEDC5EB004E561E /* mac_util_unittest.cc in Sources */,
93611AE80E5A803700F9405D /* message_loop_unittest.cc in Sources */,
7B78D3950E54FE0100609465 /* observer_list_unittest.cc in Sources */,
7B78D3960E54FE0100609465 /* path_service_unittest.cc in Sources */,
diff --git a/base/base_lib.scons b/base/base_lib.scons
index 5552c54..8f8fd0c 100644
--- a/base/base_lib.scons
+++ b/base/base_lib.scons
@@ -186,6 +186,7 @@ if env['PLATFORM'] == 'darwin':
'file_util_mac.mm',
'file_version_info_mac.mm',
'hmac_mac.cc',
+ 'mac_util.mm',
'message_pump_mac.mm',
'platform_thread_mac.mm',
'scoped_nsautorelease_pool.mm',
diff --git a/base/base_paths_mac.mm b/base/base_paths_mac.mm
index cd96e5b..394a588 100644
--- a/base/base_paths_mac.mm
+++ b/base/base_paths_mac.mm
@@ -15,13 +15,12 @@
namespace base {
bool PathProviderMac(int key, FilePath* result) {
- std::wstring cur;
+ std::string cur;
switch (key) {
case base::FILE_EXE:
case base::FILE_MODULE: {
NSString* path = [[NSBundle mainBundle] executablePath];
- cur = reinterpret_cast<const wchar_t*>(
- [path cStringUsingEncoding:NSUTF32StringEncoding]);
+ cur = [path fileSystemRepresentation];
break;
}
case base::DIR_APP_DATA:
@@ -35,22 +34,23 @@ bool PathProviderMac(int key, FilePath* result) {
DCHECK([dirs count] == 1);
NSString* tail = [[NSString alloc] initWithCString:"Google/Chrome"];
NSString* path = [[dirs lastObject] stringByAppendingPathComponent:tail];
- cur = reinterpret_cast<const wchar_t*>(
- [path cStringUsingEncoding:NSUTF32StringEncoding]);
+ cur = [path fileSystemRepresentation];
break;
}
- case base::DIR_SOURCE_ROOT:
+ case base::DIR_SOURCE_ROOT: {
+ FilePath path;
// On the mac, unit tests execute two levels deep from the source root.
// For example: src/xcodebuild/{Debug|Release}/base_unittests
- PathService::Get(base::DIR_EXE, &cur);
- file_util::UpOneDirectory(&cur);
- file_util::UpOneDirectory(&cur);
- break;
+ PathService::Get(base::DIR_EXE, &path);
+ path = path.DirName();
+ *result = path.DirName();
+ return true;
+ }
default:
return false;
}
- *result = FilePath::FromWStringHack(cur);
+ *result = FilePath(cur);
return true;
}
diff --git a/base/base_unittests.scons b/base/base_unittests.scons
index 1ba4ec6..169d8ebb 100644
--- a/base/base_unittests.scons
+++ b/base/base_unittests.scons
@@ -138,6 +138,7 @@ if env['PLATFORM'] == 'win32':
if env['PLATFORM'] == 'darwin':
# Mac-specific tests.
input_files.extend([
+ 'mac_util_unittest.cc',
'platform_test_mac.mm',
])
diff --git a/base/mac_util.h b/base/mac_util.h
new file mode 100644
index 0000000..47ec6b6
--- /dev/null
+++ b/base/mac_util.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MAC_UTIL_H_
+#define BASE_MAC_UTIL_H_
+
+struct FSRef;
+
+#include <string>
+
+namespace mac_util {
+
+std::string PathFromFSRef(const FSRef& ref);
+bool FSRefFromPath(const std::string& path, FSRef* ref);
+
+} // namespace mac_util
+
+#endif // BASE_MAC_UTIL_H_
diff --git a/base/mac_util.mm b/base/mac_util.mm
new file mode 100644
index 0000000..1f92e62
--- /dev/null
+++ b/base/mac_util.mm
@@ -0,0 +1,26 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac_util.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/scoped_cftyperef.h"
+
+namespace mac_util {
+
+std::string PathFromFSRef(const FSRef& ref) {
+ scoped_cftyperef<CFURLRef> url(
+ CFURLCreateFromFSRef(kCFAllocatorDefault, &ref));
+ NSString *path_string = [(NSURL *)url.get() path];
+ return [path_string fileSystemRepresentation];
+}
+
+bool FSRefFromPath(const std::string& path, FSRef* ref) {
+ OSStatus status = FSPathMakeRef((const UInt8*)path.c_str(),
+ ref, nil);
+ return status == noErr;
+}
+
+} // namespace mac_util
diff --git a/base/mac_util_unittest.cc b/base/mac_util_unittest.cc
new file mode 100644
index 0000000..03a90e9
--- /dev/null
+++ b/base/mac_util_unittest.cc
@@ -0,0 +1,20 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac_util.h"
+
+#include <ApplicationServices/ApplicationServices.h>
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+typedef PlatformTest MacUtilTest;
+
+TEST_F(MacUtilTest, TestFSRef) {
+ FSRef ref;
+ std::string path("/System/Library");
+
+ ASSERT_TRUE(mac_util::FSRefFromPath(path, &ref));
+ EXPECT_EQ(path, mac_util::PathFromFSRef(ref));
+}