summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 00:31:30 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 00:31:30 +0000
commitd9cb161850584e5d277b141aadb68abec0af28bb (patch)
tree52cdb82bc14b488f7c93edcaa018550fcd8c9cc3 /base
parent92f132ae9e06a0f55d65b44a324ac74b53a2945d (diff)
downloadchromium_src-d9cb161850584e5d277b141aadb68abec0af28bb.zip
chromium_src-d9cb161850584e5d277b141aadb68abec0af28bb.tar.gz
chromium_src-d9cb161850584e5d277b141aadb68abec0af28bb.tar.bz2
file_version_info was not finding Mac values correctly.
Changed file_version_info to find Mac values, and changed version_info to fail if values can't be found. BUG=NONE TEST=BUILD Review URL: http://codereview.chromium.org/5815001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69592 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_version_info.h5
-rw-r--r--base/file_version_info_mac.h15
-rw-r--r--base/file_version_info_mac.mm68
3 files changed, 34 insertions, 54 deletions
diff --git a/base/file_version_info.h b/base/file_version_info.h
index 19407d2..41a97fa 100644
--- a/base/file_version_info.h
+++ b/base/file_version_info.h
@@ -24,10 +24,13 @@ class FileVersionInfo {
// goes wrong (typically the file does not exit or cannot be opened). The
// returned object should be deleted when you are done with it.
static FileVersionInfo* CreateFileVersionInfo(const FilePath& file_path);
+#endif // OS_WIN || OS_MACOSX
+
+#if defined(OS_WIN)
// This version, taking a wstring, is deprecated and only kept around
// until we can fix all callers.
static FileVersionInfo* CreateFileVersionInfo(const std::wstring& file_path);
-#endif
+#endif // OS_WIN
// Creates a FileVersionInfo for the current module. Returns NULL in case
// of error. The returned object should be deleted when you are done with it.
diff --git a/base/file_version_info_mac.h b/base/file_version_info_mac.h
index d66c4e6..36cb538 100644
--- a/base/file_version_info_mac.h
+++ b/base/file_version_info_mac.h
@@ -8,9 +8,8 @@
#include <string>
-#include "base/basictypes.h"
#include "base/file_version_info.h"
-#include "base/scoped_ptr.h"
+#include "base/scoped_nsobject.h"
#ifdef __OBJC__
@class NSBundle;
@@ -25,7 +24,6 @@ class NSBundle;
class FileVersionInfoMac : public FileVersionInfo {
public:
explicit FileVersionInfoMac(NSBundle *bundle);
- ~FileVersionInfoMac();
// Accessors to the different version properties.
// Returns an empty string if the property is not found.
@@ -47,14 +45,13 @@ class FileVersionInfoMac : public FileVersionInfo {
virtual bool is_official_build();
private:
- // Lets you access other properties not covered above.
- bool GetValue(const wchar_t* name, std::wstring* value);
- // Similar to GetValue but returns a wstring (empty string if the property
- // does not exist).
- std::wstring GetStringValue(const wchar_t* name);
- NSBundle *bundle_;
+ // Returns a wstring value for a property name.
+ // Returns the empty string if the property does not exist.
+ std::wstring GetWStringValue(CFStringRef name);
+
+ scoped_nsobject<NSBundle> bundle_;
DISALLOW_COPY_AND_ASSIGN(FileVersionInfoMac);
};
diff --git a/base/file_version_info_mac.mm b/base/file_version_info_mac.mm
index 57be79a..7b1ac54 100644
--- a/base/file_version_info_mac.mm
+++ b/base/file_version_info_mac.mm
@@ -4,43 +4,33 @@
#include "base/file_version_info_mac.h"
-#import <Cocoa/Cocoa.h>
+#import <Foundation/Foundation.h>
-#include "base/basictypes.h"
#include "base/file_path.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+#include "base/mac_util.h"
FileVersionInfoMac::FileVersionInfoMac(NSBundle *bundle) : bundle_(bundle) {
- [bundle_ retain];
-}
-
-FileVersionInfoMac::~FileVersionInfoMac() {
- [bundle_ release];
}
// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
- // TODO(erikkay): this should really use bundleForClass, but we don't have
- // a class to hang onto yet.
- NSBundle* bundle = [NSBundle mainBundle];
- return new FileVersionInfoMac(bundle);
-}
-
-// static
-FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
- const std::wstring& file_path) {
- NSString* path = [NSString stringWithCString:
- reinterpret_cast<const char*>(file_path.c_str())
- encoding:NSUTF32StringEncoding];
- return new FileVersionInfoMac([NSBundle bundleWithPath:path]);
+ return CreateFileVersionInfo(mac_util::MainAppBundlePath());
}
// static
FileVersionInfo* FileVersionInfo::CreateFileVersionInfo(
const FilePath& file_path) {
- NSString* path = [NSString stringWithUTF8String:file_path.value().c_str()];
- return new FileVersionInfoMac([NSBundle bundleWithPath:path]);
+ NSString* path = base::SysUTF8ToNSString(file_path.value());
+ NSBundle *bundle = [NSBundle bundleWithPath:path];
+ NSString *identifier = [bundle bundleIdentifier];
+ if (!identifier) {
+ NOTREACHED() << "Unable to create file version for " << file_path.value();
+ return NULL;
+ } else {
+ return new FileVersionInfoMac(bundle);
+ }
}
std::wstring FileVersionInfoMac::company_name() {
@@ -56,11 +46,11 @@ std::wstring FileVersionInfoMac::internal_name() {
}
std::wstring FileVersionInfoMac::product_name() {
- return GetStringValue(L"CFBundleName");
+ return GetWStringValue(kCFBundleNameKey);
}
std::wstring FileVersionInfoMac::product_short_name() {
- return GetStringValue(L"CFBundleName");
+ return GetWStringValue(kCFBundleNameKey);
}
std::wstring FileVersionInfoMac::comments() {
@@ -68,11 +58,11 @@ std::wstring FileVersionInfoMac::comments() {
}
std::wstring FileVersionInfoMac::legal_copyright() {
- return GetStringValue(L"CFBundleGetInfoString");
+ return GetWStringValue(CFSTR("CFBundleGetInfoString"));
}
std::wstring FileVersionInfoMac::product_version() {
- return GetStringValue(L"CFBundleShortVersionString");
+ return GetWStringValue(CFSTR("CFBundleShortVersionString"));
}
std::wstring FileVersionInfoMac::file_description() {
@@ -92,7 +82,7 @@ std::wstring FileVersionInfoMac::file_version() {
}
std::wstring FileVersionInfoMac::original_filename() {
- return GetStringValue(L"CFBundleName");
+ return GetWStringValue(kCFBundleNameKey);
}
std::wstring FileVersionInfoMac::special_build() {
@@ -100,7 +90,7 @@ std::wstring FileVersionInfoMac::special_build() {
}
std::wstring FileVersionInfoMac::last_change() {
- return GetStringValue(L"SVNRevision");
+ return GetWStringValue(CFSTR("SVNRevision"));
}
bool FileVersionInfoMac::is_official_build() {
@@ -111,23 +101,13 @@ bool FileVersionInfoMac::is_official_build() {
#endif
}
-bool FileVersionInfoMac::GetValue(const wchar_t* name,
- std::wstring* value_str) {
+std::wstring FileVersionInfoMac::GetWStringValue(CFStringRef name) {
if (bundle_) {
- NSString* value = [bundle_ objectForInfoDictionaryKey:
- [NSString stringWithUTF8String:WideToUTF8(name).c_str()]];
+ NSString *ns_name = mac_util::CFToNSCast(name);
+ NSString* value = [bundle_ objectForInfoDictionaryKey:ns_name];
if (value) {
- *value_str = reinterpret_cast<const wchar_t*>(
- [value cStringUsingEncoding:NSUTF32StringEncoding]);
- return true;
+ return base::SysNSStringToWide(value);
}
}
- return false;
-}
-
-std::wstring FileVersionInfoMac::GetStringValue(const wchar_t* name) {
- std::wstring str;
- if (GetValue(name, &str))
- return str;
return std::wstring();
}