OLD | NEW |
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 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
8 // this class. | 8 // this class. |
9 | 9 |
10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 509 |
510 // start->Internet shortcut. | 510 // start->Internet shortcut. |
511 string16 start_menu(ShellUtil::kRegStartMenuInternet); | 511 string16 start_menu(ShellUtil::kRegStartMenuInternet); |
512 string16 app_name = dist->GetBaseAppName() + suffix; | 512 string16 app_name = dist->GetBaseAppName() + suffix; |
513 entries->push_back(new RegistryEntry(start_menu, app_name)); | 513 entries->push_back(new RegistryEntry(start_menu, app_name)); |
514 } | 514 } |
515 | 515 |
516 // Generate work_item tasks required to create current registry entry and | 516 // Generate work_item tasks required to create current registry entry and |
517 // add them to the given work item list. | 517 // add them to the given work item list. |
518 void AddToWorkItemList(HKEY root, WorkItemList *items) const { | 518 void AddToWorkItemList(HKEY root, WorkItemList *items) const { |
519 items->AddCreateRegKeyWorkItem(root, _key_path); | 519 items->AddCreateRegKeyWorkItem(root, key_path_); |
520 if (_is_string) { | 520 if (is_string_) { |
521 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); | 521 items->AddSetRegValueWorkItem(root, key_path_, name_, value_, true); |
522 } else { | 522 } else { |
523 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); | 523 items->AddSetRegValueWorkItem(root, key_path_, name_, int_value_, true); |
524 } | 524 } |
525 } | 525 } |
526 | 526 |
527 // Checks if the current registry entry exists in HKCU\|_key_path|\|_name| | 527 // Checks if the current registry entry exists in HKCU\|key_path_|\|name_| |
528 // and value is |_value|. If the key does NOT exist in HKCU, checks for | 528 // and value is |value_|. If the key does NOT exist in HKCU, checks for |
529 // the correct name and value in HKLM. | 529 // the correct name and value in HKLM. |
530 // |look_for_in| specifies roots (HKCU and/or HKLM) in which to look for the | 530 // |look_for_in| specifies roots (HKCU and/or HKLM) in which to look for the |
531 // key, unspecified roots are not looked into (i.e. the the key is assumed not | 531 // key, unspecified roots are not looked into (i.e. the the key is assumed not |
532 // to exist in them). | 532 // to exist in them). |
533 // |look_for_in| must at least specify one root to look into. | 533 // |look_for_in| must at least specify one root to look into. |
534 // If |look_for_in| is LOOK_IN_HKCU_THEN_HKLM, this method mimics Windows' | 534 // If |look_for_in| is LOOK_IN_HKCU_THEN_HKLM, this method mimics Windows' |
535 // behavior when searching in HKCR (HKCU takes precedence over HKLM). For | 535 // behavior when searching in HKCR (HKCU takes precedence over HKLM). For |
536 // registrations outside of HKCR on versions of Windows prior to Win8, | 536 // registrations outside of HKCR on versions of Windows prior to Win8, |
537 // Chrome's values go in HKLM. This function will make unnecessary (but | 537 // Chrome's values go in HKLM. This function will make unnecessary (but |
538 // harmless) queries into HKCU in that case. | 538 // harmless) queries into HKCU in that case. |
539 bool ExistsInRegistry(uint32 look_for_in) const { | 539 bool ExistsInRegistry(uint32 look_for_in) const { |
540 DCHECK(look_for_in); | 540 DCHECK(look_for_in); |
541 | 541 |
542 RegistryStatus status = DOES_NOT_EXIST; | 542 RegistryStatus status = DOES_NOT_EXIST; |
543 if (look_for_in & LOOK_IN_HKCU) | 543 if (look_for_in & LOOK_IN_HKCU) |
544 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | 544 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); |
545 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) | 545 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) |
546 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); | 546 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); |
547 return status == SAME_VALUE; | 547 return status == SAME_VALUE; |
548 } | 548 } |
549 | 549 |
550 private: | 550 private: |
551 // States this RegistryKey can be in compared to the registry. | 551 // States this RegistryKey can be in compared to the registry. |
552 enum RegistryStatus { | 552 enum RegistryStatus { |
553 // |_name| does not exist in the registry | 553 // |name_| does not exist in the registry |
554 DOES_NOT_EXIST, | 554 DOES_NOT_EXIST, |
555 // |_name| exists, but its value != |_value| | 555 // |name_| exists, but its value != |value_| |
556 DIFFERENT_VALUE, | 556 DIFFERENT_VALUE, |
557 // |_name| exists and its value is |_value| | 557 // |name_| exists and its value is |value_| |
558 SAME_VALUE, | 558 SAME_VALUE, |
559 }; | 559 }; |
560 | 560 |
561 // Create a object that represent default value of a key | 561 // Create a object that represent default value of a key |
562 RegistryEntry(const string16& key_path, const string16& value) | 562 RegistryEntry(const string16& key_path, const string16& value) |
563 : _key_path(key_path), _name(), | 563 : key_path_(key_path), name_(), |
564 _is_string(true), _value(value), _int_value(0) { | 564 is_string_(true), value_(value), int_value_(0) { |
565 } | 565 } |
566 | 566 |
567 // Create a object that represent a key of type REG_SZ | 567 // Create a object that represent a key of type REG_SZ |
568 RegistryEntry(const string16& key_path, const string16& name, | 568 RegistryEntry(const string16& key_path, const string16& name, |
569 const string16& value) | 569 const string16& value) |
570 : _key_path(key_path), _name(name), | 570 : key_path_(key_path), name_(name), |
571 _is_string(true), _value(value), _int_value(0) { | 571 is_string_(true), value_(value), int_value_(0) { |
572 } | 572 } |
573 | 573 |
574 // Create a object that represent a key of integer type | 574 // Create a object that represent a key of integer type |
575 RegistryEntry(const string16& key_path, const string16& name, | 575 RegistryEntry(const string16& key_path, const string16& name, |
576 DWORD value) | 576 DWORD value) |
577 : _key_path(key_path), _name(name), | 577 : key_path_(key_path), name_(name), |
578 _is_string(false), _value(), _int_value(value) { | 578 is_string_(false), value_(), int_value_(value) { |
579 } | 579 } |
580 | 580 |
581 string16 _key_path; // key path for the registry entry | 581 string16 key_path_; // key path for the registry entry |
582 string16 _name; // name of the registry entry | 582 string16 name_; // name of the registry entry |
583 bool _is_string; // true if current registry entry is of type REG_SZ | 583 bool is_string_; // true if current registry entry is of type REG_SZ |
584 string16 _value; // string value (useful if _is_string = true) | 584 string16 value_; // string value (useful if is_string_ = true) |
585 DWORD _int_value; // integer value (useful if _is_string = false) | 585 DWORD int_value_; // integer value (useful if is_string_ = false) |
586 | 586 |
587 // Helper function for ExistsInRegistry(). | 587 // Helper function for ExistsInRegistry(). |
588 // Returns the RegistryStatus of the current registry entry in | 588 // Returns the RegistryStatus of the current registry entry in |
589 // |root|\|_key_path|\|_name|. | 589 // |root|\|key_path_|\|name_|. |
590 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const { | 590 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const { |
591 RegKey key(root, _key_path.c_str(), KEY_QUERY_VALUE); | 591 RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE); |
592 bool found = false; | 592 bool found = false; |
593 bool correct_value = false; | 593 bool correct_value = false; |
594 if (_is_string) { | 594 if (is_string_) { |
595 string16 read_value; | 595 string16 read_value; |
596 found = key.ReadValue(_name.c_str(), &read_value) == ERROR_SUCCESS; | 596 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS; |
597 correct_value = read_value.size() == _value.size() && | 597 correct_value = read_value.size() == value_.size() && |
598 std::equal(_value.begin(), _value.end(), read_value.begin(), | 598 std::equal(value_.begin(), value_.end(), read_value.begin(), |
599 base::CaseInsensitiveCompare<wchar_t>()); | 599 base::CaseInsensitiveCompare<wchar_t>()); |
600 } else { | 600 } else { |
601 DWORD read_value; | 601 DWORD read_value; |
602 found = key.ReadValueDW(_name.c_str(), &read_value) == ERROR_SUCCESS; | 602 found = key.ReadValueDW(name_.c_str(), &read_value) == ERROR_SUCCESS; |
603 correct_value = read_value == _int_value; | 603 correct_value = read_value == int_value_; |
604 } | 604 } |
605 return found ? | 605 return found ? |
606 (correct_value ? SAME_VALUE : DIFFERENT_VALUE) : DOES_NOT_EXIST; | 606 (correct_value ? SAME_VALUE : DIFFERENT_VALUE) : DOES_NOT_EXIST; |
607 } | 607 } |
608 | 608 |
609 DISALLOW_COPY_AND_ASSIGN(RegistryEntry); | 609 DISALLOW_COPY_AND_ASSIGN(RegistryEntry); |
610 }; // class RegistryEntry | 610 }; // class RegistryEntry |
611 | 611 |
612 | 612 |
613 // This method converts all the RegistryEntries from the given list to | 613 // This method converts all the RegistryEntries from the given list to |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2081 // are any left...). | 2081 // are any left...). |
2082 if (free_bits >= 8 && next_byte_index < size) { | 2082 if (free_bits >= 8 && next_byte_index < size) { |
2083 free_bits -= 8; | 2083 free_bits -= 8; |
2084 bit_stream += bytes[next_byte_index++] << free_bits; | 2084 bit_stream += bytes[next_byte_index++] << free_bits; |
2085 } | 2085 } |
2086 } | 2086 } |
2087 | 2087 |
2088 DCHECK_EQ(ret.length(), encoded_length); | 2088 DCHECK_EQ(ret.length(), encoded_length); |
2089 return ret; | 2089 return ret; |
2090 } | 2090 } |
OLD | NEW |