Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1603)

Side by Side Diff: chrome/common/chrome_paths_mac.mm

Issue 12663023: [mac] Make app shims look in the correct user data dir on Canary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // 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.
45 base::FilePath versioned_dir = chrome::GetVersionedDirectory(); 45 base::FilePath versioned_dir = chrome::GetVersionedDirectory();
46 base::FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName(); 46 base::FilePath outer_app_dir = versioned_dir.DirName().DirName().DirName();
47 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();
48 NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c]; 48 NSString* outer_app_dir_ns = [NSString stringWithUTF8String:outer_app_dir_c];
49 49
50 return [[NSBundle bundleWithPath:outer_app_dir_ns] retain]; 50 return [[NSBundle bundleWithPath:outer_app_dir_ns] retain];
51 } 51 }
52 #endif // !defined(OS_IOS) 52 #endif // !defined(OS_IOS)
53 53
54 const char* ProductDirNameInternal() { 54 char* ProductDirNameForBundle(NSBundle* chrome_bundle) {
55 const char* product_dir_name = NULL; 55 const char* product_dir_name = NULL;
56 #if !defined(OS_IOS) 56 #if !defined(OS_IOS)
57 base::mac::ScopedNSAutoreleasePool pool; 57 base::mac::ScopedNSAutoreleasePool pool;
58 58
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 = 59 NSString* product_dir_name_ns =
70 [bundle objectForInfoDictionaryKey:@"CrProductDirName"]; 60 [chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"];
71 product_dir_name = [product_dir_name_ns fileSystemRepresentation]; 61 product_dir_name = [product_dir_name_ns fileSystemRepresentation];
72 #endif 62 #endif
Mark Mentovai 2013/04/03 17:52:01 #else DCHECK(!chrome_bundle) to ensure that nobod
73 63
74 if (!product_dir_name) { 64 if (!product_dir_name) {
75 #if defined(GOOGLE_CHROME_BUILD) 65 #if defined(GOOGLE_CHROME_BUILD)
76 product_dir_name = "Google/Chrome"; 66 product_dir_name = "Google/Chrome";
77 #else 67 #else
78 product_dir_name = "Chromium"; 68 product_dir_name = "Chromium";
79 #endif 69 #endif
80 } 70 }
81 71
82 // Leaked, but the only caller initializes a static with this result, so it 72 // Leaked, but the only caller initializes a static with this result, so it
83 // only happens once, and that's OK. 73 // only happens once, and that's OK.
84 return strdup(product_dir_name); 74 return strdup(product_dir_name);
85 } 75 }
86 76
87 // ProductDirName returns the name of the directory inside 77 // ProductDirName returns the name of the directory inside
88 // ~/Library/Application Support that should hold the product application 78 // ~/Library/Application Support that should hold the product application
89 // data. This can be overridden by setting the CrProductDirName key in the 79 // 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 80 // outer browser .app's Info.plist. The default is "Google/Chrome" for
91 // officially-branded builds, and "Chromium" for unbranded builds. For the 81 // officially-branded builds, and "Chromium" for unbranded builds. For the
92 // official canary channel, the Info.plist will have CrProductDirName set 82 // official canary channel, the Info.plist will have CrProductDirName set
93 // to "Google/Chrome Canary". 83 // to "Google/Chrome Canary".
94 std::string ProductDirName() { 84 std::string ProductDirName() {
95 static const char* product_dir_name = ProductDirNameInternal(); 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
89 // 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
91 // differences between channels within the versioned directory. This would
92 // normally use base::mac::FrameworkBundle(), but that references the
93 // framework bundle within the versioned directory. Ordinarily, the profile
94 // 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
96 // browser .app's Info.plist for the CrProductDirName key.
97 static const char* product_dir_name =
98 ProductDirNameForBundle(chrome::OuterAppBundle());
99 #endif
96 return std::string(product_dir_name); 100 return std::string(product_dir_name);
97 } 101 }
98 102
103 bool GetDefaultUserDataDirectoryForProduct(const std::string& product_dir,
104 base::FilePath* result) {
105 bool success = false;
106 if (result && PathService::Get(base::DIR_APP_DATA, result)) {
107 *result = result->Append(product_dir);
108 success = true;
109 }
110 return success;
111 }
112
99 } // namespace 113 } // namespace
100 114
101 namespace chrome { 115 namespace chrome {
102 116
103 bool GetDefaultUserDataDirectory(base::FilePath* result) { 117 bool GetDefaultUserDataDirectory(base::FilePath* result) {
104 bool success = false; 118 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 } 119 }
111 120
112 bool GetUserDocumentsDirectory(base::FilePath* result) { 121 bool GetUserDocumentsDirectory(base::FilePath* result) {
113 return base::mac::GetUserDirectory(NSDocumentDirectory, result); 122 return base::mac::GetUserDirectory(NSDocumentDirectory, result);
114 } 123 }
115 124
116 void GetUserCacheDirectory(const base::FilePath& profile_dir, 125 void GetUserCacheDirectory(const base::FilePath& profile_dir,
117 base::FilePath* result) { 126 base::FilePath* result) {
118 // If the profile directory is under ~/Library/Application Support, 127 // If the profile directory is under ~/Library/Application Support,
119 // use a suitable cache directory under ~/Library/Caches. For 128 // use a suitable cache directory under ~/Library/Caches. For
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return base::mac::GetLocalDirectory(NSApplicationSupportDirectory, result); 220 return base::mac::GetLocalDirectory(NSApplicationSupportDirectory, result);
212 } 221 }
213 222
214 NSBundle* OuterAppBundle() { 223 NSBundle* OuterAppBundle() {
215 // Cache this. Foundation leaks it anyway, and this should be the only call 224 // Cache this. Foundation leaks it anyway, and this should be the only call
216 // to OuterAppBundleInternal(). 225 // to OuterAppBundleInternal().
217 static NSBundle* bundle = OuterAppBundleInternal(); 226 static NSBundle* bundle = OuterAppBundleInternal();
218 return bundle; 227 return bundle;
219 } 228 }
220 229
230 bool GetUserDataDirectoryForBrowserBundle(
231 NSBundle* bundle, base::FilePath* result) {
Mark Mentovai 2013/04/03 17:52:01 Same thing with the wrapping on this line.
232 scoped_ptr_malloc<char> product_dir_name = ProductDirNameForBundle(bundle);
233 return GetDefaultUserDataDirectoryForProduct(product_dir_name.get(), result);
234 }
235
221 #endif // !defined(OS_IOS) 236 #endif // !defined(OS_IOS)
222 237
223 bool ProcessNeedsProfileDir(const std::string& process_type) { 238 bool ProcessNeedsProfileDir(const std::string& process_type) {
224 // For now we have no reason to forbid this on other MacOS as we don't 239 // For now we have no reason to forbid this on other MacOS as we don't
225 // have the roaming profile troubles there. 240 // have the roaming profile troubles there.
226 return true; 241 return true;
227 } 242 }
228 243
229 } // namespace chrome 244 } // namespace chrome
OLDNEW
« chrome/common/chrome_paths_internal.h ('K') | « chrome/common/chrome_paths_internal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698