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

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

Issue 9147031: Functions to return locations of various Chrome bundles. (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/bundle_locations.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/mac/bundle_locations.h"
6
7 #include "base/logging.h"
8 #include "base/sys_string_conversions.h"
9
10 namespace base {
11 namespace mac {
12
13 // Functions in this file must assert thread safety since NSBundle isn't
14 // threadsafe.
15 static NSBundle* g_override_framework_bundle = nil;
16 static NSBundle* g_override_outer_bundle = nil;
17
18 NSBundle* MainBundle() {
19 DCHECK([NSThread isMainThread]);
Mark Mentovai 2012/01/11 19:11:42 I don’t know if these DCHECKs are a good idea.
20 return [NSBundle mainBundle];
21 }
22
23 FilePath MainBundlePath() {
24 DCHECK([NSThread isMainThread]);
Mark Mentovai 2012/01/11 19:11:42 Don’t do this here, MainBundle does it anyway. Sa
25 NSBundle* bundle = MainBundle();
26 return FilePath([[bundle bundlePath] fileSystemRepresentation]);
27 }
28
29 NSBundle* OuterBundle() {
30 DCHECK([NSThread isMainThread]);
31 if (g_override_outer_bundle)
32 return g_override_outer_bundle;
33 return [NSBundle mainBundle];
34 }
35
36 FilePath OuterBundlePath() {
37 DCHECK([NSThread isMainThread]);
38 NSBundle* bundle = OuterBundle();
39 return FilePath([[bundle bundlePath] fileSystemRepresentation]);
40 }
41
42 NSBundle* FrameworkBundle() {
43 DCHECK([NSThread isMainThread]);
44 if (g_override_framework_bundle)
45 return g_override_framework_bundle;
46 return [NSBundle mainBundle];
47 }
48
49 FilePath FrameworkBundlePath() {
50 DCHECK([NSThread isMainThread]);
51 NSBundle* bundle = FrameworkBundle();
52 return FilePath([[bundle bundlePath] fileSystemRepresentation]);
53 }
54
55 static void AssignOverrideBundle(NSBundle* new_bundle,
56 NSBundle* override_bundle) {
Mark Mentovai 2012/01/11 19:11:42 I don’t think this does what you think it does. Ho
57 if (new_bundle != override_bundle) {
58 [override_bundle release];
59 override_bundle = [new_bundle retain];
60 }
61 }
62
63 static void AssignOverridePath(const FilePath& file_path,
64 NSBundle* override_bundle) {
65 NSString* path = base::SysUTF8ToNSString(file_path.value());
66 NSBundle* new_bundle = [NSBundle bundleWithPath:path];
67 DCHECK(new_bundle) << "Failed to load the bundle at " << file_path.value();
68 AssignOverrideBundle(new_bundle, override_bundle);
69 }
70
71 void SetOverrideOuterBundle(NSBundle* bundle) {
72 DCHECK([NSThread isMainThread]);
Mark Mentovai 2012/01/11 19:11:42 Again, not sure about these DCHCEKs, but if you ar
73 AssignOverrideBundle(bundle, g_override_outer_bundle);
74 }
75
76 void SetOverrideFrameworkBundle(NSBundle* bundle) {
77 DCHECK([NSThread isMainThread]);
78 AssignOverrideBundle(bundle, g_override_framework_bundle);
79 }
80
81 void SetOverrideOuterBundlePath(const FilePath& file_path) {
82 DCHECK([NSThread isMainThread]);
83 AssignOverridePath(file_path, g_override_outer_bundle);
84 }
85
86 void SetOverrideFrameworkBundlePath(const FilePath& file_path) {
87 DCHECK([NSThread isMainThread]);
88 AssignOverridePath(file_path, g_override_framework_bundle);
89 }
90
91 } // namespace mac
92 } // namespace base
OLDNEW
« no previous file with comments | « base/mac/bundle_locations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698