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

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: Created 7 years, 9 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* ProductDirNameInternal(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 59 // Use OuterAppBundle() to get the main app's bundle. This key needs to live
jeremy 2013/03/24 14:17:13 Can you please update this comment?
jeremya 2013/04/01 23:30:22 Moved it to where the call to OuterAppBundle went.
60 // 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
61 // channel, and the autoupdate system dictates that there can be no 61 // channel, and the autoupdate system dictates that there can be no
62 // differences between channels within the versioned directory. This would 62 // differences between channels within the versioned directory. This would
63 // normally use base::mac::FrameworkBundle(), but that references the 63 // normally use base::mac::FrameworkBundle(), but that references the
64 // framework bundle within the versioned directory. Ordinarily, the profile 64 // framework bundle within the versioned directory. Ordinarily, the profile
65 // 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
66 // 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
67 // browser .app's Info.plist for the CrProductDirName key. 67 // browser .app's Info.plist for the CrProductDirName key.
68 NSBundle* bundle = chrome::OuterAppBundle();
69 NSString* product_dir_name_ns = 68 NSString* product_dir_name_ns =
70 [bundle objectForInfoDictionaryKey:@"CrProductDirName"]; 69 [chrome_bundle objectForInfoDictionaryKey:@"CrProductDirName"];
71 product_dir_name = [product_dir_name_ns fileSystemRepresentation]; 70 product_dir_name = [product_dir_name_ns fileSystemRepresentation];
72 #endif 71 #endif
73 72
74 if (!product_dir_name) { 73 if (!product_dir_name) {
75 #if defined(GOOGLE_CHROME_BUILD) 74 #if defined(GOOGLE_CHROME_BUILD)
76 product_dir_name = "Google/Chrome"; 75 product_dir_name = "Google/Chrome";
77 #else 76 #else
78 product_dir_name = "Chromium"; 77 product_dir_name = "Chromium";
79 #endif 78 #endif
80 } 79 }
81 80
82 // Leaked, but the only caller initializes a static with this result, so it 81 // Leaked, but the only caller initializes a static with this result, so it
83 // only happens once, and that's OK. 82 // only happens once, and that's OK.
84 return strdup(product_dir_name); 83 return strdup(product_dir_name);
85 } 84 }
86 85
87 // ProductDirName returns the name of the directory inside 86 // ProductDirName returns the name of the directory inside
88 // ~/Library/Application Support that should hold the product application 87 // ~/Library/Application Support that should hold the product application
89 // data. This can be overridden by setting the CrProductDirName key in the 88 // 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 89 // outer browser .app's Info.plist. The default is "Google/Chrome" for
91 // officially-branded builds, and "Chromium" for unbranded builds. For the 90 // officially-branded builds, and "Chromium" for unbranded builds. For the
92 // official canary channel, the Info.plist will have CrProductDirName set 91 // official canary channel, the Info.plist will have CrProductDirName set
93 // to "Google/Chrome Canary". 92 // to "Google/Chrome Canary".
94 std::string ProductDirName() { 93 std::string ProductDirName() {
95 static const char* product_dir_name = ProductDirNameInternal(); 94 #if defined(OS_IOS)
95 static const char* product_dir_name = ProductDirNameInternal(nil);
96 #else
97 static const char* product_dir_name =
98 ProductDirNameInternal(chrome::OuterAppBundle());
99 #endif
96 return std::string(product_dir_name); 100 return std::string(product_dir_name);
97 } 101 }
98 102
99 } // namespace 103 } // namespace
100 104
101 namespace chrome { 105 namespace chrome {
102 106
103 bool GetDefaultUserDataDirectory(base::FilePath* result) { 107 bool GetDefaultUserDataDirectoryForProduct(const std::string& product_dir,
Mark Mentovai 2013/03/22 18:08:41 This belongs in the anonymous namespace a few line
jeremya 2013/04/01 23:30:22 Done.
108 base::FilePath* result) {
104 bool success = false; 109 bool success = false;
105 if (result && PathService::Get(base::DIR_APP_DATA, result)) { 110 if (result && PathService::Get(base::DIR_APP_DATA, result)) {
106 *result = result->Append(ProductDirName()); 111 *result = result->Append(product_dir);
107 success = true; 112 success = true;
108 } 113 }
109 return success; 114 return success;
110 } 115 }
111 116
117 bool GetDefaultUserDataDirectory(base::FilePath* result) {
118 return GetDefaultUserDataDirectoryForProduct(ProductDirName(), result);
119 }
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
120 // example, a profile directory of ~/Library/Application 129 // example, a profile directory of ~/Library/Application
121 // Support/Google/Chrome/MyProfileName would use the cache directory 130 // Support/Google/Chrome/MyProfileName would use the cache directory
(...skipping 89 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 GetUserDataDirectoryForBundle(NSBundle* bundle, base::FilePath* result) {
231 char* product_dir_name = ProductDirNameInternal(bundle);
Mark Mentovai 2013/03/22 18:08:41 I don’t like calling *Internal functions from some
Mark Mentovai 2013/03/22 18:08:41 You can stick the result into a scoped_ptr_malloc
jeremya 2013/04/01 23:30:22 Done.
jeremya 2013/04/01 23:30:22 Done.
232 bool success =
233 GetDefaultUserDataDirectoryForProduct(product_dir_name, result);
234 // ProductDirNameInternal() returns a strdup()'d string, so clean it up here.
235 free(static_cast<void*>(product_dir_name));
236 return success;
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
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