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

Side by Side Diff: base/mac/foundation_util.mm

Issue 10823157: Prettify Mac names, rewrite getDisplayPath API call to focus on $HOME (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: comment Created 8 years, 3 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
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 "base/mac/foundation_util.h" 5 #include "base/mac/foundation_util.h"
6 #include "base/mac/mac_util.h"
6 7
7 #include <stdlib.h> 8 #include <stdlib.h>
8 #include <string.h> 9 #include <string.h>
9 10
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/mac/bundle_locations.h" 13 #include "base/mac/bundle_locations.h"
13 #include "base/mac/mac_logging.h" 14 #include "base/mac/mac_logging.h"
14 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
15 16
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 122 }
122 123
123 bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) { 124 bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) {
124 return GetSearchPathDirectory(directory, NSLocalDomainMask, result); 125 return GetSearchPathDirectory(directory, NSLocalDomainMask, result);
125 } 126 }
126 127
127 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) { 128 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) {
128 return GetSearchPathDirectory(directory, NSUserDomainMask, result); 129 return GetSearchPathDirectory(directory, NSUserDomainMask, result);
129 } 130 }
130 131
132 std::string GetDisplayBaseName(const FilePath& path) {
133 FSRef ref;
134 if (!FSRefFromPath(path.value(), &ref))
Nico 2012/09/04 14:09:37 Can you use a CFURL instead of a FSRef?
thorogood 2012/09/06 00:16:53 It seems like I could, e.g.: [NSURL fileURLWithPat
Nico 2012/09/06 00:22:28 FSRef is a very old type, and NSURL is what Apple
thorogood 2012/09/06 04:42:37 Turns out it's now reasonably more verbose, both t
135 return path.BaseName().value();
136
137 CFStringRef str;
138 if (LSCopyDisplayNameForRef(&ref, &str) != noErr)
139 return path.BaseName().value();
140
141 std::string result(base::SysCFStringRefToUTF8(str));
142 NSObjectRelease((void *) str);
Nico 2012/09/04 14:09:37 CFRelease
thorogood 2012/09/06 00:16:53 Done.
143 return result;
144 }
145
131 FilePath GetUserLibraryPath() { 146 FilePath GetUserLibraryPath() {
132 FilePath user_library_path; 147 FilePath user_library_path;
133 if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) { 148 if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) {
134 DLOG(WARNING) << "Could not get user library path"; 149 DLOG(WARNING) << "Could not get user library path";
135 } 150 }
136 return user_library_path; 151 return user_library_path;
137 } 152 }
138 153
139 // Takes a path to an (executable) binary and tries to provide the path to an 154 // Takes a path to an (executable) binary and tries to provide the path to an
140 // application bundle containing it. It takes the outermost bundle that it can 155 // application bundle containing it. It takes the outermost bundle that it can
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 403 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
389 } 404 }
390 o << "Code: " << CFErrorGetCode(err) 405 o << "Code: " << CFErrorGetCode(err)
391 << " Domain: " << CFErrorGetDomain(err) 406 << " Domain: " << CFErrorGetDomain(err)
392 << " Desc: " << desc.get(); 407 << " Desc: " << desc.get();
393 if(errorDesc) { 408 if(errorDesc) {
394 o << "(" << errorDesc << ")"; 409 o << "(" << errorDesc << ")";
395 } 410 }
396 return o; 411 return o;
397 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698