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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #import "base/mac/foundation_util.h" | 13 #import "base/mac/foundation_util.h" |
14 #import "base/mac/scoped_nsautorelease_pool.h" | 14 #import "base/mac/scoped_nsautorelease_pool.h" |
15 #include "base/memory/free_deleter.h" | 15 #include "base/memory/free_deleter.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
19 #include "chrome/common/chrome_paths_internal.h" | 19 #include "chrome/common/chrome_paths_internal.h" |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 #if !defined(OS_IOS) | |
24 const base::FilePath* g_override_versioned_directory = NULL; | 23 const base::FilePath* g_override_versioned_directory = NULL; |
25 | 24 |
26 // Return a retained (NOT autoreleased) NSBundle* as the internal | 25 // Return a retained (NOT autoreleased) NSBundle* as the internal |
27 // implementation of chrome::OuterAppBundle(), which should be the only | 26 // implementation of chrome::OuterAppBundle(), which should be the only |
28 // caller. | 27 // caller. |
29 NSBundle* OuterAppBundleInternal() { | 28 NSBundle* OuterAppBundleInternal() { |
30 base::mac::ScopedNSAutoreleasePool pool; | 29 base::mac::ScopedNSAutoreleasePool pool; |
31 | 30 |
32 if (!base::mac::AmIBundled()) { | 31 if (!base::mac::AmIBundled()) { |
33 // If unbundled (as in a test), there's no app bundle. | 32 // If unbundled (as in a test), there's no app bundle. |
34 return nil; | 33 return nil; |
35 } | 34 } |
36 | 35 |
37 if (!base::mac::IsBackgroundOnlyProcess()) { | 36 if (!base::mac::IsBackgroundOnlyProcess()) { |
38 // Shortcut: in the browser process, just return the main app bundle. | 37 // Shortcut: in the browser process, just return the main app bundle. |
39 return [[NSBundle mainBundle] retain]; | 38 return [[NSBundle mainBundle] retain]; |
40 } | 39 } |
41 | 40 |
42 // From C.app/Contents/Versions/1.2.3.4, go up three steps to get to C.app. | 41 // From C.app/Contents/Versions/1.2.3.4, go up three steps to get to C.app. |
43 base::FilePath versioned_dir = chrome::GetVersionedDirectory(); | 42 base::FilePath versioned_dir = chrome::GetVersionedDirectory(); |
44 base::FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); | 43 base::FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); |
45 const char* outer_app_dir_c = outer_app_dir.value().c_str(); | 44 const char* outer_app_dir_c = outer_app_dir.value().c_str(); |
46 NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; | 45 NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; |
47 | 46 |
48 return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; | 47 return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; |
49 } | 48 } |
50 #endif // !defined(OS_IOS) | |
51 | 49 |
52 char* ProductDirNameForBundle(NSBundle* chrome_bundle) { | 50 char* ProductDirNameForBundle(NSBundle* chrome_bundle) { |
53 const char* product_dir_name = NULL; | 51 const char* product_dir_name = NULL; |
54 #if !defined(OS_IOS) | |
55 base::mac::ScopedNSAutoreleasePool pool; | 52 base::mac::ScopedNSAutoreleasePool pool; |
56 | 53 |
57 NSString* product_dir_name_ns = | 54 NSString* product_dir_name_ns = |
58 [chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"]; | 55 [chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"]; |
59 product_dir_name = [product_dir_name_ns fileSystemRepresentation]; | 56 product_dir_name = [product_dir_name_ns fileSystemRepresentation]; |
60 #else | |
61 DCHECK(!chrome_bundle); | |
62 #endif | |
63 | 57 |
64 if (!product_dir_name) { | 58 if (!product_dir_name) { |
65 #if defined(GOOGLE_CHROME_BUILD) | 59 #if defined(GOOGLE_CHROME_BUILD) |
66 product_dir_name = "Google/Chrome"; | 60 product_dir_name = "Google/Chrome"; |
67 #else | 61 #else |
68 product_dir_name = "Chromium"; | 62 product_dir_name = "Chromium"; |
69 #endif | 63 #endif |
70 } | 64 } |
71 | 65 |
72 // Leaked, but the only caller initializes a static with this result, so it | 66 // Leaked, but the only caller initializes a static with this result, so it |
73 // only happens once, and that's OK. | 67 // only happens once, and that's OK. |
74 return strdup(product_dir_name); | 68 return strdup(product_dir_name); |
75 } | 69 } |
76 | 70 |
77 // ProductDirName returns the name of the directory inside | 71 // ProductDirName returns the name of the directory inside |
78 // ~/Library/Application Support that should hold the product application | 72 // ~/Library/Application Support that should hold the product application |
79 // data. This can be overridden by setting the CrProductDirName key in the | 73 // data. This can be overridden by setting the CrProductDirName key in the |
80 // outer browser .app's Info.plist. The default is "Google/Chrome" for | 74 // outer browser .app's Info.plist. The default is "Google/Chrome" for |
81 // officially-branded builds, and "Chromium" for unbranded builds. For the | 75 // officially-branded builds, and "Chromium" for unbranded builds. For the |
82 // official canary channel, the Info.plist will have CrProductDirName set | 76 // official canary channel, the Info.plist will have CrProductDirName set |
83 // to "Google/Chrome Canary". | 77 // to "Google/Chrome Canary". |
84 std::string ProductDirName() { | 78 std::string ProductDirName() { |
85 #if defined(OS_IOS) | |
86 static const char* product_dir_name = ProductDirNameForBundle(nil); | |
87 #else | |
88 // Use OuterAppBundle() to get the main app's bundle. This key needs to live | 79 // Use OuterAppBundle() to get the main app's bundle. This key needs to live |
89 // in the main app's bundle because it will be set differently on the canary | 80 // in the main app's bundle because it will be set differently on the canary |
90 // channel, and the autoupdate system dictates that there can be no | 81 // channel, and the autoupdate system dictates that there can be no |
91 // differences between channels within the versioned directory. This would | 82 // differences between channels within the versioned directory. This would |
92 // normally use base::mac::FrameworkBundle(), but that references the | 83 // normally use base::mac::FrameworkBundle(), but that references the |
93 // framework bundle within the versioned directory. Ordinarily, the profile | 84 // framework bundle within the versioned directory. Ordinarily, the profile |
94 // should not be accessed from non-browser processes, but those processes do | 85 // should not be accessed from non-browser processes, but those processes do |
95 // attempt to get the profile directory, so direct them to look in the outer | 86 // attempt to get the profile directory, so direct them to look in the outer |
96 // browser .app's Info.plist for the CrProductDirName key. | 87 // browser .app's Info.plist for the CrProductDirName key. |
97 static const char* product_dir_name = | 88 static const char* product_dir_name = |
98 ProductDirNameForBundle(chrome::OuterAppBundle()); | 89 ProductDirNameForBundle(chrome::OuterAppBundle()); |
99 #endif | |
100 return std::string(product_dir_name); | 90 return std::string(product_dir_name); |
101 } | 91 } |
102 | 92 |
103 bool GetDefaultUserDataDirectoryForProduct(const std::string& product_dir, | 93 bool GetDefaultUserDataDirectoryForProduct(const std::string& product_dir, |
104 base::FilePath* result) { | 94 base::FilePath* result) { |
105 bool success = false; | 95 bool success = false; |
106 if (result && PathService::Get(base::DIR_APP_DATA, result)) { | 96 if (result && PathService::Get(base::DIR_APP_DATA, result)) { |
107 *result = result->Append(product_dir); | 97 *result = result->Append(product_dir); |
108 success = true; | 98 success = true; |
109 } | 99 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 144 } |
155 | 145 |
156 bool GetUserPicturesDirectory(base::FilePath* result) { | 146 bool GetUserPicturesDirectory(base::FilePath* result) { |
157 return base::mac::GetUserDirectory(NSPicturesDirectory, result); | 147 return base::mac::GetUserDirectory(NSPicturesDirectory, result); |
158 } | 148 } |
159 | 149 |
160 bool GetUserVideosDirectory(base::FilePath* result) { | 150 bool GetUserVideosDirectory(base::FilePath* result) { |
161 return base::mac::GetUserDirectory(NSMoviesDirectory, result); | 151 return base::mac::GetUserDirectory(NSMoviesDirectory, result); |
162 } | 152 } |
163 | 153 |
164 #if !defined(OS_IOS) | |
165 | |
166 base::FilePath GetVersionedDirectory() { | 154 base::FilePath GetVersionedDirectory() { |
167 if (g_override_versioned_directory) | 155 if (g_override_versioned_directory) |
168 return *g_override_versioned_directory; | 156 return *g_override_versioned_directory; |
169 | 157 |
170 // Start out with the path to the running executable. | 158 // Start out with the path to the running executable. |
171 base::FilePath path; | 159 base::FilePath path; |
172 PathService::Get(base::FILE_EXE, &path); | 160 PathService::Get(base::FILE_EXE, &path); |
173 | 161 |
174 // One step up to MacOS, another to Contents. | 162 // One step up to MacOS, another to Contents. |
175 path = path.DirName().DirName(); | 163 path = path.DirName().DirName(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 return bundle; | 215 return bundle; |
228 } | 216 } |
229 | 217 |
230 bool GetUserDataDirectoryForBrowserBundle(NSBundle* bundle, | 218 bool GetUserDataDirectoryForBrowserBundle(NSBundle* bundle, |
231 base::FilePath* result) { | 219 base::FilePath* result) { |
232 std::unique_ptr<char, base::FreeDeleter> product_dir_name( | 220 std::unique_ptr<char, base::FreeDeleter> product_dir_name( |
233 ProductDirNameForBundle(bundle)); | 221 ProductDirNameForBundle(bundle)); |
234 return GetDefaultUserDataDirectoryForProduct(product_dir_name.get(), result); | 222 return GetDefaultUserDataDirectoryForProduct(product_dir_name.get(), result); |
235 } | 223 } |
236 | 224 |
237 #endif // !defined(OS_IOS) | |
238 | |
239 bool ProcessNeedsProfileDir(const std::string& process_type) { | 225 bool ProcessNeedsProfileDir(const std::string& process_type) { |
240 // For now we have no reason to forbid this on other MacOS as we don't | 226 // For now we have no reason to forbid this on other MacOS as we don't |
241 // have the roaming profile troubles there. | 227 // have the roaming profile troubles there. |
242 return true; | 228 return true; |
243 } | 229 } |
244 | 230 |
245 } // namespace chrome | 231 } // namespace chrome |
OLD | NEW |