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

Side by Side Diff: base/mac_util.mm

Issue 4947002: Mac: Let browser_tests run in bundled mode for their whole lifetime. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: test Created 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mac_util.h ('k') | chrome/common/pepper_plugin_registry.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_util.h" 5 #include "base/mac_util.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 NSString *path_string = [(NSURL *)url.get() path]; 138 NSString *path_string = [(NSURL *)url.get() path];
139 return [path_string fileSystemRepresentation]; 139 return [path_string fileSystemRepresentation];
140 } 140 }
141 141
142 bool FSRefFromPath(const std::string& path, FSRef* ref) { 142 bool FSRefFromPath(const std::string& path, FSRef* ref) {
143 OSStatus status = FSPathMakeRef((const UInt8*)path.c_str(), 143 OSStatus status = FSPathMakeRef((const UInt8*)path.c_str(),
144 ref, nil); 144 ref, nil);
145 return status == noErr; 145 return status == noErr;
146 } 146 }
147 147
148 static bool g_override_am_i_bundled = false;
149 static bool g_override_am_i_bundled_value = false;
150
148 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled 151 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
149 bool AmIBundled() { 152 static bool UncachedAmIBundled() {
153 if (g_override_am_i_bundled)
154 return g_override_am_i_bundled_value;
155
150 ProcessSerialNumber psn = {0, kCurrentProcess}; 156 ProcessSerialNumber psn = {0, kCurrentProcess};
151 157
152 FSRef fsref; 158 FSRef fsref;
153 OSStatus pbErr; 159 OSStatus pbErr;
154 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { 160 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) {
155 LOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr; 161 LOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr;
156 return false; 162 return false;
157 } 163 }
158 164
159 FSCatalogInfo info; 165 FSCatalogInfo info;
160 OSErr fsErr; 166 OSErr fsErr;
161 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, 167 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info,
162 NULL, NULL, NULL)) != noErr) { 168 NULL, NULL, NULL)) != noErr) {
163 LOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr; 169 LOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr;
164 return false; 170 return false;
165 } 171 }
166 172
167 return info.nodeFlags & kFSNodeIsDirectoryMask; 173 return info.nodeFlags & kFSNodeIsDirectoryMask;
168 } 174 }
169 175
176 bool AmIBundled() {
177 // If the return value is not cached, this function will return different
178 // values depending on when it's called. This confuses some client code, see
179 // http://crbug.com/63183 .
180 static bool result = UncachedAmIBundled();
181 DCHECK_EQ(result, UncachedAmIBundled())
182 << "The return value of AmIBundled() changed. This will confuse tests. "
183 << "Call SetAmIBundled() override manually if your test binary "
184 << "delay-loads the framework.";
185 return result;
186 }
187
188 void SetOverrideAmIBundled(bool value) {
189 g_override_am_i_bundled = true;
190 g_override_am_i_bundled_value = value;
191 }
192
170 bool IsBackgroundOnlyProcess() { 193 bool IsBackgroundOnlyProcess() {
171 // This function really does want to examine NSBundle's idea of the main 194 // This function really does want to examine NSBundle's idea of the main
172 // bundle dictionary, and not the overriden MainAppBundle. It needs to look 195 // bundle dictionary, and not the overriden MainAppBundle. It needs to look
173 // at the actual running .app's Info.plist to access its LSUIElement 196 // at the actual running .app's Info.plist to access its LSUIElement
174 // property. 197 // property.
175 NSDictionary* info_dictionary = [[NSBundle mainBundle] infoDictionary]; 198 NSDictionary* info_dictionary = [[NSBundle mainBundle] infoDictionary];
176 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO; 199 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO;
177 } 200 }
178 201
179 // No threading worries since NSBundle isn't thread safe. 202 // No threading worries since NSBundle isn't thread safe.
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); 710 id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
688 [nsobj retain]; 711 [nsobj retain];
689 } 712 }
690 713
691 void NSObjectRelease(void* obj) { 714 void NSObjectRelease(void* obj) {
692 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); 715 id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
693 [nsobj release]; 716 [nsobj release];
694 } 717 }
695 718
696 } // namespace mac_util 719 } // namespace mac_util
OLDNEW
« no previous file with comments | « base/mac_util.h ('k') | chrome/common/pepper_plugin_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698