summaryrefslogtreecommitdiffstats
path: root/base/mac
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-28 19:29:53 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-28 19:29:53 +0000
commit7bc74e5f32dad6db6ffefb9f9d4341b5d322b3f4 (patch)
treee916266f62d390c79fa30441bab759442a8c7b7f /base/mac
parente60d04105555023b94adf08d6af8b615ae0f9eec (diff)
downloadchromium_src-7bc74e5f32dad6db6ffefb9f9d4341b5d322b3f4.zip
chromium_src-7bc74e5f32dad6db6ffefb9f9d4341b5d322b3f4.tar.gz
chromium_src-7bc74e5f32dad6db6ffefb9f9d4341b5d322b3f4.tar.bz2
Fix AmIBundled for command-line executions.
BUG=304860, 312196 TEST=run from the command line with dots Review URL: https://codereview.chromium.org/45703003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac')
-rw-r--r--base/mac/foundation_util.mm31
1 files changed, 24 insertions, 7 deletions
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index 1d33391..5f8f694 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