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

Side by Side Diff: net/base/platform_mime_util_mac.mm

Issue 16917011: mac: Replace base::mac::ScopedCFTypeRef with base::ScopedCFTypeRef. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with fixed off-by-1 in git-clang-format Created 7 years, 6 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
« no previous file with comments | « net/base/network_config_watcher_mac.cc ('k') | net/cert/cert_verify_proc_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/base/platform_mime_util.h" 5 #include "net/base/platform_mime_util.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 18 matching lines...) Expand all
29 @end 29 @end
30 #endif // !defined(OS_IOS) 30 #endif // !defined(OS_IOS)
31 31
32 namespace net { 32 namespace net {
33 33
34 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( 34 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
35 const base::FilePath::StringType& ext, std::string* result) const { 35 const base::FilePath::StringType& ext, std::string* result) const {
36 std::string ext_nodot = ext; 36 std::string ext_nodot = ext;
37 if (ext_nodot.length() >= 1 && ext_nodot[0] == L'.') 37 if (ext_nodot.length() >= 1 && ext_nodot[0] == L'.')
38 ext_nodot.erase(ext_nodot.begin()); 38 ext_nodot.erase(ext_nodot.begin());
39 base::mac::ScopedCFTypeRef<CFStringRef> ext_ref( 39 base::ScopedCFTypeRef<CFStringRef> ext_ref(
40 base::SysUTF8ToCFStringRef(ext_nodot)); 40 base::SysUTF8ToCFStringRef(ext_nodot));
41 if (!ext_ref) 41 if (!ext_ref)
42 return false; 42 return false;
43 base::mac::ScopedCFTypeRef<CFStringRef> uti( 43 base::ScopedCFTypeRef<CFStringRef> uti(UTTypeCreatePreferredIdentifierForTag(
44 UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, 44 kUTTagClassFilenameExtension, ext_ref, NULL));
45 ext_ref,
46 NULL));
47 if (!uti) 45 if (!uti)
48 return false; 46 return false;
49 base::mac::ScopedCFTypeRef<CFStringRef> mime_ref( 47 base::ScopedCFTypeRef<CFStringRef> mime_ref(
50 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)); 48 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
51 if (!mime_ref) 49 if (!mime_ref)
52 return false; 50 return false;
53 51
54 *result = base::SysCFStringRefToUTF8(mime_ref); 52 *result = base::SysCFStringRefToUTF8(mime_ref);
55 return true; 53 return true;
56 } 54 }
57 55
58 bool PlatformMimeUtil::GetPreferredExtensionForMimeType( 56 bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
59 const std::string& mime_type, base::FilePath::StringType* ext) const { 57 const std::string& mime_type, base::FilePath::StringType* ext) const {
60 base::mac::ScopedCFTypeRef<CFStringRef> mime_ref( 58 base::ScopedCFTypeRef<CFStringRef> mime_ref(
61 base::SysUTF8ToCFStringRef(mime_type)); 59 base::SysUTF8ToCFStringRef(mime_type));
62 if (!mime_ref) 60 if (!mime_ref)
63 return false; 61 return false;
64 base::mac::ScopedCFTypeRef<CFStringRef> uti( 62 base::ScopedCFTypeRef<CFStringRef> uti(UTTypeCreatePreferredIdentifierForTag(
65 UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, 63 kUTTagClassMIMEType, mime_ref, NULL));
66 mime_ref,
67 NULL));
68 if (!uti) 64 if (!uti)
69 return false; 65 return false;
70 base::mac::ScopedCFTypeRef<CFStringRef> ext_ref( 66 base::ScopedCFTypeRef<CFStringRef> ext_ref(
71 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension)); 67 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension));
72 if (!ext_ref) 68 if (!ext_ref)
73 return false; 69 return false;
74 70
75 *ext = base::SysCFStringRefToUTF8(ext_ref); 71 *ext = base::SysCFStringRefToUTF8(ext_ref);
76 return true; 72 return true;
77 } 73 }
78 74
79 void PlatformMimeUtil::GetPlatformExtensionsForMimeType( 75 void PlatformMimeUtil::GetPlatformExtensionsForMimeType(
80 const std::string& mime_type, 76 const std::string& mime_type,
(...skipping 20 matching lines...) Expand all
101 extensions->insert(base::SysNSStringToUTF8(extension)); 97 extensions->insert(base::SysNSStringToUTF8(extension));
102 } else { 98 } else {
103 // Huh? Give up. 99 // Huh? Give up.
104 base::FilePath::StringType ext; 100 base::FilePath::StringType ext;
105 if (GetPreferredExtensionForMimeType(mime_type, &ext)) 101 if (GetPreferredExtensionForMimeType(mime_type, &ext))
106 extensions->insert(ext); 102 extensions->insert(ext);
107 } 103 }
108 } 104 }
109 105
110 } // namespace net 106 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_config_watcher_mac.cc ('k') | net/cert/cert_verify_proc_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698