| 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 #include "chrome/installer/util/google_update_settings.h" | 5 #include "chrome/installer/util/google_update_settings.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 126 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 127 std::wstring reg_path = dist->GetStateKey(); | 127 std::wstring reg_path = dist->GetStateKey(); |
| 128 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); | 128 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ | KEY_WRITE); |
| 129 if (!key.HasValue(name)) | 129 if (!key.HasValue(name)) |
| 130 return true; | 130 return true; |
| 131 return (key.DeleteValue(name) == ERROR_SUCCESS); | 131 return (key.DeleteValue(name) == ERROR_SUCCESS); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool GetChromeChannelInternal(bool system_install, | 134 bool GetChromeChannelInternal(bool system_install, |
| 135 bool add_multi_modifier, | 135 bool add_multi_modifier, |
| 136 string16* channel) { | 136 base::string16* channel) { |
| 137 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 137 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 138 if (dist->GetChromeChannel(channel)) { | 138 if (dist->GetChromeChannel(channel)) { |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| 141 | 141 |
| 142 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 142 HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 143 string16 reg_path = dist->GetStateKey(); | 143 base::string16 reg_path = dist->GetStateKey(); |
| 144 RegKey key(root_key, reg_path.c_str(), KEY_READ); | 144 RegKey key(root_key, reg_path.c_str(), KEY_READ); |
| 145 | 145 |
| 146 installer::ChannelInfo channel_info; | 146 installer::ChannelInfo channel_info; |
| 147 if (!channel_info.Initialize(key)) { | 147 if (!channel_info.Initialize(key)) { |
| 148 channel->assign(installer::kChromeChannelUnknown); | 148 channel->assign(installer::kChromeChannelUnknown); |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 | 151 |
| 152 if (!channel_info.GetChannelName(channel)) { | 152 if (!channel_info.GetChannelName(channel)) { |
| 153 channel->assign(installer::kChromeChannelUnknown); | 153 channel->assign(installer::kChromeChannelUnknown); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 did_run ? L"1" : L"0", | 397 did_run ? L"1" : L"0", |
| 398 system_level); | 398 system_level); |
| 399 } | 399 } |
| 400 | 400 |
| 401 std::wstring GoogleUpdateSettings::GetChromeChannel(bool system_install) { | 401 std::wstring GoogleUpdateSettings::GetChromeChannel(bool system_install) { |
| 402 std::wstring channel; | 402 std::wstring channel; |
| 403 GetChromeChannelInternal(system_install, false, &channel); | 403 GetChromeChannelInternal(system_install, false, &channel); |
| 404 return channel; | 404 return channel; |
| 405 } | 405 } |
| 406 | 406 |
| 407 bool GoogleUpdateSettings::GetChromeChannelAndModifiers(bool system_install, | 407 bool GoogleUpdateSettings::GetChromeChannelAndModifiers( |
| 408 string16* channel) { | 408 bool system_install, |
| 409 base::string16* channel) { |
| 409 return GetChromeChannelInternal(system_install, true, channel); | 410 return GetChromeChannelInternal(system_install, true, channel); |
| 410 } | 411 } |
| 411 | 412 |
| 412 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, | 413 void GoogleUpdateSettings::UpdateInstallStatus(bool system_install, |
| 413 installer::ArchiveType archive_type, int install_return_code, | 414 installer::ArchiveType archive_type, int install_return_code, |
| 414 const std::wstring& product_guid) { | 415 const std::wstring& product_guid) { |
| 415 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE || | 416 DCHECK(archive_type != installer::UNKNOWN_ARCHIVE_TYPE || |
| 416 install_return_code != 0); | 417 install_return_code != 0); |
| 417 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 418 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 418 | 419 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 564 } |
| 564 } | 565 } |
| 565 #endif // defined(GOOGLE_CHROME_BUILD) | 566 #endif // defined(GOOGLE_CHROME_BUILD) |
| 566 | 567 |
| 567 if (is_overridden != NULL) | 568 if (is_overridden != NULL) |
| 568 *is_overridden = found_override; | 569 *is_overridden = found_override; |
| 569 | 570 |
| 570 return update_policy; | 571 return update_policy; |
| 571 } | 572 } |
| 572 | 573 |
| 573 string16 GoogleUpdateSettings::GetUninstallCommandLine(bool system_install) { | 574 base::string16 GoogleUpdateSettings::GetUninstallCommandLine( |
| 575 bool system_install) { |
| 574 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 576 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 575 string16 cmd_line; | 577 base::string16 cmd_line; |
| 576 RegKey update_key; | 578 RegKey update_key; |
| 577 | 579 |
| 578 if (update_key.Open(root_key, google_update::kRegPathGoogleUpdate, | 580 if (update_key.Open(root_key, google_update::kRegPathGoogleUpdate, |
| 579 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 581 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 580 update_key.ReadValue(google_update::kRegUninstallCmdLine, &cmd_line); | 582 update_key.ReadValue(google_update::kRegUninstallCmdLine, &cmd_line); |
| 581 } | 583 } |
| 582 | 584 |
| 583 return cmd_line; | 585 return cmd_line; |
| 584 } | 586 } |
| 585 | 587 |
| 586 Version GoogleUpdateSettings::GetGoogleUpdateVersion(bool system_install) { | 588 Version GoogleUpdateSettings::GetGoogleUpdateVersion(bool system_install) { |
| 587 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 589 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 588 string16 version; | 590 base::string16 version; |
| 589 RegKey key; | 591 RegKey key; |
| 590 | 592 |
| 591 if (key.Open(root_key, | 593 if (key.Open(root_key, |
| 592 google_update::kRegPathGoogleUpdate, | 594 google_update::kRegPathGoogleUpdate, |
| 593 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 595 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 594 key.ReadValue(google_update::kRegGoogleUpdateVersion, | 596 key.ReadValue(google_update::kRegGoogleUpdateVersion, |
| 595 &version) == ERROR_SUCCESS) { | 597 &version) == ERROR_SUCCESS) { |
| 596 return Version(UTF16ToUTF8(version)); | 598 return Version(UTF16ToUTF8(version)); |
| 597 } | 599 } |
| 598 | 600 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 637 |
| 636 bool GoogleUpdateSettings::GetUpdateDetailForApp(bool system_install, | 638 bool GoogleUpdateSettings::GetUpdateDetailForApp(bool system_install, |
| 637 const wchar_t* app_guid, | 639 const wchar_t* app_guid, |
| 638 ProductData* data) { | 640 ProductData* data) { |
| 639 DCHECK(app_guid); | 641 DCHECK(app_guid); |
| 640 DCHECK(data); | 642 DCHECK(data); |
| 641 | 643 |
| 642 bool product_found = false; | 644 bool product_found = false; |
| 643 | 645 |
| 644 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 646 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 645 string16 clientstate_reg_path(google_update::kRegPathClientState); | 647 base::string16 clientstate_reg_path(google_update::kRegPathClientState); |
| 646 clientstate_reg_path.append(L"\\"); | 648 clientstate_reg_path.append(L"\\"); |
| 647 clientstate_reg_path.append(app_guid); | 649 clientstate_reg_path.append(app_guid); |
| 648 | 650 |
| 649 RegKey clientstate; | 651 RegKey clientstate; |
| 650 if (clientstate.Open(root_key, clientstate_reg_path.c_str(), | 652 if (clientstate.Open(root_key, clientstate_reg_path.c_str(), |
| 651 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | 653 KEY_QUERY_VALUE) == ERROR_SUCCESS) { |
| 652 string16 version; | 654 base::string16 version; |
| 653 DWORD dword_value; | 655 DWORD dword_value; |
| 654 if ((clientstate.ReadValueDW(google_update::kRegLastCheckSuccessField, | 656 if ((clientstate.ReadValueDW(google_update::kRegLastCheckSuccessField, |
| 655 &dword_value) == ERROR_SUCCESS) && | 657 &dword_value) == ERROR_SUCCESS) && |
| 656 (clientstate.ReadValue(google_update::kRegVersionField, | 658 (clientstate.ReadValue(google_update::kRegVersionField, |
| 657 &version) == ERROR_SUCCESS)) { | 659 &version) == ERROR_SUCCESS)) { |
| 658 product_found = true; | 660 product_found = true; |
| 659 data->version = WideToASCII(version); | 661 data->version = WideToASCII(version); |
| 660 data->last_success = base::Time::FromTimeT(dword_value); | 662 data->last_success = base::Time::FromTimeT(dword_value); |
| 661 data->last_result = 0; | 663 data->last_result = 0; |
| 662 data->last_error_code = 0; | 664 data->last_error_code = 0; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 693 bool GoogleUpdateSettings::GetUpdateDetail(bool system_install, | 695 bool GoogleUpdateSettings::GetUpdateDetail(bool system_install, |
| 694 ProductData* data) { | 696 ProductData* data) { |
| 695 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 697 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 696 return GetUpdateDetailForApp(system_install, | 698 return GetUpdateDetailForApp(system_install, |
| 697 dist->GetAppGuid().c_str(), | 699 dist->GetAppGuid().c_str(), |
| 698 data); | 700 data); |
| 699 } | 701 } |
| 700 | 702 |
| 701 bool GoogleUpdateSettings::SetExperimentLabels( | 703 bool GoogleUpdateSettings::SetExperimentLabels( |
| 702 bool system_install, | 704 bool system_install, |
| 703 const string16& experiment_labels) { | 705 const base::string16& experiment_labels) { |
| 704 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 706 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 705 | 707 |
| 706 // Use the browser distribution and install level to write to the correct | 708 // Use the browser distribution and install level to write to the correct |
| 707 // client state/app guid key. | 709 // client state/app guid key. |
| 708 bool success = false; | 710 bool success = false; |
| 709 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 711 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 710 if (dist->ShouldSetExperimentLabels()) { | 712 if (dist->ShouldSetExperimentLabels()) { |
| 711 string16 client_state_path( | 713 base::string16 client_state_path( |
| 712 system_install ? dist->GetStateMediumKey() : dist->GetStateKey()); | 714 system_install ? dist->GetStateMediumKey() : dist->GetStateKey()); |
| 713 RegKey client_state( | 715 RegKey client_state( |
| 714 reg_root, client_state_path.c_str(), KEY_SET_VALUE); | 716 reg_root, client_state_path.c_str(), KEY_SET_VALUE); |
| 715 if (experiment_labels.empty()) { | 717 if (experiment_labels.empty()) { |
| 716 success = client_state.DeleteValue(google_update::kExperimentLabels) | 718 success = client_state.DeleteValue(google_update::kExperimentLabels) |
| 717 == ERROR_SUCCESS; | 719 == ERROR_SUCCESS; |
| 718 } else { | 720 } else { |
| 719 success = client_state.WriteValue(google_update::kExperimentLabels, | 721 success = client_state.WriteValue(google_update::kExperimentLabels, |
| 720 experiment_labels.c_str()) == ERROR_SUCCESS; | 722 experiment_labels.c_str()) == ERROR_SUCCESS; |
| 721 } | 723 } |
| 722 } | 724 } |
| 723 | 725 |
| 724 return success; | 726 return success; |
| 725 } | 727 } |
| 726 | 728 |
| 727 bool GoogleUpdateSettings::ReadExperimentLabels( | 729 bool GoogleUpdateSettings::ReadExperimentLabels( |
| 728 bool system_install, | 730 bool system_install, |
| 729 string16* experiment_labels) { | 731 base::string16* experiment_labels) { |
| 730 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 732 HKEY reg_root = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 731 | 733 |
| 732 // If this distribution does not set the experiment labels, don't bother | 734 // If this distribution does not set the experiment labels, don't bother |
| 733 // reading. | 735 // reading. |
| 734 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 736 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 735 if (!dist->ShouldSetExperimentLabels()) | 737 if (!dist->ShouldSetExperimentLabels()) |
| 736 return false; | 738 return false; |
| 737 | 739 |
| 738 string16 client_state_path( | 740 base::string16 client_state_path( |
| 739 system_install ? dist->GetStateMediumKey() : dist->GetStateKey()); | 741 system_install ? dist->GetStateMediumKey() : dist->GetStateKey()); |
| 740 | 742 |
| 741 RegKey client_state; | 743 RegKey client_state; |
| 742 LONG result = | 744 LONG result = |
| 743 client_state.Open(reg_root, client_state_path.c_str(), KEY_QUERY_VALUE); | 745 client_state.Open(reg_root, client_state_path.c_str(), KEY_QUERY_VALUE); |
| 744 if (result == ERROR_SUCCESS) { | 746 if (result == ERROR_SUCCESS) { |
| 745 result = client_state.ReadValue(google_update::kExperimentLabels, | 747 result = client_state.ReadValue(google_update::kExperimentLabels, |
| 746 experiment_labels); | 748 experiment_labels); |
| 747 } | 749 } |
| 748 | 750 |
| 749 // If the key or value was not present, return the empty string. | 751 // If the key or value was not present, return the empty string. |
| 750 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { | 752 if (result == ERROR_FILE_NOT_FOUND || result == ERROR_PATH_NOT_FOUND) { |
| 751 experiment_labels->clear(); | 753 experiment_labels->clear(); |
| 752 return true; | 754 return true; |
| 753 } | 755 } |
| 754 | 756 |
| 755 return result == ERROR_SUCCESS; | 757 return result == ERROR_SUCCESS; |
| 756 } | 758 } |
| OLD | NEW |