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

Side by Side Diff: chrome/browser/importer/ie_importer.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/importer/ie_importer.h" 5 #include "chrome/browser/importer/ie_importer.h"
6 6
7 #include <ole2.h> 7 #include <ole2.h>
8 #include <intshcut.h> 8 #include <intshcut.h>
9 #include <pstore.h> 9 #include <pstore.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 const wchar_t kStorage2Path[] = 259 const wchar_t kStorage2Path[] =
260 L"Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2"; 260 L"Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2";
261 261
262 base::win::RegKey key(HKEY_CURRENT_USER, kStorage2Path, KEY_READ); 262 base::win::RegKey key(HKEY_CURRENT_USER, kStorage2Path, KEY_READ);
263 base::win::RegistryValueIterator reg_iterator(HKEY_CURRENT_USER, 263 base::win::RegistryValueIterator reg_iterator(HKEY_CURRENT_USER,
264 kStorage2Path); 264 kStorage2Path);
265 while (reg_iterator.Valid() && !cancelled()) { 265 while (reg_iterator.Valid() && !cancelled()) {
266 // Get the size of the encrypted data. 266 // Get the size of the encrypted data.
267 DWORD value_len = 0; 267 DWORD value_len = 0;
268 if (key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL) && 268 LONG result = key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL);
269 value_len) { 269 if (ERROR_SUCCESS == result && value_len) {
270 // Query the encrypted data. 270 // Query the encrypted data.
271 std::vector<unsigned char> value; 271 std::vector<unsigned char> value;
grt (UTC plus 2) 2011/01/11 03:51:30 Do you mind doing a little extra cleanup here? Th
amit 2011/01/12 04:11:23 Done.
272 value.resize(value_len); 272 value.resize(value_len);
273 if (key.ReadValue(reg_iterator.Name(), &value.front(), &value_len, 273 result = key.ReadValue(reg_iterator.Name(), &value.front(), &value_len,
274 NULL)) { 274 NULL);
275 if (ERROR_SUCCESS == result) {
275 IE7PasswordInfo password_info; 276 IE7PasswordInfo password_info;
276 password_info.url_hash = reg_iterator.Name(); 277 password_info.url_hash = reg_iterator.Name();
277 password_info.encrypted_data = value; 278 password_info.encrypted_data = value;
278 password_info.date_created = Time::Now(); 279 password_info.date_created = Time::Now();
279 280
280 bridge_->AddIE7PasswordInfo(password_info); 281 bridge_->AddIE7PasswordInfo(password_info);
281 } 282 }
282 } 283 }
283 284
284 ++reg_iterator; 285 ++reg_iterator;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 std::map<std::string, TemplateURL*> search_engines_map; 359 std::map<std::string, TemplateURL*> search_engines_map;
359 key.ReadValue(L"DefaultScope", &default_search_engine_name); 360 key.ReadValue(L"DefaultScope", &default_search_engine_name);
360 base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER, 361 base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER,
361 kSearchScopePath); 362 kSearchScopePath);
362 while (key_iterator.Valid()) { 363 while (key_iterator.Valid()) {
363 std::wstring sub_key_name = kSearchScopePath; 364 std::wstring sub_key_name = kSearchScopePath;
364 sub_key_name.append(L"\\").append(key_iterator.Name()); 365 sub_key_name.append(L"\\").append(key_iterator.Name());
365 base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(), 366 base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(),
366 KEY_READ); 367 KEY_READ);
367 std::wstring wide_url; 368 std::wstring wide_url;
368 if (!sub_key.ReadValue(L"URL", &wide_url) || wide_url.empty()) { 369 if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) ||
370 wide_url.empty()) {
369 VLOG(1) << "No URL for IE search engine at " << key_iterator.Name(); 371 VLOG(1) << "No URL for IE search engine at " << key_iterator.Name();
370 ++key_iterator; 372 ++key_iterator;
371 continue; 373 continue;
372 } 374 }
373 // For the name, we try the default value first (as Live Search uses a 375 // For the name, we try the default value first (as Live Search uses a
374 // non displayable name in DisplayName, and the readable name under the 376 // non displayable name in DisplayName, and the readable name under the
375 // default value). 377 // default value).
376 std::wstring name; 378 std::wstring name;
377 if (!sub_key.ReadValue(NULL, &name) || name.empty()) { 379 if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) {
378 // Try the displayable name. 380 // Try the displayable name.
379 if (!sub_key.ReadValue(L"DisplayName", &name) || name.empty()) { 381 if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) ||
382 name.empty()) {
380 VLOG(1) << "No name for IE search engine at " << key_iterator.Name(); 383 VLOG(1) << "No name for IE search engine at " << key_iterator.Name();
381 ++key_iterator; 384 ++key_iterator;
382 continue; 385 continue;
383 } 386 }
384 } 387 }
385 388
386 std::string url(WideToUTF8(wide_url)); 389 std::string url(WideToUTF8(wide_url));
387 std::map<std::string, TemplateURL*>::iterator t_iter = 390 std::map<std::string, TemplateURL*>::iterator t_iter =
388 search_engines_map.find(url); 391 search_engines_map.find(url);
389 TemplateURL* template_url = 392 TemplateURL* template_url =
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 428 }
426 429
427 void IEImporter::ImportHomepage() { 430 void IEImporter::ImportHomepage() {
428 const wchar_t kIESettingsMain[] = 431 const wchar_t kIESettingsMain[] =
429 L"Software\\Microsoft\\Internet Explorer\\Main"; 432 L"Software\\Microsoft\\Internet Explorer\\Main";
430 const wchar_t kIEHomepage[] = L"Start Page"; 433 const wchar_t kIEHomepage[] = L"Start Page";
431 const wchar_t kIEDefaultHomepage[] = L"Default_Page_URL"; 434 const wchar_t kIEDefaultHomepage[] = L"Default_Page_URL";
432 435
433 base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ); 436 base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ);
434 std::wstring homepage_url; 437 std::wstring homepage_url;
435 if (!key.ReadValue(kIEHomepage, &homepage_url) || homepage_url.empty()) 438 if (key.ReadValue(kIEHomepage, &homepage_url) != ERROR_SUCCESS ||
439 homepage_url.empty())
436 return; 440 return;
437 441
438 GURL homepage = GURL(homepage_url); 442 GURL homepage = GURL(homepage_url);
439 if (!homepage.is_valid()) 443 if (!homepage.is_valid())
440 return; 444 return;
441 445
442 // Check to see if this is the default website and skip import. 446 // Check to see if this is the default website and skip import.
443 base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ); 447 base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ);
444 std::wstring default_homepage_url; 448 std::wstring default_homepage_url;
445 if (keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url) && 449 LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url);
446 !default_homepage_url.empty()) { 450 if (result == ERROR_SUCCESS && !default_homepage_url.empty()) {
447 if (homepage.spec() == GURL(default_homepage_url).spec()) 451 if (homepage.spec() == GURL(default_homepage_url).spec())
448 return; 452 return;
449 } 453 }
450 454
451 bridge_->AddHomePage(homepage); 455 bridge_->AddHomePage(homepage);
452 } 456 }
453 457
454 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { 458 bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) {
455 if (!source_path_.empty()) { 459 if (!source_path_.empty()) {
456 // Source path exists during testing. 460 // Source path exists during testing.
(...skipping 12 matching lines...) Expand all
469 473
470 // There is a Links folder under Favorites folder in Windows Vista, but it 474 // There is a Links folder under Favorites folder in Windows Vista, but it
471 // is not recording in Vista's registry. So in Vista, we assume the Links 475 // is not recording in Vista's registry. So in Vista, we assume the Links
472 // folder is under Favorites folder since it looks like there is not name 476 // folder is under Favorites folder since it looks like there is not name
473 // different in every language version of Windows Vista. 477 // different in every language version of Windows Vista.
474 if (base::win::GetVersion() < base::win::VERSION_VISTA) { 478 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
475 // The Link folder name is stored in the registry. 479 // The Link folder name is stored in the registry.
476 DWORD buffer_length = sizeof(buffer); 480 DWORD buffer_length = sizeof(buffer);
477 base::win::RegKey reg_key(HKEY_CURRENT_USER, 481 base::win::RegKey reg_key(HKEY_CURRENT_USER,
478 L"Software\\Microsoft\\Internet Explorer\\Toolbar", KEY_READ); 482 L"Software\\Microsoft\\Internet Explorer\\Toolbar", KEY_READ);
479 if (!reg_key.ReadValue(L"LinksFolderName", buffer, &buffer_length, NULL)) 483 if (reg_key.ReadValue(L"LinksFolderName", buffer,
484 &buffer_length, NULL) != ERROR_SUCCESS)
480 return false; 485 return false;
481 info->links_folder = buffer; 486 info->links_folder = buffer;
482 } else { 487 } else {
483 info->links_folder = L"Links"; 488 info->links_folder = L"Links";
484 } 489 }
485 490
486 return true; 491 return true;
487 } 492 }
488 493
489 void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info, 494 void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return std::wstring(url); 583 return std::wstring(url);
579 } 584 }
580 585
581 int IEImporter::CurrentIEVersion() const { 586 int IEImporter::CurrentIEVersion() const {
582 static int version = -1; 587 static int version = -1;
583 if (version < 0) { 588 if (version < 0) {
584 wchar_t buffer[128]; 589 wchar_t buffer[128];
585 DWORD buffer_length = sizeof(buffer); 590 DWORD buffer_length = sizeof(buffer);
586 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, 591 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE,
587 L"Software\\Microsoft\\Internet Explorer", KEY_READ); 592 L"Software\\Microsoft\\Internet Explorer", KEY_READ);
588 bool result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); 593 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL);
589 version = (result ? _wtoi(buffer) : 0); 594 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0);
590 } 595 }
591 return version; 596 return version;
592 } 597 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698