 Chromium Code Reviews
 Chromium Code Reviews Issue 2507753002:
  Install the chrome event log provider together with the browser.  (Closed)
    
  
    Issue 2507753002:
  Install the chrome event log provider together with the browser.  (Closed) 
  | Index: chrome/installer/setup/setup_util.cc | 
| diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc | 
| index 233287bf519375396cf4082baa66791711886c63..d690390d2a3bf7569473d0f617b9210c39ce0942 100644 | 
| --- a/chrome/installer/setup/setup_util.cc | 
| +++ b/chrome/installer/setup/setup_util.cc | 
| @@ -11,6 +11,8 @@ | 
| #include <algorithm> | 
| #include <iterator> | 
| +#include <limits> | 
| +#include <memory> | 
| #include <set> | 
| #include <string> | 
| @@ -36,6 +38,7 @@ | 
| #include "chrome/installer/setup/user_hive_visitor.h" | 
| #include "chrome/installer/util/app_registration_data.h" | 
| #include "chrome/installer/util/google_update_constants.h" | 
| +#include "chrome/installer/util/install_util.h" | 
| #include "chrome/installer/util/installation_state.h" | 
| #include "chrome/installer/util/master_preferences.h" | 
| #include "chrome/installer/util/master_preferences_constants.h" | 
| @@ -47,6 +50,10 @@ namespace installer { | 
| namespace { | 
| +// Event log provider registry location and value names. | 
| +constexpr wchar_t kEventLogProviderRegPath[] = | 
| + L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\chrome"; | 
| + | 
| // Returns true if product |type| cam be meaningfully installed without the | 
| // --multi-install flag. | 
| bool SupportsSingleInstall(BrowserDistribution::Type type) { | 
| @@ -660,6 +667,54 @@ void RecordUnPackMetrics(UnPackStatus unpack_status, | 
| ->Add(status); | 
| } | 
| +void RegisterEventLogProvider(const base::FilePath& install_directory, | 
| + const std::string& version) { | 
| + VLOG(1) << "Registering Chrome's event log provider at " | 
| + << kEventLogProviderRegPath; | 
| + | 
| + std::unique_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); | 
| + work_item_list->set_log_message("Register event log provider"); | 
| + | 
| + work_item_list->AddCreateRegKeyWorkItem( | 
| + HKEY_LOCAL_MACHINE, kEventLogProviderRegPath, WorkItem::kWow64Default); | 
| + // Speicifes the number of event categories defined in the dll. | 
| + work_item_list->AddSetRegValueWorkItem( | 
| + HKEY_LOCAL_MACHINE, kEventLogProviderRegPath, WorkItem::kWow64Default, | 
| + L"CategoryCount", static_cast<DWORD>(1), true); | 
| + // Specifies the event type emitted by this event source. | 
| + work_item_list->AddSetRegValueWorkItem( | 
| + HKEY_LOCAL_MACHINE, kEventLogProviderRegPath, WorkItem::kWow64Default, | 
| + L"TypesSupported", | 
| + static_cast<DWORD>(EVENTLOG_ERROR_TYPE | EVENTLOG_INFORMATION_TYPE | | 
| + EVENTLOG_WARNING_TYPE), | 
| + true); | 
| + | 
| + const base::FilePath provider(install_directory.AppendASCII(version).Append( | 
| + FILE_PATH_LITERAL("eventlog_provider.dll"))); | 
| + | 
| + static constexpr const wchar_t* file_keys[] = { | 
| 
grt (UTC plus 2)
2016/11/24 07:49:34
nit: kFileKeys
 
pastarmovj
2016/11/24 09:51:09
Done.
 | 
| + L"CategoryMessageFile", L"EventMessageFile", L"ParameterMessageFile", | 
| + }; | 
| + for (const wchar_t* file_key : file_keys) { | 
| + work_item_list->AddSetRegValueWorkItem( | 
| + HKEY_LOCAL_MACHINE, kEventLogProviderRegPath, WorkItem::kWow64Default, | 
| + file_key, provider.value(), true); | 
| + } | 
| + | 
| + // if the operation fails we log the error but still continue because none of | 
| + // these are critical for the proper operation of the browser. | 
| + if (!work_item_list->Do()) | 
| + work_item_list->Rollback(); | 
| +} | 
| + | 
| +void DeRegisterEventLogProvider() { | 
| + // TODO(http://crbug.com/668120): If the Event Viewer is open the provider dll | 
| + // will fail to get deleted. This doesn't fail the uninstallation altogether | 
| + // but leaves files behind. | 
| + InstallUtil::DeleteRegistryKey(HKEY_LOCAL_MACHINE, kEventLogProviderRegPath, | 
| + WorkItem::kWow64Default); | 
| +} | 
| + | 
| ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | 
| : is_enabled_(false) { | 
| HANDLE temp_handle; |