Chromium Code Reviews

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

Issue 3855001: Move scoped_cftyperef from base to base/mac, use the new namespace, and name ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « net/base/network_config_watcher_mac.cc ('k') | net/base/ssl_config_service_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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <CoreServices/CoreServices.h> 5 #include <CoreServices/CoreServices.h>
6 #include <string> 6 #include <string>
7 7
8 #include "base/scoped_cftyperef.h" 8 #include "base/mac/scoped_cftyperef.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "net/base/platform_mime_util.h" 10 #include "net/base/platform_mime_util.h"
11 11
12 namespace net { 12 namespace net {
13 13
14 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( 14 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
15 const FilePath::StringType& ext, std::string* result) const { 15 const FilePath::StringType& ext, std::string* result) const {
16 std::string ext_nodot = ext; 16 std::string ext_nodot = ext;
17 if (ext_nodot.length() >= 1 && ext_nodot[0] == L'.') 17 if (ext_nodot.length() >= 1 && ext_nodot[0] == L'.')
18 ext_nodot.erase(ext_nodot.begin()); 18 ext_nodot.erase(ext_nodot.begin());
19 scoped_cftyperef<CFStringRef> ext_ref(base::SysUTF8ToCFStringRef(ext_nodot)); 19 base::mac::ScopedCFTypeRef<CFStringRef> ext_ref(
20 base::SysUTF8ToCFStringRef(ext_nodot));
20 if (!ext_ref) 21 if (!ext_ref)
21 return false; 22 return false;
22 scoped_cftyperef<CFStringRef> uti( 23 base::mac::ScopedCFTypeRef<CFStringRef> uti(
23 UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, 24 UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
24 ext_ref, 25 ext_ref,
25 NULL)); 26 NULL));
26 if (!uti) 27 if (!uti)
27 return false; 28 return false;
28 scoped_cftyperef<CFStringRef> mime_ref( 29 base::mac::ScopedCFTypeRef<CFStringRef> mime_ref(
29 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)); 30 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
30 if (!mime_ref) 31 if (!mime_ref)
31 return false; 32 return false;
32 33
33 *result = base::SysCFStringRefToUTF8(mime_ref); 34 *result = base::SysCFStringRefToUTF8(mime_ref);
34 return true; 35 return true;
35 } 36 }
36 37
37 bool PlatformMimeUtil::GetPreferredExtensionForMimeType( 38 bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
38 const std::string& mime_type, FilePath::StringType* ext) const { 39 const std::string& mime_type, FilePath::StringType* ext) const {
39 scoped_cftyperef<CFStringRef> mime_ref(base::SysUTF8ToCFStringRef(mime_type)); 40 base::mac::ScopedCFTypeRef<CFStringRef> mime_ref(
41 base::SysUTF8ToCFStringRef(mime_type));
40 if (!mime_ref) 42 if (!mime_ref)
41 return false; 43 return false;
42 scoped_cftyperef<CFStringRef> uti( 44 base::mac::ScopedCFTypeRef<CFStringRef> uti(
43 UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, 45 UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType,
44 mime_ref, 46 mime_ref,
45 NULL)); 47 NULL));
46 if (!uti) 48 if (!uti)
47 return false; 49 return false;
48 scoped_cftyperef<CFStringRef> ext_ref( 50 base::mac::ScopedCFTypeRef<CFStringRef> ext_ref(
49 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension)); 51 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension));
50 if (!ext_ref) 52 if (!ext_ref)
51 return false; 53 return false;
52 54
53 *ext = base::SysCFStringRefToUTF8(ext_ref); 55 *ext = base::SysCFStringRefToUTF8(ext_ref);
54 return true; 56 return true;
55 } 57 }
56 58
57 } // namespace net 59 } // namespace net
OLDNEW
« no previous file with comments | « net/base/network_config_watcher_mac.cc ('k') | net/base/ssl_config_service_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine