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

Side by Side Diff: base/mac/foundation_util.mm

Issue 9187053: Transition to base/mac/bundle_locations.h step 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix review comments. Created 8 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mac/foundation_util.h ('k') | chrome/app/chrome_main_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/mac/foundation_util.h" 5 #include "base/mac/foundation_util.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/bundle_locations.h"
12 #include "base/sys_string_conversions.h" 13 #include "base/sys_string_conversions.h"
13 14
14 namespace base { 15 namespace base {
15 namespace mac { 16 namespace mac {
16 17
17 static bool g_override_am_i_bundled = false; 18 static bool g_override_am_i_bundled = false;
18 static bool g_override_am_i_bundled_value = false; 19 static bool g_override_am_i_bundled_value = false;
19 20
20 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled 21 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
21 static bool UncachedAmIBundled() { 22 static bool UncachedAmIBundled() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return result; 55 return result;
55 } 56 }
56 57
57 void SetOverrideAmIBundled(bool value) { 58 void SetOverrideAmIBundled(bool value) {
58 g_override_am_i_bundled = true; 59 g_override_am_i_bundled = true;
59 g_override_am_i_bundled_value = value; 60 g_override_am_i_bundled_value = value;
60 } 61 }
61 62
62 bool IsBackgroundOnlyProcess() { 63 bool IsBackgroundOnlyProcess() {
63 // This function really does want to examine NSBundle's idea of the main 64 // This function really does want to examine NSBundle's idea of the main
64 // bundle dictionary, and not the overriden MainAppBundle. It needs to look 65 // bundle dictionary. It needs to look at the actual running .app's
65 // at the actual running .app's Info.plist to access its LSUIElement 66 // Info.plist to access its LSUIElement property.
66 // property. 67 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary];
67 NSDictionary* info_dictionary = [[NSBundle mainBundle] infoDictionary];
68 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO; 68 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO;
69 } 69 }
70 70
71 // No threading worries since NSBundle isn't thread safe.
72 static NSBundle* g_override_app_bundle = nil;
73
74 NSBundle* MainAppBundle() { 71 NSBundle* MainAppBundle() {
75 if (g_override_app_bundle) 72 return base::mac::FrameworkBundle();
76 return g_override_app_bundle;
77 return [NSBundle mainBundle];
78 } 73 }
79 74
80 FilePath MainAppBundlePath() { 75 FilePath MainAppBundlePath() {
81 NSBundle* bundle = MainAppBundle(); 76 return base::mac::FrameworkBundlePath();
82 return FilePath([[bundle bundlePath] fileSystemRepresentation]);
83 } 77 }
84 78
85 FilePath PathForMainAppBundleResource(CFStringRef resourceName) { 79 FilePath PathForFrameworkBundleResource(CFStringRef resourceName) {
86 NSBundle* bundle = MainAppBundle(); 80 NSBundle* bundle = base::mac::FrameworkBundle();
87 NSString* resourcePath = [bundle pathForResource:(NSString*)resourceName 81 NSString* resourcePath = [bundle pathForResource:(NSString*)resourceName
88 ofType:nil]; 82 ofType:nil];
89 if (!resourcePath) 83 if (!resourcePath)
90 return FilePath(); 84 return FilePath();
91 return FilePath([resourcePath fileSystemRepresentation]); 85 return FilePath([resourcePath fileSystemRepresentation]);
92 } 86 }
93 87
94 void SetOverrideAppBundle(NSBundle* bundle) {
95 if (bundle != g_override_app_bundle) {
96 [g_override_app_bundle release];
97 g_override_app_bundle = [bundle retain];
98 }
99 }
100
101 void SetOverrideAppBundlePath(const FilePath& file_path) {
102 NSString* path = base::SysUTF8ToNSString(file_path.value());
103 NSBundle* bundle = [NSBundle bundleWithPath:path];
104 DCHECK(bundle) << "Failed to load the bundle at " << file_path.value();
105
106 SetOverrideAppBundle(bundle);
107 }
108
109 OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) { 88 OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) {
110 OSType creator = kUnknownType; 89 OSType creator = kUnknownType;
111 CFBundleGetPackageInfo(bundle, NULL, &creator); 90 CFBundleGetPackageInfo(bundle, NULL, &creator);
112 return creator; 91 return creator;
113 } 92 }
114 93
115 OSType CreatorCodeForApplication() { 94 OSType CreatorCodeForApplication() {
116 CFBundleRef bundle = CFBundleGetMainBundle(); 95 CFBundleRef bundle = CFBundleGetMainBundle();
117 if (!bundle) 96 if (!bundle)
118 return kUnknownType; 97 return kUnknownType;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 354 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
376 } 355 }
377 o << "Code: " << CFErrorGetCode(err) 356 o << "Code: " << CFErrorGetCode(err)
378 << " Domain: " << CFErrorGetDomain(err) 357 << " Domain: " << CFErrorGetDomain(err)
379 << " Desc: " << desc.get(); 358 << " Desc: " << desc.get();
380 if(errorDesc) { 359 if(errorDesc) {
381 o << "(" << errorDesc << ")"; 360 o << "(" << errorDesc << ")";
382 } 361 }
383 return o; 362 return o;
384 } 363 }
OLDNEW
« no previous file with comments | « base/mac/foundation_util.h ('k') | chrome/app/chrome_main_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698