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

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

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <string> 5 #include <string>
6 6
7 #include "net/base/platform_mime_util.h" 7 #include "net/base/platform_mime_util.h"
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/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 FilePath::StringType& ext, std::string* result) const { 15 const FilePath::StringType& ext, std::string* result) const {
16 // check windows registry for file extension's mime type (registry key 16 // check windows registry for file extension's mime type (registry key
17 // names are not case-sensitive). 17 // names are not case-sensitive).
18 std::wstring value, key = L"." + ext; 18 std::wstring value, key = L"." + ext;
19 base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue( 19 base::win::RegKey mime_key;
20 L"Content Type", &value); 20 LONG ret = mime_key.Open(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ);
grt (UTC plus 2) 2011/01/14 15:53:43 What's the benefit to making this code bigger like
amit 2011/01/15 01:28:11 reverted
21 if (ret == ERROR_SUCCESS)
22 ret = mime_key.ReadValue(L"Content Type", &value);
21 if (!value.empty()) { 23 if (!value.empty()) {
22 *result = WideToUTF8(value); 24 *result = WideToUTF8(value);
23 return true; 25 return true;
24 } 26 }
25 return false; 27 return false;
26 } 28 }
27 29
28 bool PlatformMimeUtil::GetPreferredExtensionForMimeType( 30 bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
29 const std::string& mime_type, FilePath::StringType* ext) const { 31 const std::string& mime_type, FilePath::StringType* ext) const {
30 std::wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type)); 32 std::wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type));
31 if (!base::win::RegKey(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ).ReadValue( 33 base::win::RegKey extension_key;
32 L"Extension", ext)) { 34 LONG ret = extension_key.Open(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ);
35 if (ret == ERROR_SUCCESS)
grt (UTC plus 2) 2011/01/14 15:53:43 Same comment.
amit 2011/01/15 01:28:11 Done.
36 ret = extension_key.ReadValue(L"Extension", ext);
37 if (ret != ERROR_SUCCESS) {
33 return false; 38 return false;
34 } 39 }
35 // Strip off the leading dot, this should always be the case. 40 // Strip off the leading dot, this should always be the case.
36 if (!ext->empty() && ext->at(0) == L'.') 41 if (!ext->empty() && ext->at(0) == L'.')
37 ext->erase(ext->begin()); 42 ext->erase(ext->begin());
38 43
39 return true; 44 return true;
40 } 45 }
41 46
42 } // namespace net 47 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698