diff options
-rw-r--r-- | base/base.xcodeproj/project.pbxproj | 48 | ||||
-rw-r--r-- | base/file_version_info_mac.mm | 148 | ||||
-rw-r--r-- | base/lock_impl_posix.cc | 9 | ||||
-rw-r--r-- | base/path_service.cc | 42 | ||||
-rw-r--r-- | base/path_service.h | 4 | ||||
-rw-r--r-- | base/path_service_unittest.cc | 4 |
6 files changed, 228 insertions, 27 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj index 83f82cc..14e7d2d 100644 --- a/base/base.xcodeproj/project.pbxproj +++ b/base/base.xcodeproj/project.pbxproj @@ -95,7 +95,6 @@ 829E2FA50DBFD79E00819EBF /* skia_utils_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = 829E2FA30DBFD79E00819EBF /* skia_utils_mac.cc */; }; 829E31340DBFDB6F00819EBF /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 829E31330DBFDB6F00819EBF /* CoreGraphics.framework */; }; 829E35D50DC0DC9400819EBF /* logging.cc in Sources */ = {isa = PBXBuildFile; fileRef = 825403270D92D2090006B936 /* logging.cc */; }; - 829E35D60DC0DC9400819EBF /* logging.h in Headers */ = {isa = PBXBuildFile; fileRef = 825403280D92D2090006B936 /* logging.h */; }; 829E35D60DC0DC9400819EBF /* notimplemented.h in Headers */ = {isa = PBXBuildFile; fileRef = 825403280D92D2090006B936 /* notimplemented.h */; }; 829E35DA0DC0DD0400819EBF /* lock_impl_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BEFC29D0D99832D000829AD /* lock_impl_posix.cc */; }; 829E35DB0DC0DD0500819EBF /* lock_impl.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BEFC29C0D99832D000829AD /* lock_impl.h */; }; @@ -114,10 +113,22 @@ A5A0268E0E4A2BDC00498DA9 /* file_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */; }; A5A0270B0E4A630D00498DA9 /* file_util_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */; }; A5A0276C0E4BA33700498DA9 /* build_config.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A0276B0E4BA33700498DA9 /* build_config.h */; }; + A5A0282E0E4CFA8500498DA9 /* file_util_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0282D0E4CFA8500498DA9 /* file_util_unittest.cc */; }; + A5A028360E4CFBE700498DA9 /* file_version_info_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A028340E4CFBE700498DA9 /* file_version_info_mac.mm */; }; + A5A028370E4CFBE700498DA9 /* file_version_info_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A028350E4CFBE700498DA9 /* file_version_info_unittest.cc */; }; + A5A028380E4CFBE700498DA9 /* file_version_info_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A028340E4CFBE700498DA9 /* file_version_info_mac.mm */; }; + A5A028390E4CFBE700498DA9 /* file_version_info_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A028350E4CFBE700498DA9 /* file_version_info_unittest.cc */; }; + A5A0284D0E4CFD7500498DA9 /* file_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A026540E4A214600498DA9 /* file_util.cc */; }; + A5A0284E0E4CFD7B00498DA9 /* file_util_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */; }; + A5A0284F0E4CFD7E00498DA9 /* file_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */; }; + A5A028510E4CFD9500498DA9 /* path_service.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0261E0E48FF2200498DA9 /* path_service.cc */; }; + A5A028520E4CFDE300498DA9 /* path_service_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = E4562AD60E27E27E005E4685 /* path_service_unittest.cc */; }; + A5A028690E4CFFAB00498DA9 /* base_paths.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A028680E4CFFAB00498DA9 /* base_paths.cc */; }; + A5A0286A0E4CFFAB00498DA9 /* base_paths.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A028680E4CFFAB00498DA9 /* base_paths.cc */; }; + A5A0286B0E4CFFC700498DA9 /* base_paths_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */; }; ABF4B98F0DC2BA6900A6E319 /* base_paths_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */; }; ABF4B99E0DC2BB6000A6E319 /* clipboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B99D0DC2BB6000A6E319 /* clipboard.mm */; }; ABF4B9A70DC2BBAE00A6E319 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 829E31330DBFDB6F00819EBF /* CoreGraphics.framework */; }; - ABF4B9AD0DC2BC4800A6E319 /* file_version_info.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B9AC0DC2BC4800A6E319 /* file_version_info.mm */; }; 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 */; }; @@ -405,7 +416,6 @@ 825403250D92D2090006B936 /* lock.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lock.cc; sourceTree = "<group>"; }; 825403260D92D2090006B936 /* lock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lock.h; sourceTree = "<group>"; }; 825403270D92D2090006B936 /* logging.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = logging.cc; sourceTree = "<group>"; }; - 825403280D92D2090006B936 /* logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = logging.h; sourceTree = "<group>"; }; 825403280D92D2090006B936 /* notimplemented.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = notimplemented.h; sourceTree = "<group>"; }; 825403290D92D2090006B936 /* md5.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = md5.cc; sourceTree = "<group>"; }; 8254032A0D92D2090006B936 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = "<group>"; }; @@ -500,15 +510,17 @@ A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_posix.cc; sourceTree = "<group>"; }; A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = file_util_mac.mm; sourceTree = "<group>"; }; A5A0276B0E4BA33700498DA9 /* build_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = build_config.h; path = ../build/build_config.h; sourceTree = SOURCE_ROOT; }; + A5A0282D0E4CFA8500498DA9 /* file_util_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_unittest.cc; sourceTree = "<group>"; }; + A5A028340E4CFBE700498DA9 /* file_version_info_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = file_version_info_mac.mm; sourceTree = "<group>"; }; + A5A028350E4CFBE700498DA9 /* file_version_info_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_version_info_unittest.cc; sourceTree = "<group>"; }; + A5A028680E4CFFAB00498DA9 /* base_paths.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = base_paths.cc; sourceTree = "<group>"; }; ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = base_paths_mac.mm; sourceTree = "<group>"; }; ABF4B99D0DC2BB6000A6E319 /* clipboard.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard.mm; 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.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service.cc; sourceTree = "<group>"; }; 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>"; }; E4562A2A0E27CA2F005E4685 /* libpng.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libpng.xcodeproj; path = ../third_party/libpng/libpng.xcodeproj; sourceTree = SOURCE_ROOT; }; E4562A3B0E27CAB6005E4685 /* zlib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = zlib.xcodeproj; path = ../third_party/zlib/zlib.xcodeproj; sourceTree = SOURCE_ROOT; }; - E4562AB10E27D8D7005E4685 /* file_version_info_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_version_info_unittest.cc; sourceTree = "<group>"; }; E4562AD60E27E27E005E4685 /* path_service_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service_unittest.cc; sourceTree = "<group>"; }; E4562AF30E27E428005E4685 /* icu.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = icu.xcodeproj; path = ../third_party/icu38/build/icu.xcodeproj; sourceTree = SOURCE_ROOT; }; E4562B200E27E5A2005E4685 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; }; @@ -579,6 +591,7 @@ 825402A80D92D0C60006B936 = { isa = PBXGroup; children = ( + A5A0282D0E4CFA8500498DA9 /* file_util_unittest.cc */, 825402B60D92D0E20006B936 /* base */, 825403B40D92D2EC0006B936 /* base_gfx */, 829E2FA80DBFD7D500819EBF /* Frameworks */, @@ -589,6 +602,9 @@ 825402B60D92D0E20006B936 /* base */ = { isa = PBXGroup; children = ( + A5A028680E4CFFAB00498DA9 /* base_paths.cc */, + A5A028340E4CFBE700498DA9 /* file_version_info_mac.mm */, + A5A028350E4CFBE700498DA9 /* file_version_info_unittest.cc */, A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */, A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */, A5A026540E4A214600498DA9 /* file_util.cc */, @@ -625,9 +641,7 @@ 825402FF0D92D1BC0006B936 /* event_recorder.cc */, 825403000D92D1BC0006B936 /* event_recorder.h */, 825403030D92D1C50006B936 /* file_util.h */, - E4562AB10E27D8D7005E4685 /* file_version_info_unittest.cc */, 825403070D92D1CD0006B936 /* file_version_info.h */, - ABF4B9AC0DC2BC4800A6E319 /* file_version_info.mm */, 8254030B0D92D1D10006B936 /* fix_wp64.h */, 7B4C5D880E4915D800679E8F /* float_util.h */, 824652C00DC12044007C2BAA /* hash_tables.h */, @@ -653,7 +667,7 @@ 7BEFC29C0D99832D000829AD /* lock_impl.h */, 7BEFC29D0D99832D000829AD /* lock_impl_posix.cc */, 825403270D92D2090006B936 /* logging.cc */, - 825403280D92D2090006B936 /* logging.h */, + 825403280D92D2090006B936 /* notimplemented.h */, 825403280D92D2090006B936 /* notimplemented.h */, 825403290D92D2090006B936 /* md5.cc */, 8254032A0D92D2090006B936 /* md5.h */, @@ -873,7 +887,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 829E35D60DC0DC9400819EBF /* logging.h in Headers */, + 829E35D60DC0DC9400819EBF /* notimplemented.h in Headers */, 829E35D60DC0DC9400819EBF /* notimplemented.h in Headers */, 829E35DB0DC0DD0500819EBF /* lock_impl.h in Headers */, 829E36420DC0F69D00819EBF /* string16.h in Headers */, @@ -1144,6 +1158,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ABF4B98F0DC2BA6900A6E319 /* base_paths_mac.mm in Sources */, 829E35D50DC0DC9400819EBF /* logging.cc in Sources */, 829E35DA0DC0DD0400819EBF /* lock_impl_posix.cc in Sources */, 829E36440DC0F69F00819EBF /* string_util_mac.cc in Sources */, @@ -1159,9 +1174,7 @@ 824654A60DC25CD7007C2BAA /* pickle.cc in Sources */, 824654DF0DC26521007C2BAA /* prtime.cc in Sources */, 824655DD0DC659B8007C2BAA /* word_iterator.cc in Sources */, - ABF4B98F0DC2BA6900A6E319 /* base_paths_mac.mm in Sources */, ABF4B99E0DC2BB6000A6E319 /* clipboard.mm in Sources */, - ABF4B9AD0DC2BC4800A6E319 /* file_version_info.mm in Sources */, ABF4B9AF0DC2BC6200A6E319 /* json_reader.cc in Sources */, ABF4B9B00DC2BC6500A6E319 /* json_writer.cc in Sources */, ABF4B9B20DC2BC8300A6E319 /* memory_debug.cc in Sources */, @@ -1190,6 +1203,10 @@ A5A0268E0E4A2BDC00498DA9 /* file_util_posix.cc in Sources */, A5A0270B0E4A630D00498DA9 /* file_util_mac.mm in Sources */, 7B4C5F4A0E4B6BF900679E8F /* sys_string_conversions_mac.cc in Sources */, + A5A0282E0E4CFA8500498DA9 /* file_util_unittest.cc in Sources */, + A5A028360E4CFBE700498DA9 /* file_version_info_mac.mm in Sources */, + A5A028370E4CFBE700498DA9 /* file_version_info_unittest.cc in Sources */, + A5A028690E4CFFAB00498DA9 /* base_paths.cc in Sources */, E49E4C890E4CF56100AD47F7 /* string_tokenizer_unittest.cc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1216,6 +1233,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A5A0286B0E4CFFC700498DA9 /* base_paths_mac.mm in Sources */, + A5A028520E4CFDE300498DA9 /* path_service_unittest.cc in Sources */, + A5A028510E4CFD9500498DA9 /* path_service.cc in Sources */, + A5A0284F0E4CFD7E00498DA9 /* file_util_posix.cc in Sources */, + A5A0284E0E4CFD7B00498DA9 /* file_util_mac.mm in Sources */, + A5A0284D0E4CFD7500498DA9 /* file_util.cc in Sources */, E49F19560E4CBB3100386AEC /* at_exit.cc in Sources */, E49F19580E4CBB3100386AEC /* base_switches.cc in Sources */, E49F195B0E4CBB3100386AEC /* json_reader.cc in Sources */, @@ -1233,6 +1256,9 @@ E49F197C0E4CBDF400386AEC /* stack_container_unittest.cc in Sources */, E49F19A40E4CBFE900386AEC /* sys_string_conversions_mac.cc in Sources */, E49F1A330E4CCCF200386AEC /* command_line.cc in Sources */, + A5A028380E4CFBE700498DA9 /* file_version_info_mac.mm in Sources */, + A5A028390E4CFBE700498DA9 /* file_version_info_unittest.cc in Sources */, + A5A0286A0E4CFFAB00498DA9 /* base_paths.cc in Sources */, E49F1A390E4CCD6400386AEC /* command_line_unittest.cc in Sources */, E49F1A5E0E4CD6E200386AEC /* run_all_unittests.cc in Sources */, E49F1A7B0E4CD99D00386AEC /* icu_util.cc in Sources */, diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm new file mode 100644 index 0000000..a3e3e0c --- /dev/null +++ b/base/file_version_info_mac.mm @@ -0,0 +1,148 @@ +// 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. +// Copied from base/basictypes.h with some modifications + +#import <Cocoa/Cocoa.h> + +#include "base/file_version_info.h" + +#include "base/logging.h" +#include "base/string_util.h" + +FileVersionInfo::FileVersionInfo(const std::wstring& file_path, NSBundle *bundle) + : file_path_(file_path), bundle_(bundle) { + if (!bundle_) { + NSString* path = [[NSString alloc] + initWithCString:reinterpret_cast<const char*>(file_path_.c_str()) + encoding:NSUTF32StringEncoding]; + bundle_ = [NSBundle bundleWithPath: path]; + } +} + +FileVersionInfo::~FileVersionInfo() { + +} + +// static +FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() { + NSBundle* bundle = [NSBundle mainBundle]; + return new FileVersionInfo(L"", bundle); +} + +// static +FileVersionInfo* FileVersionInfo::CreateFileVersionInfo( + const std::wstring& file_path) { + return new FileVersionInfo(file_path, nil); +} + +std::wstring FileVersionInfo::company_name() { + return L""; +} + +std::wstring FileVersionInfo::company_short_name() { + return L""; +} + +std::wstring FileVersionInfo::internal_name() { + return L""; +} + +std::wstring FileVersionInfo::product_name() { + return GetStringValue(L"CFBundleName"); +} + +std::wstring FileVersionInfo::product_short_name() { + return GetStringValue(L"CFBundleName"); +} + +std::wstring FileVersionInfo::comments() { + return L""; +} + +std::wstring FileVersionInfo::legal_copyright() { + return GetStringValue(L"CFBundleGetInfoString"); +} + +std::wstring FileVersionInfo::product_version() { + return GetStringValue(L"CFBundleShortVersionString"); +} + +std::wstring FileVersionInfo::file_description() { + return L""; +} + +std::wstring FileVersionInfo::legal_trademarks() { + return L""; +} + +std::wstring FileVersionInfo::private_build() { + return L""; +} + +std::wstring FileVersionInfo::file_version() { + return GetStringValue(L"CFBundleVersion"); +} + +std::wstring FileVersionInfo::original_filename() { + return GetStringValue(L"CFBundleName"); +} + +std::wstring FileVersionInfo::special_build() { + return L""; +} + +std::wstring FileVersionInfo::last_change() { + return L""; +} + +bool FileVersionInfo::is_official_build() { + return false; +} + +bool FileVersionInfo::GetValue(const wchar_t* name, std::wstring* value_str) { + std::wstring str; + if (bundle_) { + NSString* value = [bundle_ objectForInfoDictionaryKey: + [NSString stringWithUTF8String:WideToUTF8(name).c_str()]]; + if (value) { + *value_str = reinterpret_cast<const wchar_t*>( + [value cStringUsingEncoding:NSUTF32StringEncoding]); + return true; + } + } + return false; +} + +std::wstring FileVersionInfo::GetStringValue(const wchar_t* name) { + std::wstring str; + if (GetValue(name, &str)) + return str; + return L""; +} + diff --git a/base/lock_impl_posix.cc b/base/lock_impl_posix.cc index aceb414..20cd894 100644 --- a/base/lock_impl_posix.cc +++ b/base/lock_impl_posix.cc @@ -34,7 +34,14 @@ #include "base/logging.h" LockImpl::LockImpl() { - int rv = pthread_mutex_init(&os_lock_, NULL); + pthread_mutexattr_t mta; + int rv = pthread_mutexattr_init(&mta); + DCHECK(rv == 0); + //rv = pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); + DCHECK(rv == 0); + rv = pthread_mutex_init(&os_lock_, &mta); + DCHECK(rv == 0); + rv = pthread_mutexattr_destroy(&mta); DCHECK(rv == 0); } diff --git a/base/path_service.cc b/base/path_service.cc index 8205b03..1601513 100644 --- a/base/path_service.cc +++ b/base/path_service.cc @@ -121,6 +121,25 @@ PathData* path_data = new PathData(); } // namespace + +bool PathService::GetFromCache(int key, std::wstring* result) { + AutoLock scoped_lock(path_data->lock); + + // check for a cached version + PathMap::const_iterator it = path_data->cache.find(key); + if (it != path_data->cache.end()) { + *result = it->second; + return true; + } + return false; +} + +void PathService::AddToCache(int key, const std::wstring& path) { + AutoLock scoped_lock(path_data->lock); + // Save the computed path in our cache. + path_data->cache[key] = path; +} + // TODO(brettw): this function does not handle long paths (filename > MAX_PATH) // characters). This isn't supported very well by Windows right now, so it is // moot, but we should keep this in mind for the future. @@ -134,20 +153,14 @@ bool PathService::Get(int key, std::wstring* result) { if (key == base::DIR_CURRENT) return file_util::GetCurrentDirectory(result); - // TODO(darin): it would be nice to avoid holding this lock while calling out - // to the path providers. - AutoLock scoped_lock(path_data->lock); - - // check for a cached version - PathMap::const_iterator it = path_data->cache.find(key); - if (it != path_data->cache.end()) { - *result = it->second; + if (GetFromCache(key, result)) return true; - } - + std::wstring path; // search providers for the requested path + // NOTE: it should be safe to iterate here without the lock + // since RegisterProvider always prepends. Provider* provider = path_data->providers; while (provider) { if (provider->func(key, &path)) @@ -159,9 +172,8 @@ bool PathService::Get(int key, std::wstring* result) { if (path.empty()) return false; - // Save the computed path in our cache. - path_data->cache[key] = path; - + AddToCache(key, path); + result->swap(path); return true; } @@ -190,9 +202,9 @@ bool PathService::Override(int key, const std::wstring& path) { // 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)) + if (!realpath(WideToUTF8(path).c_str(), file_path_buf)) return false; - std::wstring file_path(NativeMBToWide(file_path_buf)); + std::wstring file_path(UTF8ToWide(file_path_buf)); #endif // make sure the directory exists: diff --git a/base/path_service.h b/base/path_service.h index e018516..bc21e33 100644 --- a/base/path_service.h +++ b/base/path_service.h @@ -90,6 +90,10 @@ class PathService { static void RegisterProvider(ProviderFunc provider, int key_start, int key_end); +private: + static bool GetFromCache(int key, std::wstring* path); + static void AddToCache(int key, const std::wstring& path); + }; #endif // BASE_PATH_SERVICE_H__ diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc index b75ab7e..970ea0c 100644 --- a/base/path_service_unittest.cc +++ b/base/path_service_unittest.cc @@ -31,7 +31,9 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#if defined(OS_WIN) #include "base/win_util.h" +#endif #include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest-spi.h" @@ -45,12 +47,14 @@ bool ReturnsValidPath(int dir_type) { return result && !path.empty() && file_util::PathExists(path); } +#if defined(OS_WIN) // Function to test DIR_LOCAL_APP_DATA_LOW on Windows XP. Make sure it fails. bool ReturnsInvalidPath(int dir_type) { std::wstring path; bool result = PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &path); return !result && path.empty(); } +#endif } // namespace |