Skip to content

Commit

Permalink
Fix AmIBundled for command-line executions. Again.
Browse files Browse the repository at this point in the history
BUG=304860, 312196
TEST=run from the command line with dots
R=mark@chromium.org

Review URL: https://codereview.chromium.org/51023003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231672 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
avi@chromium.org committed Oct 29, 2013
1 parent 84683f0 commit 0167900
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions base/mac/foundation_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@
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;
}

bool UncachedAmIBundled() {
#if defined(OS_IOS)
// All apps are bundled on iOS.
Expand All @@ -51,16 +37,8 @@ bool UncachedAmIBundled() {
if (g_override_am_i_bundled)
return g_override_am_i_bundled_value;

NSBundle* bundle = base::mac::OuterBundle();
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.
int depth_difference = executable_count - bundle_count;
CHECK(depth_difference == 1 || depth_difference == 3);
return depth_difference == 3;
// Yes, this is cheap.
return [[base::mac::OuterBundle() bundlePath] hasSuffix:@".app"];
#endif
}

Expand Down

0 comments on commit 0167900

Please sign in to comment.