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/scoped_nsautorelease_pool.h" | 15 #import "base/mac/scoped_nsautorelease_pool.h" |
| 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
17 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
18 | 19 |
19 #if !defined(OS_IOS) | 20 #if !defined(OS_IOS) |
20 #import "base/mac/mac_util.h" | 21 #import "base/mac/mac_util.h" |
21 #endif | 22 #endif |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 #if !defined(OS_IOS) | 26 #if !defined(OS_IOS) |
(...skipping 18 matching lines...) Expand all Loading... |
44 // From C.app/Contents/Versions/1.2.3.4, go up three steps to get to C.app. | 45 // From C.app/Contents/Versions/1.2.3.4, go up three steps to get to C.app. |
45 base::FilePath versioned_dir = chrome::GetVersionedDirectory(); | 46 base::FilePath versioned_dir = chrome::GetVersionedDirectory(); |
46 base::FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); | 47 base::FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); |
47 const char* outer_app_dir_c = outer_app_dir.value().c_str(); | 48 const char* outer_app_dir_c = outer_app_dir.value().c_str(); |
48 NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; | 49 NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; |
49 | 50 |
50 return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; | 51 return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; |
51 } | 52 } |
52 #endif // !defined(OS_IOS) | 53 #endif // !defined(OS_IOS) |
53 | 54 |
54 const char* ProductDirNameInternal() { | 55 char* ProductDirNameForBundle(NSBundle* chrome_bundle) { |
55 const char* product_dir_name = NULL; | 56 const char* product_dir_name = NULL; |
56 #if !defined(OS_IOS) | 57 #if !defined(OS_IOS) |
57 base::mac::ScopedNSAutoreleasePool pool; | 58 base::mac::ScopedNSAutoreleasePool pool; |
58 | 59 |
59 // Use OuterAppBundle() to get the main app's bundle. This key needs to live | |
60 // in the main app's bundle because it will be set differently on the canary | |
61 // channel, and the autoupdate system dictates that there can be no | |
62 // differences between channels within the versioned directory. This would | |
63 // normally use base::mac::FrameworkBundle(), but that references the | |
64 // framework bundle within the versioned directory. Ordinarily, the profile | |
65 // should not be accessed from non-browser processes, but those processes do | |
66 // attempt to get the profile directory, so direct them to look in the outer | |
67 // browser .app's Info.plist for the CrProductDirName key. | |
68 NSBundle* bundle = chrome::OuterAppBundle(); | |
69 NSString* product_dir_name_ns = | 60 NSString* product_dir_name_ns = |
70 [bundle objectForInfoDictionaryKey:@"CrProductDirName"]; | 61 [chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"]; |
71 product_dir_name = [product_dir_name_ns fileSystemRepresentation]; | 62 product_dir_name = [product_dir_name_ns fileSystemRepresentation]; |
| 63 #else |
| 64 DCHECK(!chrome_bundle); |
72 #endif | 65 #endif |
73 | 66 |
74 if (!product_dir_name) { | 67 if (!product_dir_name) { |
75 #if defined(GOOGLE_CHROME_BUILD) | 68 #if defined(GOOGLE_CHROME_BUILD) |
76 product_dir_name = "Google/Chrome"; | 69 product_dir_name = "Google/Chrome"; |
77 #else | 70 #else |
78 product_dir_name = "Chromium"; | 71 product_dir_name = "Chromium"; |
79 #endif | 72 #endif |
80 } | 73 } |
81 | 74 |
82 // Leaked, but the only caller initializes a static with this result, so it | 75 // Leaked, but the only caller initializes a static with this result, so it |
83 // only happens once, and that's OK. | 76 // only happens once, and that's OK. |
84 return strdup(product_dir_name); | 77 return strdup(product_dir_name); |
85 } | 78 } |
86 | 79 |
87 // ProductDirName returns the name of the directory inside | 80 // ProductDirName returns the name of the directory inside |
88 // ~/Library/Application Support that should hold the product application | 81 // ~/Library/Application Support that should hold the product application |
89 // data. This can be overridden by setting the CrProductDirName key in the | 82 // data. This can be overridden by setting the CrProductDirName key in the |
90 // outer browser .app's Info.plist. The default is "Google/Chrome" for | 83 // outer browser .app's Info.plist. The default is "Google/Chrome" for |
91 // officially-branded builds, and "Chromium" for unbranded builds. For the | 84 // officially-branded builds, and "Chromium" for unbranded builds. For the |
92 // official canary channel, the Info.plist will have CrProductDirName set | 85 // official canary channel, the Info.plist will have CrProductDirName set |
93 // to "Google/Chrome Canary". | 86 // to "Google/Chrome Canary". |
94 std::string ProductDirName() { | 87 std::string ProductDirName() { |
95 static const char* product_dir_name = ProductDirNameInternal(); | 88 #if defined(OS_IOS) |
| 89 static const char* product_dir_name = ProductDirNameForBundle(nil); |
| 90 #else |
| 91 // Use OuterAppBundle() to get the main app's bundle. This key needs to live |
| 92 // in the main app's bundle because it will be set differently on the canary |
| 93 // channel, and the autoupdate system dictates that there can be no |
| 94 // differences between channels within the versioned directory. This would |
| 95 // normally use base::mac::FrameworkBundle(), but that references the |
| 96 // framework bundle within the versioned directory. Ordinarily, the profile |
| 97 // should not be accessed from non-browser processes, but those processes do |
| 98 // attempt to get the profile directory, so direct them to look in the outer |
| 99 // browser .app's Info.plist for the CrProductDirName key. |
| 100 static const char* product_dir_name = |
| 101 ProductDirNameForBundle(chrome::OuterAppBundle()); |
| 102 #endif |
96 return std::string(product_dir_name); | 103 return std::string(product_dir_name); |
97 } | 104 } |
98 | 105 |
| 106 bool GetDefaultUserDataDirectoryForProduct(const std::string& product_dir, |
| 107 base::FilePath* result) { |
| 108 bool success = false; |
| 109 if (result && PathService::Get(base::DIR_APP_DATA, result)) { |
| 110 *result = result->Append(product_dir); |
| 111 success = true; |
| 112 } |
| 113 return success; |
| 114 } |
| 115 |
99 } // namespace | 116 } // namespace |
100 | 117 |
101 namespace chrome { | 118 namespace chrome { |
102 | 119 |
103 bool GetDefaultUserDataDirectory(base::FilePath* result) { | 120 bool GetDefaultUserDataDirectory(base::FilePath* result) { |
104 bool success = false; | 121 return GetDefaultUserDataDirectoryForProduct(ProductDirName(), result); |
105 if (result && PathService::Get(base::DIR_APP_DATA, result)) { | |
106 *result = result->Append(ProductDirName()); | |
107 success = true; | |
108 } | |
109 return success; | |
110 } | 122 } |
111 | 123 |
112 bool GetUserDocumentsDirectory(base::FilePath* result) { | 124 bool GetUserDocumentsDirectory(base::FilePath* result) { |
113 return base::mac::GetUserDirectory(NSDocumentDirectory, result); | 125 return base::mac::GetUserDirectory(NSDocumentDirectory, result); |
114 } | 126 } |
115 | 127 |
116 void GetUserCacheDirectory(const base::FilePath& profile_dir, | 128 void GetUserCacheDirectory(const base::FilePath& profile_dir, |
117 base::FilePath* result) { | 129 base::FilePath* result) { |
118 // If the profile directory is under ~/Library/Application Support, | 130 // If the profile directory is under ~/Library/Application Support, |
119 // use a suitable cache directory under ~/Library/Caches. For | 131 // use a suitable cache directory under ~/Library/Caches. For |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return base::mac::GetLocalDirectory(NSApplicationSupportDirectory, result); | 223 return base::mac::GetLocalDirectory(NSApplicationSupportDirectory, result); |
212 } | 224 } |
213 | 225 |
214 NSBundle* OuterAppBundle() { | 226 NSBundle* OuterAppBundle() { |
215 // Cache this. Foundation leaks it anyway, and this should be the only call | 227 // Cache this. Foundation leaks it anyway, and this should be the only call |
216 // to OuterAppBundleInternal(). | 228 // to OuterAppBundleInternal(). |
217 static NSBundle* bundle = OuterAppBundleInternal(); | 229 static NSBundle* bundle = OuterAppBundleInternal(); |
218 return bundle; | 230 return bundle; |
219 } | 231 } |
220 | 232 |
| 233 bool GetUserDataDirectoryForBrowserBundle(NSBundle* bundle, |
| 234 base::FilePath* result) { |
| 235 scoped_ptr_malloc<char> product_dir_name(ProductDirNameForBundle(bundle)); |
| 236 return GetDefaultUserDataDirectoryForProduct(product_dir_name.get(), result); |
| 237 } |
| 238 |
221 #endif // !defined(OS_IOS) | 239 #endif // !defined(OS_IOS) |
222 | 240 |
223 bool ProcessNeedsProfileDir(const std::string& process_type) { | 241 bool ProcessNeedsProfileDir(const std::string& process_type) { |
224 // For now we have no reason to forbid this on other MacOS as we don't | 242 // For now we have no reason to forbid this on other MacOS as we don't |
225 // have the roaming profile troubles there. | 243 // have the roaming profile troubles there. |
226 return true; | 244 return true; |
227 } | 245 } |
228 | 246 |
229 } // namespace chrome | 247 } // namespace chrome |
OLD | NEW |