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

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

Issue 8540021: Create a nicer interface for base::mac::GetValueFromDictionary (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: COMPILE_ASSERT the arraysizes Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
14 13
15 namespace base { 14 namespace base {
16 namespace mac { 15 namespace mac {
17 16
18 static bool g_override_am_i_bundled = false; 17 static bool g_override_am_i_bundled = false;
19 static bool g_override_am_i_bundled_value = false; 18 static bool g_override_am_i_bundled_value = false;
20 19
21 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled 20 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
22 static bool UncachedAmIBundled() { 21 static bool UncachedAmIBundled() {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength)) 192 !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
194 return FilePath(bundle_name); 193 return FilePath(bundle_name);
195 194
196 // Separate this component from the next one. 195 // Separate this component from the next one.
197 bundle_name += '/'; 196 bundle_name += '/';
198 } 197 }
199 198
200 return FilePath(); 199 return FilePath();
201 } 200 }
202 201
202 std::string GetValueFromDictionaryErrorMessage(CFStringRef key,
203 CFStringRef expected_type_ref,
204 CFTypeRef value) {
205 ScopedCFTypeRef<CFStringRef> actual_type_ref(
206 CFCopyTypeIDDescription(CFGetTypeID(value)));
207 return "Expected value for key "
Mark Mentovai 2011/11/13 01:28:22 http://dev.chromium.org/developers/coding-style#TO
208 + base::SysCFStringRefToUTF8(key)
209 + " to be "
210 + base::SysCFStringRefToUTF8(expected_type_ref)
211 + " but it was "
212 + base::SysCFStringRefToUTF8(actual_type_ref)
213 + " instead";
214 }
215
203 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, 216 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
204 CFStringRef key, 217 CFStringRef key,
205 CFTypeID expected_type) { 218 CFTypeID expected_type) {
206 CFTypeRef value = CFDictionaryGetValue(dict, key); 219 CFTypeRef value = CFDictionaryGetValue(dict, key);
207 if (!value) 220 if (!value)
208 return value; 221 return value;
209 222
210 if (CFGetTypeID(value) != expected_type) { 223 if (CFGetTypeID(value) != expected_type) {
211 ScopedCFTypeRef<CFStringRef> expected_type_ref( 224 ScopedCFTypeRef<CFStringRef> expected_type_ref(
212 CFCopyTypeIDDescription(expected_type)); 225 CFCopyTypeIDDescription(expected_type));
Mark Mentovai 2011/11/13 01:28:22 Why did you change the correct four-space indent o
KushalP 2011/11/13 12:30:27 I'm not entirely sure. I must have done it manuall
213 ScopedCFTypeRef<CFStringRef> actual_type_ref( 226 DLOG(WARNING) << GetValueFromDictionaryErrorMessage(key,
214 CFCopyTypeIDDescription(CFGetTypeID(value))); 227 expected_type_ref,
215 DLOG(WARNING) << "Expected value for key " 228 value);
216 << base::SysCFStringRefToUTF8(key)
217 << " to be "
218 << base::SysCFStringRefToUTF8(expected_type_ref)
219 << " but it was "
220 << base::SysCFStringRefToUTF8(actual_type_ref)
221 << " instead";
222 return NULL; 229 return NULL;
223 } 230 }
224 231
225 return value; 232 return value;
226 } 233 }
227 234
228 void NSObjectRetain(void* obj) { 235 void NSObjectRetain(void* obj) {
229 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); 236 id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
230 [nsobj retain]; 237 [nsobj retain];
231 } 238 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 372 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
366 } 373 }
367 o << "Code: " << CFErrorGetCode(err) 374 o << "Code: " << CFErrorGetCode(err)
368 << " Domain: " << CFErrorGetDomain(err) 375 << " Domain: " << CFErrorGetDomain(err)
369 << " Desc: " << desc.get(); 376 << " Desc: " << desc.get();
370 if(errorDesc) { 377 if(errorDesc) {
371 o << "(" << errorDesc << ")"; 378 o << "(" << errorDesc << ")";
372 } 379 }
373 return o; 380 return o;
374 } 381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698