| Index: base/mac/foundation_util.mm
|
| diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
|
| index 1d33391f1e2341da72732c14b2a20e99520fb9d9..5f8f6946a0aa9be56c49c05e9dc7239ebe29ddcf 100644
|
| --- a/base/mac/foundation_util.mm
|
| +++ b/base/mac/foundation_util.mm
|
| @@ -23,11 +23,26 @@ CFTypeID SecTrustedApplicationGetTypeID();
|
| namespace base {
|
| namespace mac {
|
|
|
| -static bool g_override_am_i_bundled = false;
|
| -static bool g_override_am_i_bundled_value = false;
|
| +namespace {
|
| +
|
| +bool g_override_am_i_bundled = false;
|
| +bool g_override_am_i_bundled_value = false;
|
| +
|
| +int CheapPathNormalizedCount(NSString* path) {
|
| + int count = 0;
|
| + for (NSString* component in [path pathComponents]) {
|
| + if ([component isEqualToString:@"."])
|
| + continue;
|
| + else if ([component isEqualToString:@".."])
|
| + --count;
|
| + else
|
| + ++count;
|
| + }
|
| +
|
| + return count;
|
| +}
|
|
|
| -// Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
|
| -static bool UncachedAmIBundled() {
|
| +bool UncachedAmIBundled() {
|
| #if defined(OS_IOS)
|
| // All apps are bundled on iOS.
|
| return true;
|
| @@ -36,18 +51,20 @@ static bool UncachedAmIBundled() {
|
| return g_override_am_i_bundled_value;
|
|
|
| NSBundle* bundle = base::mac::OuterBundle();
|
| - NSArray* bundle_parts = [[bundle bundlePath] pathComponents];
|
| - NSArray* executable_parts = [[bundle executablePath] pathComponents];
|
| + int bundle_count = CheapPathNormalizedCount([bundle bundlePath]);
|
| + int executable_count = CheapPathNormalizedCount([bundle executablePath]);
|
|
|
| // Bundled executables are exactly three levels deeper than their bundle.
|
| // Non-bundled executables have a fake bundle with a bundle path of their
|
| // parent directory.
|
| - NSUInteger depth_difference = [executable_parts count] - [bundle_parts count];
|
| + int depth_difference = executable_count - bundle_count;
|
| CHECK(depth_difference == 1 || depth_difference == 3);
|
| return depth_difference == 3;
|
| #endif
|
| }
|
|
|
| +} // namespace
|
| +
|
| 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
|
|
|