| OLD | NEW | 
|---|
| 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 "chrome/common/chrome_paths_internal.h" | 5 #include "chrome/common/chrome_paths_internal.h" | 
| 6 | 6 | 
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> | 
| 8 #include <string.h> | 8 #include <string.h> | 
| 9 | 9 | 
| 10 #include <string> | 10 #include <string> | 
| 11 | 11 | 
| 12 #include "base/base_paths.h" | 12 #include "base/base_paths.h" | 
| 13 #include "base/logging.h" | 13 #include "base/logging.h" | 
| 14 #import "base/mac/foundation_util.h" | 14 #import "base/mac/foundation_util.h" | 
| 15 #import "base/mac/mac_util.h" |  | 
| 16 #import "base/mac/scoped_nsautorelease_pool.h" | 15 #import "base/mac/scoped_nsautorelease_pool.h" | 
| 17 #include "base/path_service.h" | 16 #include "base/path_service.h" | 
| 18 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" | 
| 19 | 18 | 
|  | 19 #if !defined(OS_IOS) | 
|  | 20 #import "base/mac/mac_util.h" | 
|  | 21 #endif | 
|  | 22 | 
| 20 namespace { | 23 namespace { | 
| 21 | 24 | 
|  | 25 #if !defined(OS_IOS) | 
| 22 const FilePath* g_override_versioned_directory = NULL; | 26 const FilePath* g_override_versioned_directory = NULL; | 
| 23 | 27 | 
| 24 // Return a retained (NOT autoreleased) NSBundle* as the internal | 28 // Return a retained (NOT autoreleased) NSBundle* as the internal | 
| 25 // implementation of chrome::OuterAppBundle(), which should be the only | 29 // implementation of chrome::OuterAppBundle(), which should be the only | 
| 26 // caller. | 30 // caller. | 
| 27 NSBundle* OuterAppBundleInternal() { | 31 NSBundle* OuterAppBundleInternal() { | 
| 28   base::mac::ScopedNSAutoreleasePool pool; | 32   base::mac::ScopedNSAutoreleasePool pool; | 
| 29 | 33 | 
| 30   if (!base::mac::AmIBundled()) { | 34   if (!base::mac::AmIBundled()) { | 
| 31     // If unbundled (as in a test), there's no app bundle. | 35     // If unbundled (as in a test), there's no app bundle. | 
| 32     return nil; | 36     return nil; | 
| 33   } | 37   } | 
| 34 | 38 | 
| 35   if (!base::mac::IsBackgroundOnlyProcess()) { | 39   if (!base::mac::IsBackgroundOnlyProcess()) { | 
| 36     // Shortcut: in the browser process, just return the main app bundle. | 40     // Shortcut: in the browser process, just return the main app bundle. | 
| 37     return [[NSBundle mainBundle] retain]; | 41     return [[NSBundle mainBundle] retain]; | 
| 38   } | 42   } | 
| 39 | 43 | 
| 40   // From C.app/Contents/Versions/1.2.3.4, go up three steps to get to C.app. | 44   // From C.app/Contents/Versions/1.2.3.4, go up three steps to get to C.app. | 
| 41   FilePath versioned_dir = chrome::GetVersionedDirectory(); | 45   FilePath versioned_dir = chrome::GetVersionedDirectory(); | 
| 42   FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); | 46   FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); | 
| 43   const char* outer_app_dir_c = outer_app_dir.value().c_str(); | 47   const char* outer_app_dir_c = outer_app_dir.value().c_str(); | 
| 44   NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; | 48   NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; | 
| 45 | 49 | 
| 46   return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; | 50   return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; | 
| 47 } | 51 } | 
|  | 52 #endif  // !defined(OS_IOS) | 
| 48 | 53 | 
| 49 const char* ProductDirNameInternal() { | 54 const char* ProductDirNameInternal() { | 
|  | 55   const char* product_dir_name = NULL; | 
|  | 56 #if !defined(OS_IOS) | 
| 50   base::mac::ScopedNSAutoreleasePool pool; | 57   base::mac::ScopedNSAutoreleasePool pool; | 
| 51 | 58 | 
| 52   // Use OuterAppBundle() to get the main app's bundle. This key needs to live | 59   // Use OuterAppBundle() to get the main app's bundle. This key needs to live | 
| 53   // in the main app's bundle because it will be set differently on the canary | 60   // in the main app's bundle because it will be set differently on the canary | 
| 54   // channel, and the autoupdate system dictates that there can be no | 61   // channel, and the autoupdate system dictates that there can be no | 
| 55   // differences between channels within the versioned directory. This would | 62   // differences between channels within the versioned directory. This would | 
| 56   // normally use base::mac::FrameworkBundle(), but that references the | 63   // normally use base::mac::FrameworkBundle(), but that references the | 
| 57   // framework bundle within the versioned directory. Ordinarily, the profile | 64   // framework bundle within the versioned directory. Ordinarily, the profile | 
| 58   // should not be accessed from non-browser processes, but those processes do | 65   // should not be accessed from non-browser processes, but those processes do | 
| 59   // attempt to get the profile directory, so direct them to look in the outer | 66   // attempt to get the profile directory, so direct them to look in the outer | 
| 60   // browser .app's Info.plist for the CrProductDirName key. | 67   // browser .app's Info.plist for the CrProductDirName key. | 
| 61   NSBundle* bundle = chrome::OuterAppBundle(); | 68   NSBundle* bundle = chrome::OuterAppBundle(); | 
| 62   NSString* product_dir_name_ns = | 69   NSString* product_dir_name_ns = | 
| 63       [bundle objectForInfoDictionaryKey:@"CrProductDirName"]; | 70       [bundle objectForInfoDictionaryKey:@"CrProductDirName"]; | 
| 64   const char* product_dir_name = [product_dir_name_ns fileSystemRepresentation]; | 71   product_dir_name = [product_dir_name_ns fileSystemRepresentation]; | 
|  | 72 #endif | 
| 65 | 73 | 
| 66   if (!product_dir_name) { | 74   if (!product_dir_name) { | 
| 67 #if defined(GOOGLE_CHROME_BUILD) | 75 #if defined(GOOGLE_CHROME_BUILD) | 
| 68     product_dir_name = "Google/Chrome"; | 76     product_dir_name = "Google/Chrome"; | 
| 69 #else | 77 #else | 
| 70     product_dir_name = "Chromium"; | 78     product_dir_name = "Chromium"; | 
| 71 #endif | 79 #endif | 
| 72   } | 80   } | 
| 73 | 81 | 
| 74   // Leaked, but the only caller initializes a static with this result, so it | 82   // Leaked, but the only caller initializes a static with this result, so it | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 98     *result = result->Append(ProductDirName()); | 106     *result = result->Append(ProductDirName()); | 
| 99     success = true; | 107     success = true; | 
| 100   } | 108   } | 
| 101   return success; | 109   return success; | 
| 102 } | 110 } | 
| 103 | 111 | 
| 104 bool GetUserDocumentsDirectory(FilePath* result) { | 112 bool GetUserDocumentsDirectory(FilePath* result) { | 
| 105   return base::mac::GetUserDirectory(NSDocumentDirectory, result); | 113   return base::mac::GetUserDirectory(NSDocumentDirectory, result); | 
| 106 } | 114 } | 
| 107 | 115 | 
| 108 bool GetGlobalApplicationSupportDirectory(FilePath* result) { |  | 
| 109   return base::mac::GetLocalDirectory(NSApplicationSupportDirectory, result); |  | 
| 110 } |  | 
| 111 |  | 
| 112 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { | 116 void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) { | 
| 113   // If the profile directory is under ~/Library/Application Support, | 117   // If the profile directory is under ~/Library/Application Support, | 
| 114   // use a suitable cache directory under ~/Library/Caches.  For | 118   // use a suitable cache directory under ~/Library/Caches.  For | 
| 115   // example, a profile directory of ~/Library/Application | 119   // example, a profile directory of ~/Library/Application | 
| 116   // Support/Google/Chrome/MyProfileName would use the cache directory | 120   // Support/Google/Chrome/MyProfileName would use the cache directory | 
| 117   // ~/Library/Caches/Google/Chrome/MyProfileName. | 121   // ~/Library/Caches/Google/Chrome/MyProfileName. | 
| 118 | 122 | 
| 119   // Default value in cases where any of the following fails. | 123   // Default value in cases where any of the following fails. | 
| 120   *result = profile_dir; | 124   *result = profile_dir; | 
| 121 | 125 | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 140 } | 144 } | 
| 141 | 145 | 
| 142 bool GetUserPicturesDirectory(FilePath* result) { | 146 bool GetUserPicturesDirectory(FilePath* result) { | 
| 143   return base::mac::GetUserDirectory(NSPicturesDirectory, result); | 147   return base::mac::GetUserDirectory(NSPicturesDirectory, result); | 
| 144 } | 148 } | 
| 145 | 149 | 
| 146 bool GetUserVideosDirectory(FilePath* result) { | 150 bool GetUserVideosDirectory(FilePath* result) { | 
| 147   return base::mac::GetUserDirectory(NSMoviesDirectory, result); | 151   return base::mac::GetUserDirectory(NSMoviesDirectory, result); | 
| 148 } | 152 } | 
| 149 | 153 | 
|  | 154 #if !defined(OS_IOS) | 
|  | 155 | 
| 150 FilePath GetVersionedDirectory() { | 156 FilePath GetVersionedDirectory() { | 
| 151   if (g_override_versioned_directory) | 157   if (g_override_versioned_directory) | 
| 152     return *g_override_versioned_directory; | 158     return *g_override_versioned_directory; | 
| 153 | 159 | 
| 154   // Start out with the path to the running executable. | 160   // Start out with the path to the running executable. | 
| 155   FilePath path; | 161   FilePath path; | 
| 156   PathService::Get(base::FILE_EXE, &path); | 162   PathService::Get(base::FILE_EXE, &path); | 
| 157 | 163 | 
| 158   // One step up to MacOS, another to Contents. | 164   // One step up to MacOS, another to Contents. | 
| 159   path = path.DirName().DirName(); | 165   path = path.DirName().DirName(); | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 193 | 199 | 
| 194   // The framework bundle is at a known path and name from the browser .app's | 200   // The framework bundle is at a known path and name from the browser .app's | 
| 195   // versioned directory. | 201   // versioned directory. | 
| 196   return GetVersionedDirectory().Append(kFrameworkName); | 202   return GetVersionedDirectory().Append(kFrameworkName); | 
| 197 } | 203 } | 
| 198 | 204 | 
| 199 bool GetLocalLibraryDirectory(FilePath* result) { | 205 bool GetLocalLibraryDirectory(FilePath* result) { | 
| 200   return base::mac::GetLocalDirectory(NSLibraryDirectory, result); | 206   return base::mac::GetLocalDirectory(NSLibraryDirectory, result); | 
| 201 } | 207 } | 
| 202 | 208 | 
|  | 209 bool GetGlobalApplicationSupportDirectory(FilePath* result) { | 
|  | 210   return base::mac::GetLocalDirectory(NSApplicationSupportDirectory, result); | 
|  | 211 } | 
|  | 212 | 
| 203 NSBundle* OuterAppBundle() { | 213 NSBundle* OuterAppBundle() { | 
| 204   // Cache this. Foundation leaks it anyway, and this should be the only call | 214   // Cache this. Foundation leaks it anyway, and this should be the only call | 
| 205   // to OuterAppBundleInternal(). | 215   // to OuterAppBundleInternal(). | 
| 206   static NSBundle* bundle = OuterAppBundleInternal(); | 216   static NSBundle* bundle = OuterAppBundleInternal(); | 
| 207   return bundle; | 217   return bundle; | 
| 208 } | 218 } | 
| 209 | 219 | 
|  | 220 #endif  // !defined(OS_IOS) | 
|  | 221 | 
| 210 bool ProcessNeedsProfileDir(const std::string& process_type) { | 222 bool ProcessNeedsProfileDir(const std::string& process_type) { | 
| 211   // For now we have no reason to forbid this on other MacOS as we don't | 223   // For now we have no reason to forbid this on other MacOS as we don't | 
| 212   // have the roaming profile troubles there. | 224   // have the roaming profile troubles there. | 
| 213   return true; | 225   return true; | 
| 214 } | 226 } | 
| 215 | 227 | 
| 216 }  // namespace chrome | 228 }  // namespace chrome | 
| OLD | NEW | 
|---|