OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // All Rights Reserved. | 4 // All Rights Reserved. |
5 | 5 |
6 #include "base/registry.h" | 6 #include "base/registry.h" |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <shlwapi.h> | 9 #include <shlwapi.h> |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 344 } |
345 | 345 |
346 | 346 |
347 bool RegKey::DeleteValue(const tchar * value_name) { | 347 bool RegKey::DeleteValue(const tchar * value_name) { |
348 assert(value_name); | 348 assert(value_name); |
349 HRESULT const result = RegDeleteValue(key_, value_name); | 349 HRESULT const result = RegDeleteValue(key_, value_name); |
350 return (result == ERROR_SUCCESS); | 350 return (result == ERROR_SUCCESS); |
351 } | 351 } |
352 | 352 |
353 bool RegKey::StartWatching() { | 353 bool RegKey::StartWatching() { |
354 assert(watch_event_ == 0); | 354 if (!watch_event_) |
355 watch_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); | 355 watch_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); |
| 356 |
356 DWORD filter = REG_NOTIFY_CHANGE_NAME | | 357 DWORD filter = REG_NOTIFY_CHANGE_NAME | |
357 REG_NOTIFY_CHANGE_ATTRIBUTES | | 358 REG_NOTIFY_CHANGE_ATTRIBUTES | |
358 REG_NOTIFY_CHANGE_LAST_SET | | 359 REG_NOTIFY_CHANGE_LAST_SET | |
359 REG_NOTIFY_CHANGE_SECURITY; | 360 REG_NOTIFY_CHANGE_SECURITY; |
360 | 361 |
361 // Watch the registry key for a change of value. | 362 // Watch the registry key for a change of value. |
362 HRESULT result = RegNotifyChangeKeyValue(key_, TRUE, filter, | 363 HRESULT result = RegNotifyChangeKeyValue(key_, TRUE, filter, |
363 watch_event_, TRUE); | 364 watch_event_, TRUE); |
364 if (SUCCEEDED(result)) { | 365 if (SUCCEEDED(result)) { |
365 return true; | 366 return true; |
366 } else { | 367 } else { |
367 CloseHandle(watch_event_); | 368 CloseHandle(watch_event_); |
368 watch_event_ = 0; | 369 watch_event_ = 0; |
369 return false; | 370 return false; |
370 } | 371 } |
371 } | 372 } |
372 | 373 |
373 bool RegKey::StopWatching() { | 374 bool RegKey::StopWatching() { |
374 if (watch_event_) { | 375 if (watch_event_) { |
375 CloseHandle(watch_event_); | 376 CloseHandle(watch_event_); |
376 watch_event_ = 0; | 377 watch_event_ = 0; |
377 return true; | 378 return true; |
378 } | 379 } |
379 return false; | 380 return false; |
380 } | 381 } |
381 | 382 |
382 bool RegKey::HasChanged() { | 383 bool RegKey::HasChanged() { |
383 if (watch_event_) { | 384 if (watch_event_) { |
384 if (WaitForSingleObject(watch_event_, 0) == WAIT_OBJECT_0) { | 385 if (WaitForSingleObject(watch_event_, 0) == WAIT_OBJECT_0) { |
385 // An event only gets signaled once, then it's done, so we have | |
386 // to set up another event to watch. | |
387 CloseHandle(watch_event_); | |
388 watch_event_ = 0; | |
389 StartWatching(); | 386 StartWatching(); |
390 return true; | 387 return true; |
391 } | 388 } |
392 } | 389 } |
393 return false; | 390 return false; |
394 } | 391 } |
395 | 392 |
396 // Register a COM object with the most usual properties. | 393 // Register a COM object with the most usual properties. |
397 bool RegisterCOMServer(const tchar* guid, | 394 bool RegisterCOMServer(const tchar* guid, |
398 const tchar* name, | 395 const tchar* name, |
(...skipping 12 matching lines...) Expand all Loading... |
411 ::GetModuleFileName(module, module_path, MAX_PATH); | 408 ::GetModuleFileName(module, module_path, MAX_PATH); |
412 _tcslwr_s(module_path, MAX_PATH); | 409 _tcslwr_s(module_path, MAX_PATH); |
413 return RegisterCOMServer(guid, name, module_path); | 410 return RegisterCOMServer(guid, name, module_path); |
414 } | 411 } |
415 | 412 |
416 bool UnregisterCOMServer(const tchar* guid) { | 413 bool UnregisterCOMServer(const tchar* guid) { |
417 RegKey key(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_WRITE); | 414 RegKey key(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_WRITE); |
418 key.DeleteKey(guid); | 415 key.DeleteKey(guid); |
419 return true; | 416 return true; |
420 } | 417 } |
OLD | NEW |