Chromium Code Reviews| 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 declares util functions for setup project. | 5 // This file declares util functions for setup project. |
| 6 | 6 |
| 7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <iterator> | 13 #include <iterator> |
| 14 #include <limits> | |
| 15 #include <memory> | |
| 14 #include <set> | 16 #include <set> |
| 15 #include <string> | 17 #include <string> |
| 16 | 18 |
| 17 #include "base/bind.h" | 19 #include "base/bind.h" |
| 18 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 19 #include "base/cpu.h" | 21 #include "base/cpu.h" |
| 20 #include "base/files/file_enumerator.h" | 22 #include "base/files/file_enumerator.h" |
| 21 #include "base/files/file_path.h" | 23 #include "base/files/file_path.h" |
| 22 #include "base/files/file_util.h" | 24 #include "base/files/file_util.h" |
| 23 #include "base/logging.h" | 25 #include "base/logging.h" |
| 24 #include "base/macros.h" | 26 #include "base/macros.h" |
| 25 #include "base/metrics/histogram.h" | 27 #include "base/metrics/histogram.h" |
| 26 #include "base/numerics/safe_conversions.h" | 28 #include "base/numerics/safe_conversions.h" |
| 27 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
| 28 #include "base/strings/string_util.h" | 30 #include "base/strings/string_util.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 31 #include "base/version.h" | 33 #include "base/version.h" |
| 32 #include "base/win/registry.h" | 34 #include "base/win/registry.h" |
| 33 #include "base/win/windows_version.h" | 35 #include "base/win/windows_version.h" |
| 34 #include "chrome/installer/setup/installer_state.h" | 36 #include "chrome/installer/setup/installer_state.h" |
| 35 #include "chrome/installer/setup/setup_constants.h" | 37 #include "chrome/installer/setup/setup_constants.h" |
| 36 #include "chrome/installer/setup/user_hive_visitor.h" | 38 #include "chrome/installer/setup/user_hive_visitor.h" |
| 37 #include "chrome/installer/util/app_registration_data.h" | 39 #include "chrome/installer/util/app_registration_data.h" |
| 38 #include "chrome/installer/util/google_update_constants.h" | 40 #include "chrome/installer/util/google_update_constants.h" |
| 41 #include "chrome/installer/util/install_util.h" | |
| 39 #include "chrome/installer/util/installation_state.h" | 42 #include "chrome/installer/util/installation_state.h" |
| 40 #include "chrome/installer/util/master_preferences.h" | 43 #include "chrome/installer/util/master_preferences.h" |
| 41 #include "chrome/installer/util/master_preferences_constants.h" | 44 #include "chrome/installer/util/master_preferences_constants.h" |
| 42 #include "chrome/installer/util/util_constants.h" | 45 #include "chrome/installer/util/util_constants.h" |
| 43 #include "courgette/courgette.h" | 46 #include "courgette/courgette.h" |
| 44 #include "courgette/third_party/bsdiff/bsdiff.h" | 47 #include "courgette/third_party/bsdiff/bsdiff.h" |
| 45 | 48 |
| 46 namespace installer { | 49 namespace installer { |
| 47 | 50 |
| 48 namespace { | 51 namespace { |
| 49 | 52 |
| 53 // Event log provider registry location and value names. | |
| 54 constexpr wchar_t kEventLogProvidersRegPath[] = | |
|
grt (UTC plus 2)
2016/11/18 11:38:12
nit: kEventLogProviderRegPath
pastarmovj
2016/11/21 15:48:40
Done.
| |
| 55 L"\\SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\chrome"; | |
|
grt (UTC plus 2)
2016/11/18 11:38:12
can "chrome" be any string, or does it need to be
grt (UTC plus 2)
2016/11/18 12:10:34
Maybe use BrowserDistribution::GetBaseAppName() fo
pastarmovj
2016/11/21 15:48:40
Unfortunately this has to coincide with the costan
grt (UTC plus 2)
2016/11/22 10:41:25
ah, this is pretty bad. any Chromium-based browser
grt (UTC plus 2)
2016/11/24 07:49:34
Also anything else built using Chromium's base, wh
| |
| 56 | |
| 50 // Returns true if product |type| cam be meaningfully installed without the | 57 // Returns true if product |type| cam be meaningfully installed without the |
| 51 // --multi-install flag. | 58 // --multi-install flag. |
| 52 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 59 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
| 53 return (type == BrowserDistribution::CHROME_BROWSER || | 60 return (type == BrowserDistribution::CHROME_BROWSER || |
| 54 type == BrowserDistribution::CHROME_FRAME); | 61 type == BrowserDistribution::CHROME_FRAME); |
| 55 } | 62 } |
| 56 | 63 |
| 57 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's | 64 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's |
| 58 // ClientState key for a user) indicates that Chrome has been used within the | 65 // ClientState key for a user) indicates that Chrome has been used within the |
| 59 // last 28 days. | 66 // last 28 days. |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 UNPACK_STATUS_COUNT, UNPACK_STATUS_COUNT + 1, | 660 UNPACK_STATUS_COUNT, UNPACK_STATUS_COUNT + 1, |
| 654 base::HistogramBase::kUmaTargetedHistogramFlag) | 661 base::HistogramBase::kUmaTargetedHistogramFlag) |
| 655 ->Add(unpack_status); | 662 ->Add(unpack_status); |
| 656 | 663 |
| 657 base::SparseHistogram::FactoryGet( | 664 base::SparseHistogram::FactoryGet( |
| 658 std::string(kUnPackNTSTATUSMetricsName) + "_" + consumer_name, | 665 std::string(kUnPackNTSTATUSMetricsName) + "_" + consumer_name, |
| 659 base::HistogramBase::kUmaTargetedHistogramFlag) | 666 base::HistogramBase::kUmaTargetedHistogramFlag) |
| 660 ->Add(status); | 667 ->Add(status); |
| 661 } | 668 } |
| 662 | 669 |
| 670 void RegisterEventLogProvider(const base::FilePath& chrome_exe) { | |
| 671 VLOG(1) << "Registering Chrome's event log provider at " | |
| 672 << kEventLogProvidersRegPath; | |
| 673 | |
| 674 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | |
| 675 | |
| 676 work_item_list->AddCreateRegKeyWorkItem( | |
| 677 HKEY_LOCAL_MACHINE, kEventLogProvidersRegPath, WorkItem::kWow64Default); | |
| 678 work_item_list->AddSetRegValueWorkItem( | |
| 679 HKEY_LOCAL_MACHINE, kEventLogProvidersRegPath, WorkItem::kWow64Default, | |
| 680 L"CategoryCount", static_cast<DWORD>(1), true); | |
| 681 work_item_list->AddSetRegValueWorkItem( | |
|
grt (UTC plus 2)
2016/11/18 11:38:12
nit: could you put a simple comment above each of
pastarmovj
2016/11/21 15:48:40
Done.
| |
| 682 HKEY_LOCAL_MACHINE, kEventLogProvidersRegPath, WorkItem::kWow64Default, | |
| 683 L"TypesSupported", static_cast<DWORD>(7), true); | |
| 684 | |
| 685 base::FilePath provider(chrome_exe.DirName()); | |
| 686 provider.Append(FILE_PATH_LITERAL("eventlog_provider.dll")); | |
|
grt (UTC plus 2)
2016/11/18 11:38:12
the provider is in the version directory, so you n
pastarmovj
2016/11/21 15:48:40
Done.
| |
| 687 | |
| 688 static constexpr wchar_t* file_keys[] = { | |
| 689 L"CategoryMessageFile", | |
| 690 L"EventMessageFile", | |
| 691 L"ParameterMessageFile", | |
| 692 }; | |
| 693 for (const wchar_t* file_key : file_keys) { | |
| 694 work_item_list->AddSetRegValueWorkItem( | |
| 695 HKEY_LOCAL_MACHINE, kEventLogProvidersRegPath, WorkItem::kWow64Default, | |
| 696 file_key, provider.value(), true); | |
| 697 } | |
| 698 | |
| 699 // if the operation fails we log the error but still continue because none of | |
| 700 // these are critical for the proper operation of the browser. | |
| 701 if (!work_item_list->Do()) | |
|
grt (UTC plus 2)
2016/11/18 11:38:12
are you intentionally not calling Rollback? if so,
pastarmovj
2016/11/21 15:48:41
No sorry I mistakenly assumed that the rollback is
| |
| 702 LOG(ERROR) << "Could not register Chrome's event log provider."; | |
| 703 } | |
| 704 | |
| 705 void DeRegisterEventLogProvider() { | |
| 706 InstallUtil::DeleteRegistryKey(HKEY_LOCAL_MACHINE, kEventLogProvidersRegPath, | |
| 707 WorkItem::kWow64Default); | |
| 708 } | |
| 709 | |
| 663 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | 710 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
| 664 : is_enabled_(false) { | 711 : is_enabled_(false) { |
| 665 HANDLE temp_handle; | 712 HANDLE temp_handle; |
| 666 if (!::OpenProcessToken(::GetCurrentProcess(), | 713 if (!::OpenProcessToken(::GetCurrentProcess(), |
| 667 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, | 714 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, |
| 668 &temp_handle)) { | 715 &temp_handle)) { |
| 669 return; | 716 return; |
| 670 } | 717 } |
| 671 token_.Set(temp_handle); | 718 token_.Set(temp_handle); |
| 672 | 719 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 695 } | 742 } |
| 696 | 743 |
| 697 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 744 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 698 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 745 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 699 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, | 746 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, |
| 700 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 747 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 701 } | 748 } |
| 702 } | 749 } |
| 703 | 750 |
| 704 } // namespace installer | 751 } // namespace installer |
| OLD | NEW |