OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/chrome_paths_internal.h" | 5 #include "chrome/common/chrome_paths_internal.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 NSUserDomainMask, | 60 NSUserDomainMask, |
61 YES); | 61 YES); |
62 if ([docArray count] && result) { | 62 if ([docArray count] && result) { |
63 *result = FilePath([[docArray objectAtIndex:0] fileSystemRepresentation]); | 63 *result = FilePath([[docArray objectAtIndex:0] fileSystemRepresentation]); |
64 success = true; | 64 success = true; |
65 } | 65 } |
66 return success; | 66 return success; |
67 } | 67 } |
68 | 68 |
69 FilePath GetVersionedDirectory() { | 69 FilePath GetVersionedDirectory() { |
70 // Start out with the path to the running .app. | 70 // Start out with the path to the running executable. |
71 NSBundle* app_bundle = [NSBundle mainBundle]; | 71 FilePath path; |
72 FilePath path = FilePath([[app_bundle bundlePath] fileSystemRepresentation]); | 72 PathService::Get(base::FILE_EXE, &path); |
| 73 |
| 74 // One step up to MacOS, another to Contents. |
| 75 path = path.DirName().DirName(); |
73 | 76 |
74 if (mac_util::IsBackgroundOnlyProcess()) { | 77 if (mac_util::IsBackgroundOnlyProcess()) { |
75 // path identifies the helper .app in the browser .app's versioned | 78 // path identifies the helper .app's Contents directory in the browser |
76 // directory. Go up one level to get to the browser .app's versioned | 79 // .app's versioned directory. Go up two steps to get to the browser |
77 // directory. | 80 // .app's versioned directory. |
78 path = path.DirName(); | 81 path = path.DirName().DirName(); |
79 } else { | 82 } else { |
80 // path identifies the browser .app. Go into its versioned directory. | 83 // Go into the versioned directory. |
81 path = path.Append("Contents").Append("Versions").Append(kChromeVersion); | 84 path = path.Append("Versions").Append(kChromeVersion); |
82 } | 85 } |
83 | 86 |
84 return path; | 87 return path; |
85 } | 88 } |
86 | 89 |
87 FilePath GetFrameworkBundlePath() { | 90 FilePath GetFrameworkBundlePath() { |
88 // It's tempting to use +[NSBundle bundleWithIdentifier:], but it's really | 91 // It's tempting to use +[NSBundle bundleWithIdentifier:], but it's really |
89 // slow (about 30ms on 10.5 and 10.6), despite Apple's documentation stating | 92 // slow (about 30ms on 10.5 and 10.6), despite Apple's documentation stating |
90 // that it may be more efficient than +bundleForClass:. +bundleForClass: | 93 // that it may be more efficient than +bundleForClass:. +bundleForClass: |
91 // itself takes 1-2ms. Getting an NSBundle from a path, on the other hand, | 94 // itself takes 1-2ms. Getting an NSBundle from a path, on the other hand, |
92 // essentially takes no time at all, at least when the bundle has already | 95 // essentially takes no time at all, at least when the bundle has already |
93 // been loaded as it will have been in this case. The FilePath operations | 96 // been loaded as it will have been in this case. The FilePath operations |
94 // needed to compute the framework's path are also effectively free, so that | 97 // needed to compute the framework's path are also effectively free, so that |
95 // is the approach that is used here. | 98 // is the approach that is used here. NSBundle is also documented as being |
| 99 // not thread-safe, and thread safety may be a concern here. |
96 | 100 |
97 // The framework bundle is at a known path and name from the browser .app's | 101 // The framework bundle is at a known path and name from the browser .app's |
98 // versioned directory. | 102 // versioned directory. |
99 return GetVersionedDirectory().Append(kFrameworkName); | 103 return GetVersionedDirectory().Append(kFrameworkName); |
100 } | 104 } |
101 | 105 |
102 } // namespace chrome | 106 } // namespace chrome |
OLD | NEW |