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

Side by Side Diff: chrome/browser/autofill/autofill_ie_toolbar_import_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 "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" 5 #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "chrome/browser/autofill/autofill_profile.h" 10 #include "chrome/browser/autofill/autofill_profile.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 for (size_t i = 0; i < salt.length(); ++i) { 50 for (size_t i = 0; i < salt.length(); ++i) {
51 if (salt[i] != i + 1) 51 if (salt[i] != i + 1)
52 return false; 52 return false;
53 } 53 }
54 return true; 54 return true;
55 } 55 }
56 56
57 string16 ReadAndDecryptValue(RegKey* key, const wchar_t* value_name) { 57 string16 ReadAndDecryptValue(RegKey* key, const wchar_t* value_name) {
58 DWORD data_type = REG_BINARY; 58 DWORD data_type = REG_BINARY;
59 DWORD data_size = 0; 59 DWORD data_size = 0;
60 if (!key->ReadValue(value_name, NULL, &data_size, &data_type) || 60 LONG result = key->ReadValue(value_name, NULL, &data_size, &data_type);
brettw 2011/01/10 20:42:28 In other places you didn't introduce the extra var
amit 2011/01/12 04:11:23 My logic was to directly check for ERROR_SUCCESS i
grt (UTC plus 2) 2011/01/12 15:06:38 FWIW, I think I spent more time trying to figure o
61 !data_size || data_type != REG_BINARY) 61 if ((result != ERROR_SUCCESS) || !data_size || data_type != REG_BINARY)
62 return string16(); 62 return string16();
63 std::vector<uint8> data; 63 std::vector<uint8> data;
64 data.resize(data_size); 64 data.resize(data_size);
65 if (key->ReadValue(value_name, &(data[0]), &data_size, &data_type)) { 65 result = key->ReadValue(value_name, &(data[0]), &data_size, &data_type);
66 if (result == ERROR_SUCCESS) {
66 std::string out_data; 67 std::string out_data;
67 if (DecryptData(data, &out_data)) { 68 if (DecryptData(data, &out_data)) {
68 // The actual data is in UTF16 already. 69 // The actual data is in UTF16 already.
69 if (!(out_data.size() & 1) && (out_data.size() > 2) && 70 if (!(out_data.size() & 1) && (out_data.size() > 2) &&
70 !out_data[out_data.size() - 1] && !out_data[out_data.size() - 2]) { 71 !out_data[out_data.size() - 1] && !out_data[out_data.size() - 2]) {
71 return string16( 72 return string16(
72 reinterpret_cast<const wchar_t *>(out_data.c_str())); 73 reinterpret_cast<const wchar_t *>(out_data.c_str()));
73 } 74 }
74 } 75 }
75 } 76 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 RegKey* key, 119 RegKey* key,
119 const RegToFieldMap& reg_to_field ) { 120 const RegToFieldMap& reg_to_field ) {
120 DCHECK(profile != NULL); 121 DCHECK(profile != NULL);
121 if (!key->Valid()) 122 if (!key->Valid())
122 return false; 123 return false;
123 124
124 bool has_non_empty_fields = false; 125 bool has_non_empty_fields = false;
125 126
126 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) { 127 for (uint32 value_index = 0; value_index < key->ValueCount(); ++value_index) {
127 std::wstring value_name; 128 std::wstring value_name;
128 if (!key->ReadName(value_index, &value_name)) 129 if (key->ReadName(value_index, &value_name) != ERROR_SUCCESS)
129 continue; 130 continue;
130 RegToFieldMap::const_iterator it = reg_to_field.find(value_name); 131 RegToFieldMap::const_iterator it = reg_to_field.find(value_name);
131 if (it == reg_to_field.end()) 132 if (it == reg_to_field.end())
132 continue; // This field is not imported. 133 continue; // This field is not imported.
133 string16 field_value = ReadAndDecryptValue(key, value_name.c_str()); 134 string16 field_value = ReadAndDecryptValue(key, value_name.c_str());
134 if (!field_value.empty()) { 135 if (!field_value.empty()) {
135 has_non_empty_fields = true; 136 has_non_empty_fields = true;
136 if (it->second == CREDIT_CARD_NUMBER) { 137 if (it->second == CREDIT_CARD_NUMBER) {
137 field_value = DecryptCCNumber(field_value); 138 field_value = DecryptCCNumber(field_value);
138 } 139 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 248 }
248 return (profiles->size() + credit_cards->size()) > 0; 249 return (profiles->size() + credit_cards->size()) > 0;
249 } 250 }
250 251
251 bool ImportAutofillDataWin(PersonalDataManager* pdm) { 252 bool ImportAutofillDataWin(PersonalDataManager* pdm) {
252 AutoFillImporter *importer = new AutoFillImporter(pdm); 253 AutoFillImporter *importer = new AutoFillImporter(pdm);
253 // importer will self delete. 254 // importer will self delete.
254 return importer->ImportProfiles(); 255 return importer->ImportProfiles();
255 } 256 }
256 257
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698