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" |
36 #include "chrome/install_static/install_details.h" | |
grt (UTC plus 2)
2016/12/13 13:21:52
remove this for now
pastarmovj
2016/12/16 12:44:16
Done.
| |
34 #include "chrome/installer/setup/installer_state.h" | 37 #include "chrome/installer/setup/installer_state.h" |
35 #include "chrome/installer/setup/setup_constants.h" | 38 #include "chrome/installer/setup/setup_constants.h" |
36 #include "chrome/installer/setup/user_hive_visitor.h" | 39 #include "chrome/installer/setup/user_hive_visitor.h" |
37 #include "chrome/installer/util/app_registration_data.h" | 40 #include "chrome/installer/util/app_registration_data.h" |
38 #include "chrome/installer/util/google_update_constants.h" | 41 #include "chrome/installer/util/google_update_constants.h" |
42 #include "chrome/installer/util/install_util.h" | |
39 #include "chrome/installer/util/installation_state.h" | 43 #include "chrome/installer/util/installation_state.h" |
40 #include "chrome/installer/util/master_preferences.h" | 44 #include "chrome/installer/util/master_preferences.h" |
41 #include "chrome/installer/util/master_preferences_constants.h" | 45 #include "chrome/installer/util/master_preferences_constants.h" |
42 #include "chrome/installer/util/util_constants.h" | 46 #include "chrome/installer/util/util_constants.h" |
43 #include "courgette/courgette.h" | 47 #include "courgette/courgette.h" |
44 #include "courgette/third_party/bsdiff/bsdiff.h" | 48 #include "courgette/third_party/bsdiff/bsdiff.h" |
45 | 49 |
46 namespace installer { | 50 namespace installer { |
47 | 51 |
48 namespace { | 52 namespace { |
49 | 53 |
54 // Event log provider registry location and value names. | |
grt (UTC plus 2)
2016/12/13 13:21:52
nit: value names are not defined here
pastarmovj
2016/12/16 12:44:16
Done.
| |
55 // TODO(http://crbug.com/668397): Make this string depend on the branding then | |
grt (UTC plus 2)
2016/12/13 13:21:52
remove this TODO?
pastarmovj
2016/12/16 12:44:16
Done.
| |
56 // as well. | |
57 constexpr wchar_t kEventLogProvidersRegPath[] = | |
58 L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\"; | |
59 | |
50 // Returns true if product |type| cam be meaningfully installed without the | 60 // Returns true if product |type| cam be meaningfully installed without the |
51 // --multi-install flag. | 61 // --multi-install flag. |
52 bool SupportsSingleInstall(BrowserDistribution::Type type) { | 62 bool SupportsSingleInstall(BrowserDistribution::Type type) { |
53 return (type == BrowserDistribution::CHROME_BROWSER || | 63 return (type == BrowserDistribution::CHROME_BROWSER || |
54 type == BrowserDistribution::CHROME_FRAME); | 64 type == BrowserDistribution::CHROME_FRAME); |
55 } | 65 } |
56 | 66 |
57 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's | 67 // 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 | 68 // ClientState key for a user) indicates that Chrome has been used within the |
59 // last 28 days. | 69 // last 28 days. |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 UNPACK_STATUS_COUNT, UNPACK_STATUS_COUNT + 1, | 663 UNPACK_STATUS_COUNT, UNPACK_STATUS_COUNT + 1, |
654 base::HistogramBase::kUmaTargetedHistogramFlag) | 664 base::HistogramBase::kUmaTargetedHistogramFlag) |
655 ->Add(unpack_status); | 665 ->Add(unpack_status); |
656 | 666 |
657 base::SparseHistogram::FactoryGet( | 667 base::SparseHistogram::FactoryGet( |
658 std::string(kUnPackNTSTATUSMetricsName) + "_" + consumer_name, | 668 std::string(kUnPackNTSTATUSMetricsName) + "_" + consumer_name, |
659 base::HistogramBase::kUmaTargetedHistogramFlag) | 669 base::HistogramBase::kUmaTargetedHistogramFlag) |
660 ->Add(status); | 670 ->Add(status); |
661 } | 671 } |
662 | 672 |
673 void RegisterEventLogProvider(const base::FilePath& install_directory, | |
674 const base::Version& version) { | |
675 base::string16 reg_path(kEventLogProvidersRegPath); | |
676 reg_path.append(install_static::InstallDetails::Get().install_full_name()); | |
grt (UTC plus 2)
2016/12/13 13:21:52
this is ultimately the right thing, but it won't w
pastarmovj
2016/12/16 12:44:16
Done.
| |
677 VLOG(1) << "Registering Chrome's event log provider at " | |
678 << reg_path; | |
679 | |
680 std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | |
681 work_item_list->set_log_message("Register event log provider"); | |
682 | |
683 work_item_list->AddCreateRegKeyWorkItem( | |
684 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default); | |
685 // Speicifes the number of event categories defined in the dll. | |
686 work_item_list->AddSetRegValueWorkItem( | |
687 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default, L"CategoryCount", | |
688 static_cast<DWORD>(1), true); | |
689 // Specifies the event type emitted by this event source. | |
690 work_item_list->AddSetRegValueWorkItem( | |
691 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default, L"TypesSupported", | |
692 static_cast<DWORD>(EVENTLOG_ERROR_TYPE | EVENTLOG_INFORMATION_TYPE | | |
693 EVENTLOG_WARNING_TYPE), | |
694 true); | |
695 | |
696 const base::FilePath provider( | |
697 install_directory.AppendASCII(version.GetString()) | |
698 .Append(FILE_PATH_LITERAL("eventlog_provider.dll"))); | |
699 | |
700 static constexpr const wchar_t* kFileKeys[] = { | |
701 L"CategoryMessageFile", L"EventMessageFile", L"ParameterMessageFile", | |
702 }; | |
703 for (const wchar_t* file_key : kFileKeys) { | |
704 work_item_list->AddSetRegValueWorkItem( | |
705 HKEY_LOCAL_MACHINE, reg_path, WorkItem::kWow64Default, file_key, | |
706 provider.value(), true); | |
707 } | |
708 | |
709 // if the operation fails we log the error but still continue because none of | |
710 // these are critical for the proper operation of the browser. | |
711 if (!work_item_list->Do()) | |
712 work_item_list->Rollback(); | |
713 } | |
714 | |
715 void DeRegisterEventLogProvider() { | |
716 base::string16 reg_path(kEventLogProvidersRegPath); | |
717 reg_path.append(install_static::InstallDetails::Get().install_full_name()); | |
grt (UTC plus 2)
2016/12/13 13:21:52
same as above. maybe put the ugly logic in a helpe
pastarmovj
2016/12/16 12:44:16
Done.
| |
718 | |
719 // TODO(http://crbug.com/668120): If the Event Viewer is open the provider dll | |
720 // will fail to get deleted. This doesn't fail the uninstallation altogether | |
721 // but leaves files behind. | |
722 InstallUtil::DeleteRegistryKey(HKEY_LOCAL_MACHINE, reg_path, | |
723 WorkItem::kWow64Default); | |
724 } | |
725 | |
663 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | 726 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
664 : is_enabled_(false) { | 727 : is_enabled_(false) { |
665 HANDLE temp_handle; | 728 HANDLE temp_handle; |
666 if (!::OpenProcessToken(::GetCurrentProcess(), | 729 if (!::OpenProcessToken(::GetCurrentProcess(), |
667 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, | 730 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, |
668 &temp_handle)) { | 731 &temp_handle)) { |
669 return; | 732 return; |
670 } | 733 } |
671 token_.Set(temp_handle); | 734 token_.Set(temp_handle); |
672 | 735 |
(...skipping 22 matching lines...) Expand all Loading... | |
695 } | 758 } |
696 | 759 |
697 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 760 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
698 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 761 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
699 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, | 762 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, |
700 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 763 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
701 } | 764 } |
702 } | 765 } |
703 | 766 |
704 } // namespace installer | 767 } // namespace installer |
OLD | NEW |