Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2616)

Unified Diff: base/mac/foundation_util.mm

Issue 46973003: Merge 231376 "Fix AmIBundled for command-line executions." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1650/src/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/foundation_util.mm
===================================================================
--- base/mac/foundation_util.mm (revision 232405)
+++ base/mac/foundation_util.mm (working copy)
@@ -23,11 +23,26 @@
namespace base {
namespace mac {
-static bool g_override_am_i_bundled = false;
-static bool g_override_am_i_bundled_value = false;
+namespace {
-// Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
-static bool UncachedAmIBundled() {
+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.
return true;
@@ -36,18 +51,20 @@
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698