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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 "net/base/platform_mime_util.h" 5 #include "net/base/platform_mime_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/win/registry.h" 10 #include "base/win/registry.h"
11 11
12 namespace net { 12 namespace net {
13 13
14 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( 14 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
15 const base::FilePath::StringType& ext, std::string* result) const { 15 const base::FilePath::StringType& ext,
16 std::string* result) const {
16 // check windows registry for file extension's mime type (registry key 17 // check windows registry for file extension's mime type (registry key
17 // names are not case-sensitive). 18 // names are not case-sensitive).
18 std::wstring value, key = L"." + ext; 19 std::wstring value, key = L"." + ext;
19 base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue( 20 base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ)
20 L"Content Type", &value); 21 .ReadValue(L"Content Type", &value);
21 if (!value.empty()) { 22 if (!value.empty()) {
22 *result = base::WideToUTF8(value); 23 *result = base::WideToUTF8(value);
23 return true; 24 return true;
24 } 25 }
25 return false; 26 return false;
26 } 27 }
27 28
28 bool PlatformMimeUtil::GetPreferredExtensionForMimeType( 29 bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
29 const std::string& mime_type, base::FilePath::StringType* ext) const { 30 const std::string& mime_type,
30 std::wstring key( 31 base::FilePath::StringType* ext) const {
31 L"MIME\\Database\\Content Type\\" + base::UTF8ToWide(mime_type)); 32 std::wstring key(L"MIME\\Database\\Content Type\\" +
32 if (base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue( 33 base::UTF8ToWide(mime_type));
33 L"Extension", ext) != ERROR_SUCCESS) { 34 if (base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ)
35 .ReadValue(L"Extension", ext) != ERROR_SUCCESS) {
34 return false; 36 return false;
35 } 37 }
36 // Strip off the leading dot, this should always be the case. 38 // Strip off the leading dot, this should always be the case.
37 if (!ext->empty() && ext->at(0) == L'.') 39 if (!ext->empty() && ext->at(0) == L'.')
38 ext->erase(ext->begin()); 40 ext->erase(ext->begin());
39 41
40 return true; 42 return true;
41 } 43 }
42 44
43 void PlatformMimeUtil::GetPlatformExtensionsForMimeType( 45 void PlatformMimeUtil::GetPlatformExtensionsForMimeType(
44 const std::string& mime_type, 46 const std::string& mime_type,
45 base::hash_set<base::FilePath::StringType>* extensions) const { 47 base::hash_set<base::FilePath::StringType>* extensions) const {
46 // Multiple extensions could have the given mime type specified as their types 48 // Multiple extensions could have the given mime type specified as their types
47 // in their 'HKCR\.<extension>\Content Type' keys. Iterating all the HKCR 49 // in their 'HKCR\.<extension>\Content Type' keys. Iterating all the HKCR
48 // entries, though, is wildly impractical. Cheat by returning just the 50 // entries, though, is wildly impractical. Cheat by returning just the
49 // preferred extension. 51 // preferred extension.
50 base::FilePath::StringType ext; 52 base::FilePath::StringType ext;
51 if (GetPreferredExtensionForMimeType(mime_type, &ext)) 53 if (GetPreferredExtensionForMimeType(mime_type, &ext))
52 extensions->insert(ext); 54 extensions->insert(ext);
53 } 55 }
54 56
55 } // namespace net 57 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698