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

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

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « base/mac/foundation_util.h ('k') | base/mac/libdispatch_task_runner_unittest.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/bundle_locations.h" 12 #include "base/mac/bundle_locations.h"
13 #include "base/mac/mac_logging.h" 13 #include "base/mac/mac_logging.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 15
16 #if !defined(OS_IOS) 16 #if !defined(OS_IOS)
17 extern "C" { 17 extern "C" {
18 CFTypeID SecACLGetTypeID(); 18 CFTypeID SecACLGetTypeID();
19 CFTypeID SecTrustedApplicationGetTypeID(); 19 CFTypeID SecTrustedApplicationGetTypeID();
20 Boolean _CFIsObjC(CFTypeID typeID, CFTypeRef obj); 20 Boolean _CFIsObjC(CFTypeID typeID, CFTypeRef obj);
21 } // extern "C" 21 } // extern "C"
22 #endif 22 #endif
23 23
24 namespace base { 24 namespace base {
25 namespace mac { 25 namespace mac {
26 26
27 namespace { 27 namespace {
28 28
29 bool g_cached_am_i_bundled_called = false;
30 bool g_cached_am_i_bundled_value = false;
29 bool g_override_am_i_bundled = false; 31 bool g_override_am_i_bundled = false;
30 bool g_override_am_i_bundled_value = false; 32 bool g_override_am_i_bundled_value = false;
31 33
32 bool UncachedAmIBundled() { 34 bool UncachedAmIBundled() {
33 #if defined(OS_IOS) 35 #if defined(OS_IOS)
34 // All apps are bundled on iOS. 36 // All apps are bundled on iOS.
35 return true; 37 return true;
36 #else 38 #else
37 if (g_override_am_i_bundled) 39 if (g_override_am_i_bundled)
38 return g_override_am_i_bundled_value; 40 return g_override_am_i_bundled_value;
39 41
40 // Yes, this is cheap. 42 // Yes, this is cheap.
41 return [[base::mac::OuterBundle() bundlePath] hasSuffix:@".app"]; 43 return [[base::mac::OuterBundle() bundlePath] hasSuffix:@".app"];
42 #endif 44 #endif
43 } 45 }
44 46
45 } // namespace 47 } // namespace
46 48
47 bool AmIBundled() { 49 bool AmIBundled() {
48 // If the return value is not cached, this function will return different 50 // If the return value is not cached, this function will return different
49 // values depending on when it's called. This confuses some client code, see 51 // values depending on when it's called. This confuses some client code, see
50 // http://crbug.com/63183 . 52 // http://crbug.com/63183 .
51 static bool result = UncachedAmIBundled(); 53 if (!g_cached_am_i_bundled_called) {
52 DCHECK_EQ(result, UncachedAmIBundled()) 54 g_cached_am_i_bundled_called = true;
55 g_cached_am_i_bundled_value = UncachedAmIBundled();
56 }
57 DCHECK_EQ(g_cached_am_i_bundled_value, UncachedAmIBundled())
53 << "The return value of AmIBundled() changed. This will confuse tests. " 58 << "The return value of AmIBundled() changed. This will confuse tests. "
54 << "Call SetAmIBundled() override manually if your test binary " 59 << "Call SetAmIBundled() override manually if your test binary "
55 << "delay-loads the framework."; 60 << "delay-loads the framework.";
56 return result; 61 return g_cached_am_i_bundled_value;
57 } 62 }
58 63
59 void SetOverrideAmIBundled(bool value) { 64 void SetOverrideAmIBundled(bool value) {
60 #if defined(OS_IOS) 65 #if defined(OS_IOS)
61 // It doesn't make sense not to be bundled on iOS. 66 // It doesn't make sense not to be bundled on iOS.
62 if (!value) 67 if (!value)
63 NOTREACHED(); 68 NOTREACHED();
64 #endif 69 #endif
65 g_override_am_i_bundled = true; 70 g_override_am_i_bundled = true;
66 g_override_am_i_bundled_value = value; 71 g_override_am_i_bundled_value = value;
67 } 72 }
68 73
74 BASE_EXPORT void ClearAmIBundledCache() {
75 g_cached_am_i_bundled_called = false;
76 }
77
69 bool IsBackgroundOnlyProcess() { 78 bool IsBackgroundOnlyProcess() {
70 // This function really does want to examine NSBundle's idea of the main 79 // This function really does want to examine NSBundle's idea of the main
71 // bundle dictionary. It needs to look at the actual running .app's 80 // bundle dictionary. It needs to look at the actual running .app's
72 // Info.plist to access its LSUIElement property. 81 // Info.plist to access its LSUIElement property.
73 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary]; 82 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary];
74 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO; 83 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO;
75 } 84 }
76 85
77 FilePath PathForFrameworkBundleResource(CFStringRef resourceName) { 86 FilePath PathForFrameworkBundleResource(CFStringRef resourceName) {
78 NSBundle* bundle = base::mac::FrameworkBundle(); 87 NSBundle* bundle = base::mac::FrameworkBundle();
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 445 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
437 } 446 }
438 o << "Code: " << CFErrorGetCode(err) 447 o << "Code: " << CFErrorGetCode(err)
439 << " Domain: " << CFErrorGetDomain(err) 448 << " Domain: " << CFErrorGetDomain(err)
440 << " Desc: " << desc.get(); 449 << " Desc: " << desc.get();
441 if(errorDesc) { 450 if(errorDesc) {
442 o << "(" << errorDesc << ")"; 451 o << "(" << errorDesc << ")";
443 } 452 }
444 return o; 453 return o;
445 } 454 }
OLDNEW
« no previous file with comments | « base/mac/foundation_util.h ('k') | base/mac/libdispatch_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698