Chromium Code Reviews| 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 static FilePath path; | 70 // Start out with the path to the running .app. |
| 71 NSBundle* app_bundle = [NSBundle mainBundle]; | |
|
TVL
2009/10/14 21:09:15
since the concern in here was threading, http://de
Mark Mentovai
2009/10/14 21:26:46
TVL wrote:
| |
| 72 FilePath path = FilePath([[app_bundle bundlePath] fileSystemRepresentation]); | |
| 71 | 73 |
| 72 if (path.empty()) { | 74 if (mac_util::IsBackgroundOnlyProcess()) { |
| 73 // Start out with the path to the running .app. | 75 // path identifies the helper .app in the browser .app's versioned |
| 74 NSBundle* app_bundle = [NSBundle mainBundle]; | 76 // directory. Go up one level to get to the browser .app's versioned |
| 75 path = FilePath([[app_bundle bundlePath] fileSystemRepresentation]); | 77 // directory. |
| 76 | 78 path = path.DirName(); |
| 77 if (mac_util::IsBackgroundOnlyProcess()) { | 79 } else { |
| 78 // path identifies the helper .app in the browser .app's versioned | 80 // path identifies the browser .app. Go into its versioned directory. |
| 79 // directory. Go up one level to get to the browser .app's versioned | 81 path = path.Append("Contents").Append("Versions").Append(kChromeVersion); |
| 80 // directory. | |
| 81 path = path.DirName(); | |
| 82 } else { | |
| 83 // path identifies the browser .app. Go into its versioned directory. | |
| 84 // TODO(mark): Here, |version| comes from the outer .app bundle's | |
| 85 // Info.plist. In the event of an incomplete update, it may be possible | |
| 86 // for this value to be incorrect. Consider the case where the updater | |
| 87 // is able to update one, but not both, of the executable and the | |
| 88 // Info.plist. The executable may load one version of the framework, | |
| 89 // and the Info.plist may refer to another version. Ideally, the | |
| 90 // version would be available in a compile-time constant, or there would | |
| 91 // be a better way to detect the loaded framework version at runtime. | |
| 92 NSString* version = | |
| 93 [app_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; | |
| 94 path = path.Append("Contents"). | |
| 95 Append("Versions"). | |
| 96 Append([version fileSystemRepresentation]); | |
| 97 } | |
| 98 } | 82 } |
| 99 | 83 |
| 100 return path; | 84 return path; |
| 101 } | 85 } |
| 102 | 86 |
| 103 FilePath GetFrameworkBundlePath() { | 87 FilePath GetFrameworkBundlePath() { |
| 104 // It's tempting to use +[NSBundle bundleWithIdentifier:], but it's really | 88 // It's tempting to use +[NSBundle bundleWithIdentifier:], but it's really |
| 105 // slow (about 30ms on 10.5 and 10.6), despite Apple's documentation stating | 89 // slow (about 30ms on 10.5 and 10.6), despite Apple's documentation stating |
| 106 // that it may be more efficient than +bundleForClass:. +bundleForClass: | 90 // that it may be more efficient than +bundleForClass:. +bundleForClass: |
| 107 // itself takes 1-2ms. Getting an NSBundle from a path, on the other hand, | 91 // itself takes 1-2ms. Getting an NSBundle from a path, on the other hand, |
| 108 // essentially takes no time at all, at least when the bundle has already | 92 // essentially takes no time at all, at least when the bundle has already |
| 109 // been loaded as it will have been in this case. The FilePath operations | 93 // been loaded as it will have been in this case. The FilePath operations |
| 110 // needed to compute the framework's path are also effectively free, so that | 94 // needed to compute the framework's path are also effectively free, so that |
| 111 // is the approach that is used here. | 95 // is the approach that is used here. |
| 112 | 96 |
| 113 // The framework bundle is at a known path and name from the browser .app's | 97 // The framework bundle is at a known path and name from the browser .app's |
| 114 // versioned directory. | 98 // versioned directory. |
| 115 return GetVersionedDirectory().Append(kFrameworkName); | 99 return GetVersionedDirectory().Append(kFrameworkName); |
| 116 } | 100 } |
| 117 | 101 |
| 118 } // namespace chrome | 102 } // namespace chrome |
| OLD | NEW |