summaryrefslogtreecommitdiffstats
path: root/base/mac
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-28 16:47:53 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-28 16:47:53 +0000
commitc0a5c49d0214cf5cff4bfb7befd96384aedfce36 (patch)
treed9b4029774c0c05bd73dcfaee416bf1043e9465a /base/mac
parent1f094b3ad544437ec1446d9f951ebbcee8f44365 (diff)
downloadchromium_src-c0a5c49d0214cf5cff4bfb7befd96384aedfce36.zip
chromium_src-c0a5c49d0214cf5cff4bfb7befd96384aedfce36.tar.gz
chromium_src-c0a5c49d0214cf5cff4bfb7befd96384aedfce36.tar.bz2
Move some mac_util functions into foundation_util.
BUG=None TEST=None Review URL: http://codereview.chromium.org/6278018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72966 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac')
-rw-r--r--base/mac/foundation_util.h104
-rw-r--r--base/mac/foundation_util.mm227
-rw-r--r--base/mac/mac_util.h87
-rw-r--r--base/mac/mac_util.mm213
4 files changed, 338 insertions, 293 deletions
diff --git a/base/mac/foundation_util.h b/base/mac/foundation_util.h
new file mode 100644
index 0000000..a94cf95
--- /dev/null
+++ b/base/mac/foundation_util.h
@@ -0,0 +1,104 @@
+// Copyright (c) 2011 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_FOUNDATION_UTIL_H_
+#define BASE_MAC_FOUNDATION_UTIL_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/logging.h"
+
+#if defined(__OBJC__)
+#import <Foundation/Foundation.h>
+@class NSBundle;
+#else // __OBJC__
+class NSBundle;
+#endif // __OBJC__
+
+class FilePath;
+
+// Adapted from NSPathUtilities.h and NSObjCRuntime.h.
+#if __LP64__ || NS_BUILD_32_LIKE_64
+typedef unsigned long NSSearchPathDirectory;
+typedef unsigned long NSSearchPathDomainMask;
+#else
+typedef unsigned int NSSearchPathDirectory;
+typedef unsigned int NSSearchPathDomainMask;
+#endif
+
+namespace base {
+namespace mac {
+
+// Returns true if the application is running from a bundle
+bool AmIBundled();
+void SetOverrideAmIBundled(bool value);
+
+// Returns true if this process is marked as a "Background only process".
+bool IsBackgroundOnlyProcess();
+
+// Returns the main bundle or the override, used for code that needs
+// to fetch resources from bundles, but work within a unittest where we
+// aren't a bundle.
+NSBundle* MainAppBundle();
+FilePath MainAppBundlePath();
+
+// Set the bundle that MainAppBundle will return, overriding the default value
+// (Restore the default by calling SetOverrideAppBundle(nil)).
+void SetOverrideAppBundle(NSBundle* bundle);
+void SetOverrideAppBundlePath(const FilePath& file_path);
+
+// Returns the creator code associated with the CFBundleRef at bundle.
+OSType CreatorCodeForCFBundleRef(CFBundleRef bundle);
+
+// Returns the creator code associated with this application, by calling
+// CreatorCodeForCFBundleRef for the application's main bundle. If this
+// information cannot be determined, returns kUnknownType ('????'). This
+// does not respect the override app bundle because it's based on CFBundle
+// instead of NSBundle, and because callers probably don't want the override
+// app bundle's creator code anyway.
+OSType CreatorCodeForApplication();
+
+// Searches for directories for the given key in only the given |domain_mask|.
+// If found, fills result (which must always be non-NULL) with the
+// first found directory and returns true. Otherwise, returns false.
+bool GetSearchPathDirectory(NSSearchPathDirectory directory,
+ NSSearchPathDomainMask domain_mask,
+ FilePath* result);
+
+// Searches for directories for the given key in only the local domain.
+// If found, fills result (which must always be non-NULL) with the
+// first found directory and returns true. Otherwise, returns false.
+bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result);
+
+// Searches for directories for the given key in only the user domain.
+// If found, fills result (which must always be non-NULL) with the
+// first found directory and returns true. Otherwise, returns false.
+bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result);
+
+// Returns the ~/Library directory.
+FilePath GetUserLibraryPath();
+
+// Takes a path to an (executable) binary and tries to provide the path to an
+// application bundle containing it. It takes the outermost bundle that it can
+// find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app").
+// |exec_name| - path to the binary
+// returns - path to the application bundle, or empty on error
+FilePath GetAppBundlePath(const FilePath& exec_name);
+
+// Utility function to pull out a value from a dictionary, check its type, and
+// return it. Returns NULL if the key is not present or of the wrong type.
+CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
+ CFStringRef key,
+ CFTypeID expected_type);
+
+// Retain/release calls for memory management in C++.
+void NSObjectRetain(void* obj);
+void NSObjectRelease(void* obj);
+
+} // namespace mac
+} // namespace base
+
+#endif // BASE_MAC_FOUNDATION_UTIL_H_
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
new file mode 100644
index 0000000..ad8a247
--- /dev/null
+++ b/base/mac/foundation_util.mm
@@ -0,0 +1,227 @@
+// Copyright (c) 2011 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/foundation_util.h"
+
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "base/mac/scoped_cftyperef.h"
+#include "base/sys_string_conversions.h"
+
+namespace base {
+namespace mac {
+
+static bool g_override_am_i_bundled = false;
+static bool g_override_am_i_bundled_value = false;
+
+// Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
+static bool UncachedAmIBundled() {
+ if (g_override_am_i_bundled)
+ return g_override_am_i_bundled_value;
+
+ ProcessSerialNumber psn = {0, kCurrentProcess};
+
+ FSRef fsref;
+ OSStatus pbErr;
+ if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) {
+ LOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr;
+ return false;
+ }
+
+ FSCatalogInfo info;
+ OSErr fsErr;
+ if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
+ NULL, NULL, NULL)) != noErr) {
+ LOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr;
+ return false;
+ }
+
+ return info.nodeFlags & kFSNodeIsDirectoryMask;
+}
+
+bool AmIBundled() {
+ // If the return value is not cached, this function will return different
+ // values depending on when it's called. This confuses some client code, see
+ // http://crbug.com/63183 .
+ static bool result = UncachedAmIBundled();
+ DCHECK_EQ(result, UncachedAmIBundled())
+ << "The return value of AmIBundled() changed. This will confuse tests. "
+ << "Call SetAmIBundled() override manually if your test binary "
+ << "delay-loads the framework.";
+ return result;
+}
+
+void SetOverrideAmIBundled(bool value) {
+ g_override_am_i_bundled = true;
+ g_override_am_i_bundled_value = value;
+}
+
+bool IsBackgroundOnlyProcess() {
+ // This function really does want to examine NSBundle's idea of the main
+ // bundle dictionary, and not the overriden MainAppBundle. It needs to look
+ // at the actual running .app's Info.plist to access its LSUIElement
+ // property.
+ NSDictionary* info_dictionary = [[NSBundle mainBundle] infoDictionary];
+ return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO;
+}
+
+// No threading worries since NSBundle isn't thread safe.
+static NSBundle* g_override_app_bundle = nil;
+
+NSBundle* MainAppBundle() {
+ if (g_override_app_bundle)
+ return g_override_app_bundle;
+ return [NSBundle mainBundle];
+}
+
+FilePath MainAppBundlePath() {
+ NSBundle* bundle = MainAppBundle();
+ return FilePath([[bundle bundlePath] fileSystemRepresentation]);
+}
+
+void SetOverrideAppBundle(NSBundle* bundle) {
+ if (bundle != g_override_app_bundle) {
+ [g_override_app_bundle release];
+ g_override_app_bundle = [bundle retain];
+ }
+}
+
+void SetOverrideAppBundlePath(const FilePath& file_path) {
+ NSString* path = base::SysUTF8ToNSString(file_path.value());
+ NSBundle* bundle = [NSBundle bundleWithPath:path];
+ CHECK(bundle) << "Failed to load the bundle at " << file_path.value();
+
+ SetOverrideAppBundle(bundle);
+}
+
+OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) {
+ OSType creator = kUnknownType;
+ CFBundleGetPackageInfo(bundle, NULL, &creator);
+ return creator;
+}
+
+OSType CreatorCodeForApplication() {
+ CFBundleRef bundle = CFBundleGetMainBundle();
+ if (!bundle)
+ return kUnknownType;
+
+ return CreatorCodeForCFBundleRef(bundle);
+}
+
+bool GetSearchPathDirectory(NSSearchPathDirectory directory,
+ NSSearchPathDomainMask domain_mask,
+ FilePath* result) {
+ DCHECK(result);
+ NSArray* dirs =
+ NSSearchPathForDirectoriesInDomains(directory, domain_mask, YES);
+ if ([dirs count] < 1) {
+ return false;
+ }
+ NSString* path = [dirs objectAtIndex:0];
+ *result = FilePath([path fileSystemRepresentation]);
+ return true;
+}
+
+bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) {
+ return GetSearchPathDirectory(directory, NSLocalDomainMask, result);
+}
+
+bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) {
+ return GetSearchPathDirectory(directory, NSUserDomainMask, result);
+}
+
+FilePath GetUserLibraryPath() {
+ FilePath user_library_path;
+ if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) {
+ LOG(WARNING) << "Could not get user library path";
+ }
+ return user_library_path;
+}
+
+// Takes a path to an (executable) binary and tries to provide the path to an
+// application bundle containing it. It takes the outermost bundle that it can
+// find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app").
+// |exec_name| - path to the binary
+// returns - path to the application bundle, or empty on error
+FilePath GetAppBundlePath(const FilePath& exec_name) {
+ const char kExt[] = ".app";
+ const size_t kExtLength = arraysize(kExt) - 1;
+
+ // Split the path into components.
+ std::vector<std::string> components;
+ exec_name.GetComponents(&components);
+
+ // It's an error if we don't get any components.
+ if (!components.size())
+ return FilePath();
+
+ // Don't prepend '/' to the first component.
+ std::vector<std::string>::const_iterator it = components.begin();
+ std::string bundle_name = *it;
+ DCHECK(it->length() > 0);
+ // If the first component ends in ".app", we're already done.
+ if (it->length() > kExtLength &&
+ !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
+ return FilePath(bundle_name);
+
+ // The first component may be "/" or "//", etc. Only append '/' if it doesn't
+ // already end in '/'.
+ if (bundle_name[bundle_name.length() - 1] != '/')
+ bundle_name += '/';
+
+ // Go through the remaining components.
+ for (++it; it != components.end(); ++it) {
+ DCHECK(it->length() > 0);
+
+ bundle_name += *it;
+
+ // If the current component ends in ".app", we're done.
+ if (it->length() > kExtLength &&
+ !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
+ return FilePath(bundle_name);
+
+ // Separate this component from the next one.
+ bundle_name += '/';
+ }
+
+ return FilePath();
+}
+
+CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
+ CFStringRef key,
+ CFTypeID expected_type) {
+ CFTypeRef value = CFDictionaryGetValue(dict, key);
+ if (!value)
+ return value;
+
+ if (CFGetTypeID(value) != expected_type) {
+ ScopedCFTypeRef<CFStringRef> expected_type_ref(
+ CFCopyTypeIDDescription(expected_type));
+ ScopedCFTypeRef<CFStringRef> actual_type_ref(
+ CFCopyTypeIDDescription(CFGetTypeID(value)));
+ LOG(WARNING) << "Expected value for key "
+ << base::SysCFStringRefToUTF8(key)
+ << " to be "
+ << base::SysCFStringRefToUTF8(expected_type_ref)
+ << " but it was "
+ << base::SysCFStringRefToUTF8(actual_type_ref)
+ << " instead";
+ return NULL;
+ }
+
+ return value;
+}
+
+void NSObjectRetain(void* obj) {
+ id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
+ [nsobj retain];
+}
+
+void NSObjectRelease(void* obj) {
+ id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
+ [nsobj release];
+}
+
+} // namespace mac
+} // namespace base
diff --git a/base/mac/mac_util.h b/base/mac/mac_util.h
index 7e5dddb..968756a 100644
--- a/base/mac/mac_util.h
+++ b/base/mac/mac_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -12,28 +12,19 @@
#include "base/logging.h"
+// TODO(rohitrao): Clean up sites that include mac_util.h and remove this line.
+#include "base/mac/foundation_util.h"
+
#if defined(__OBJC__)
#import <Foundation/Foundation.h>
-
-@class NSBundle;
@class NSWindow;
#else // __OBJC__
-class NSBundle;
class NSImage;
class NSWindow;
#endif // __OBJC__
class FilePath;
-// Adapted from NSPathUtilities.h and NSObjCRuntime.h.
-#if __LP64__ || NS_BUILD_32_LIKE_64
-typedef unsigned long NSSearchPathDirectory;
-typedef unsigned long NSSearchPathDomainMask;
-#else
-typedef unsigned int NSSearchPathDirectory;
-typedef unsigned int NSSearchPathDomainMask;
-#endif
-
namespace base {
namespace mac {
@@ -53,55 +44,6 @@ enum FullScreenMode {
std::string PathFromFSRef(const FSRef& ref);
bool FSRefFromPath(const std::string& path, FSRef* ref);
-// Returns true if the application is running from a bundle
-bool AmIBundled();
-void SetOverrideAmIBundled(bool value);
-
-// Returns true if this process is marked as a "Background only process".
-bool IsBackgroundOnlyProcess();
-
-// Returns the main bundle or the override, used for code that needs
-// to fetch resources from bundles, but work within a unittest where we
-// aren't a bundle.
-NSBundle* MainAppBundle();
-FilePath MainAppBundlePath();
-
-// Set the bundle that MainAppBundle will return, overriding the default value
-// (Restore the default by calling SetOverrideAppBundle(nil)).
-void SetOverrideAppBundle(NSBundle* bundle);
-void SetOverrideAppBundlePath(const FilePath& file_path);
-
-// Returns the creator code associated with the CFBundleRef at bundle.
-OSType CreatorCodeForCFBundleRef(CFBundleRef bundle);
-
-// Returns the creator code associated with this application, by calling
-// CreatorCodeForCFBundleRef for the application's main bundle. If this
-// information cannot be determined, returns kUnknownType ('????'). This
-// does not respect the override app bundle because it's based on CFBundle
-// instead of NSBundle, and because callers probably don't want the override
-// app bundle's creator code anyway.
-OSType CreatorCodeForApplication();
-
-// Searches for directories for the given key in only the given |domain_mask|.
-// If found, fills result (which must always be non-NULL) with the
-// first found directory and returns true. Otherwise, returns false.
-bool GetSearchPathDirectory(NSSearchPathDirectory directory,
- NSSearchPathDomainMask domain_mask,
- FilePath* result);
-
-// Searches for directories for the given key in only the user domain.
-// If found, fills result (which must always be non-NULL) with the
-// first found directory and returns true. Otherwise, returns false.
-bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result);
-
-// Searches for directories for the given key in only the local domain.
-// If found, fills result (which must always be non-NULL) with the
-// first found directory and returns true. Otherwise, returns false.
-bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result);
-
-// Returns the ~/Library directory.
-FilePath GetUserLibraryPath();
-
// Returns an sRGB color space. The return value is a static value; do not
// release it!
CGColorSpaceRef GetSRGBColorSpace();
@@ -135,30 +77,17 @@ void SetCursorVisibility(bool visible);
// Should windows miniaturize on a double-click (on the title bar)?
bool ShouldWindowsMiniaturizeOnDoubleClick();
-// Activates the process with the given PID.
-void ActivateProcess(pid_t);
-
// Pulls a snapshot of the entire browser into png_representation.
void GrabWindowSnapshot(NSWindow* window,
std::vector<unsigned char>* png_representation,
int* width, int* height);
-// Takes a path to an (executable) binary and tries to provide the path to an
-// application bundle containing it. It takes the outermost bundle that it can
-// find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app").
-// |exec_name| - path to the binary
-// returns - path to the application bundle, or empty on error
-FilePath GetAppBundlePath(const FilePath& exec_name);
+// Activates the process with the given PID.
+void ActivateProcess(pid_t pid);
// Set the Time Machine exclusion property for the given file.
bool SetFileBackupExclusion(const FilePath& file_path, bool exclude);
-// Utility function to pull out a value from a dictionary, check its type, and
-// return it. Returns NULL if the key is not present or of the wrong type.
-CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
- CFStringRef key,
- CFTypeID expected_type);
-
// Sets the process name as displayed in Activity Monitor to process_name.
void SetProcessName(CFStringRef process_name);
@@ -189,10 +118,6 @@ void RemoveFromLoginItems();
// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
bool WasLaunchedAsHiddenLoginItem();
-// Retain/release calls for memory management in C++.
-void NSObjectRetain(void* obj);
-void NSObjectRelease(void* obj);
-
#if defined(__OBJC__)
// Convert toll-free bridged CFTypes to NSTypes. This does not autorelease
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm
index f5eb03d..c32be37 100644
--- a/base/mac/mac_util.mm
+++ b/base/mac/mac_util.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -141,133 +141,6 @@ bool FSRefFromPath(const std::string& path, FSRef* ref) {
return status == noErr;
}
-static bool g_override_am_i_bundled = false;
-static bool g_override_am_i_bundled_value = false;
-
-// Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
-static bool UncachedAmIBundled() {
- if (g_override_am_i_bundled)
- return g_override_am_i_bundled_value;
-
- ProcessSerialNumber psn = {0, kCurrentProcess};
-
- FSRef fsref;
- OSStatus pbErr;
- if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) {
- LOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr;
- return false;
- }
-
- FSCatalogInfo info;
- OSErr fsErr;
- if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
- NULL, NULL, NULL)) != noErr) {
- LOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr;
- return false;
- }
-
- return info.nodeFlags & kFSNodeIsDirectoryMask;
-}
-
-bool AmIBundled() {
- // If the return value is not cached, this function will return different
- // values depending on when it's called. This confuses some client code, see
- // http://crbug.com/63183 .
- static bool result = UncachedAmIBundled();
- DCHECK_EQ(result, UncachedAmIBundled())
- << "The return value of AmIBundled() changed. This will confuse tests. "
- << "Call SetAmIBundled() override manually if your test binary "
- << "delay-loads the framework.";
- return result;
-}
-
-void SetOverrideAmIBundled(bool value) {
- g_override_am_i_bundled = true;
- g_override_am_i_bundled_value = value;
-}
-
-bool IsBackgroundOnlyProcess() {
- // This function really does want to examine NSBundle's idea of the main
- // bundle dictionary, and not the overriden MainAppBundle. It needs to look
- // at the actual running .app's Info.plist to access its LSUIElement
- // property.
- NSDictionary* info_dictionary = [[NSBundle mainBundle] infoDictionary];
- return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO;
-}
-
-// No threading worries since NSBundle isn't thread safe.
-static NSBundle* g_override_app_bundle = nil;
-
-NSBundle* MainAppBundle() {
- if (g_override_app_bundle)
- return g_override_app_bundle;
- return [NSBundle mainBundle];
-}
-
-FilePath MainAppBundlePath() {
- NSBundle* bundle = MainAppBundle();
- return FilePath([[bundle bundlePath] fileSystemRepresentation]);
-}
-
-void SetOverrideAppBundle(NSBundle* bundle) {
- if (bundle != g_override_app_bundle) {
- [g_override_app_bundle release];
- g_override_app_bundle = [bundle retain];
- }
-}
-
-void SetOverrideAppBundlePath(const FilePath& file_path) {
- NSString* path = base::SysUTF8ToNSString(file_path.value());
- NSBundle* bundle = [NSBundle bundleWithPath:path];
- CHECK(bundle) << "Failed to load the bundle at " << file_path.value();
-
- SetOverrideAppBundle(bundle);
-}
-
-OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) {
- OSType creator = kUnknownType;
- CFBundleGetPackageInfo(bundle, NULL, &creator);
- return creator;
-}
-
-OSType CreatorCodeForApplication() {
- CFBundleRef bundle = CFBundleGetMainBundle();
- if (!bundle)
- return kUnknownType;
-
- return CreatorCodeForCFBundleRef(bundle);
-}
-
-bool GetSearchPathDirectory(NSSearchPathDirectory directory,
- NSSearchPathDomainMask domain_mask,
- FilePath* result) {
- DCHECK(result);
- NSArray* dirs =
- NSSearchPathForDirectoriesInDomains(directory, domain_mask, YES);
- if ([dirs count] < 1) {
- return false;
- }
- NSString* path = [dirs objectAtIndex:0];
- *result = FilePath([path fileSystemRepresentation]);
- return true;
-}
-
-bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) {
- return GetSearchPathDirectory(directory, NSLocalDomainMask, result);
-}
-
-bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) {
- return GetSearchPathDirectory(directory, NSUserDomainMask, result);
-}
-
-FilePath GetUserLibraryPath() {
- FilePath user_library_path;
- if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) {
- LOG(WARNING) << "Could not get user library path";
- }
- return user_library_path;
-}
-
CGColorSpaceRef GetSRGBColorSpace() {
// Leaked. That's OK, it's scoped to the lifetime of the application.
static CGColorSpaceRef g_color_space_sRGB =
@@ -396,55 +269,6 @@ void ActivateProcess(pid_t pid) {
}
}
-// Takes a path to an (executable) binary and tries to provide the path to an
-// application bundle containing it. It takes the outermost bundle that it can
-// find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app").
-// |exec_name| - path to the binary
-// returns - path to the application bundle, or empty on error
-FilePath GetAppBundlePath(const FilePath& exec_name) {
- const char kExt[] = ".app";
- const size_t kExtLength = arraysize(kExt) - 1;
-
- // Split the path into components.
- std::vector<std::string> components;
- exec_name.GetComponents(&components);
-
- // It's an error if we don't get any components.
- if (!components.size())
- return FilePath();
-
- // Don't prepend '/' to the first component.
- std::vector<std::string>::const_iterator it = components.begin();
- std::string bundle_name = *it;
- DCHECK(it->length() > 0);
- // If the first component ends in ".app", we're already done.
- if (it->length() > kExtLength &&
- !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
- return FilePath(bundle_name);
-
- // The first component may be "/" or "//", etc. Only append '/' if it doesn't
- // already end in '/'.
- if (bundle_name[bundle_name.length() - 1] != '/')
- bundle_name += '/';
-
- // Go through the remaining components.
- for (++it; it != components.end(); ++it) {
- DCHECK(it->length() > 0);
-
- bundle_name += *it;
-
- // If the current component ends in ".app", we're done.
- if (it->length() > kExtLength &&
- !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
- return FilePath(bundle_name);
-
- // Separate this component from the next one.
- bundle_name += '/';
- }
-
- return FilePath();
-}
-
bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) {
NSString* filePath =
[NSString stringWithUTF8String:file_path.value().c_str()];
@@ -488,31 +312,6 @@ bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) {
return success;
}
-CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
- CFStringRef key,
- CFTypeID expected_type) {
- CFTypeRef value = CFDictionaryGetValue(dict, key);
- if (!value)
- return value;
-
- if (CFGetTypeID(value) != expected_type) {
- ScopedCFTypeRef<CFStringRef> expected_type_ref(
- CFCopyTypeIDDescription(expected_type));
- ScopedCFTypeRef<CFStringRef> actual_type_ref(
- CFCopyTypeIDDescription(CFGetTypeID(value)));
- LOG(WARNING) << "Expected value for key "
- << base::SysCFStringRefToUTF8(key)
- << " to be "
- << base::SysCFStringRefToUTF8(expected_type_ref)
- << " but it was "
- << base::SysCFStringRefToUTF8(actual_type_ref)
- << " instead";
- return NULL;
- }
-
- return value;
-}
-
void SetProcessName(CFStringRef process_name) {
if (!process_name || CFStringGetLength(process_name) == 0) {
NOTREACHED() << "SetProcessName given bad name.";
@@ -712,15 +511,5 @@ bool WasLaunchedAsHiddenLoginItem() {
return IsHiddenLoginItem(item);
}
-void NSObjectRetain(void* obj) {
- id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
- [nsobj retain];
-}
-
-void NSObjectRelease(void* obj) {
- id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
- [nsobj release];
-}
-
} // namespace mac
} // namespace base