| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/core/system_monitor.h" | |
| 17 #include "omaha/base/constants.h" | |
| 18 #include "omaha/base/debug.h" | |
| 19 #include "omaha/base/error.h" | |
| 20 #include "omaha/base/logging.h" | |
| 21 #include "omaha/base/reg_key.h" | |
| 22 #include "omaha/common/app_registry_utils.h" | |
| 23 #include "omaha/common/const_goopdate.h" | |
| 24 | |
| 25 namespace omaha { | |
| 26 | |
| 27 SystemMonitor::SystemMonitor(bool is_machine) | |
| 28 : is_machine_(is_machine) { | |
| 29 ::InterlockedExchangePointer(reinterpret_cast<void**>(&observer_), NULL); | |
| 30 } | |
| 31 | |
| 32 SystemMonitor::~SystemMonitor() { | |
| 33 if (m_hWnd) { | |
| 34 VERIFY1(DestroyWindow()); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 HRESULT SystemMonitor::Initialize(bool monitor_registry) { | |
| 39 if (monitor_registry) { | |
| 40 registry_monitor_.reset(new RegistryMonitor); | |
| 41 if (SUCCEEDED(registry_monitor_->Initialize())) { | |
| 42 HKEY root_key = is_machine_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
| 43 VERIFY1(SUCCEEDED(registry_monitor_->MonitorValue( | |
| 44 root_key, | |
| 45 GOOPDATE_MAIN_KEY, | |
| 46 kRegValueLastChecked, | |
| 47 REG_DWORD, | |
| 48 RegistryValueChangeCallback, | |
| 49 this))); | |
| 50 VERIFY1(SUCCEEDED(registry_monitor_->MonitorKey( | |
| 51 root_key, | |
| 52 GOOPDATE_REG_RELATIVE_CLIENTS, | |
| 53 RegistryKeyChangeCallback, | |
| 54 this))); | |
| 55 VERIFY1(SUCCEEDED(registry_monitor_->StartMonitoring())); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 // Create a window to receive broadcast messages. | |
| 60 const TCHAR kWindowTitle[] = _T("{2D905E07-FC38-4b89-83E1-931D3630937F}"); | |
| 61 VERIFY1(Create(NULL, NULL, kWindowTitle)); | |
| 62 return S_OK; | |
| 63 } | |
| 64 | |
| 65 LRESULT SystemMonitor::OnPowerBroadcast(UINT, WPARAM wparam, | |
| 66 LPARAM, BOOL& handled) { | |
| 67 CORE_LOG(L3, (_T("[SystemMonitor::OnPowerBroadcast][wparam %d]"), wparam)); | |
| 68 UNREFERENCED_PARAMETER(wparam); | |
| 69 handled = true; | |
| 70 return 0; | |
| 71 } | |
| 72 | |
| 73 LRESULT SystemMonitor::OnEndSession(UINT, WPARAM wparam, | |
| 74 LPARAM lparam, BOOL& handled) { | |
| 75 CORE_LOG(L3, (_T("[SystemMonitor::OnEndSession][wparam %d][lparam %x]"), | |
| 76 wparam, lparam)); | |
| 77 UNREFERENCED_PARAMETER(wparam); | |
| 78 UNREFERENCED_PARAMETER(lparam); | |
| 79 handled = true; | |
| 80 return 0; | |
| 81 } | |
| 82 | |
| 83 LRESULT SystemMonitor::OnQueryEndSession(UINT, WPARAM, | |
| 84 LPARAM lparam, BOOL& handled) { | |
| 85 CORE_LOG(L3, (_T("[SystemMonitor::OnQueryEndSession][lparam %x]"), lparam)); | |
| 86 UNREFERENCED_PARAMETER(lparam); | |
| 87 handled = true; | |
| 88 return TRUE; | |
| 89 } | |
| 90 | |
| 91 LRESULT SystemMonitor::OnWTSSessionChange(UINT, WPARAM wparam, | |
| 92 LPARAM lparam, BOOL& handled) { | |
| 93 CORE_LOG(L3, (_T("[SystemMonitor::OnWTSSessionChange][wparam %x][lparam %d]"), | |
| 94 wparam, lparam)); | |
| 95 UNREFERENCED_PARAMETER(wparam); | |
| 96 UNREFERENCED_PARAMETER(lparam); | |
| 97 handled = true; | |
| 98 return 0; | |
| 99 } | |
| 100 | |
| 101 void SystemMonitor::RegistryValueChangeCallback(const TCHAR* key_name, | |
| 102 const TCHAR* value_name, | |
| 103 RegistryChangeType change_type, | |
| 104 const void* new_value_data, | |
| 105 void* user_data) { | |
| 106 ASSERT1(key_name); | |
| 107 ASSERT1(value_name); | |
| 108 ASSERT1(user_data); | |
| 109 | |
| 110 ASSERT1(_tcscmp(value_name, kRegValueLastChecked) == 0); | |
| 111 | |
| 112 UNREFERENCED_PARAMETER(key_name); | |
| 113 UNREFERENCED_PARAMETER(value_name); | |
| 114 UNREFERENCED_PARAMETER(new_value_data); | |
| 115 | |
| 116 SystemMonitor* system_monitor = static_cast<SystemMonitor*>(user_data); | |
| 117 if (change_type == REGISTRY_CHANGE_TYPE_DELETE && | |
| 118 system_monitor->observer_) { | |
| 119 system_monitor->observer_->LastCheckedDeleted(); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 void SystemMonitor::RegistryKeyChangeCallback(const TCHAR* key_name, | |
| 124 void* user_data) { | |
| 125 ASSERT1(key_name); | |
| 126 ASSERT1(user_data); | |
| 127 | |
| 128 UNREFERENCED_PARAMETER(key_name); | |
| 129 ASSERT1(_tcscmp(key_name, GOOPDATE_REG_RELATIVE_CLIENTS) == 0); | |
| 130 | |
| 131 SystemMonitor* system_monitor = static_cast<SystemMonitor*>(user_data); | |
| 132 if (!system_monitor->observer_) { | |
| 133 return; | |
| 134 } | |
| 135 | |
| 136 const bool is_machine = system_monitor->is_machine_; | |
| 137 size_t num_clients(0); | |
| 138 if (SUCCEEDED(app_registry_utils::GetNumClients(is_machine, &num_clients)) && | |
| 139 num_clients <= 1) { | |
| 140 system_monitor->observer_->NoRegisteredClients(); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 } // namespace omaha | |
| OLD | NEW |