Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome_frame/registry_watcher.cc

Issue 7065024: Add a self-destruct mechanism to user-level Chrome Frame when it detects that system-level Chrome... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // A utility class that makes it easy to register for registry change
6 // notifications.
7 //
8
9 #include "chrome_frame/registry_watcher.h"
10
11 #include "chrome_frame/chrome_frame_helper_util.h"
12
13 namespace {
14 const wchar_t kRegistryWatcherEventName[] = L"chrome_registry_watcher_event";
15 } // namespace
16
17 RegistryWatcher::RegistryWatcher(HKEY hive,
18 const wchar_t* path,
19 WAITORTIMERCALLBACK callback)
20 : callback_(callback),
21 wait_event_(NULL),
22 wait_handle_(NULL),
23 stopping_(false) {
24 // Enforce that we can open the given registry path with the KEY_NOTIFY
25 // permission.
26 LONG result = RegOpenKeyEx(hive, path, 0, KEY_NOTIFY, &registry_key_);
27 if (result != ERROR_SUCCESS) {
28 registry_key_ = NULL;
29 }
30 }
31
32 RegistryWatcher::~RegistryWatcher() {
33 StopWatching();
34 if (registry_key_) {
35 RegCloseKey(registry_key_);
36 registry_key_ = NULL;
37 }
38 }
39
40 bool RegistryWatcher::StartWatching() {
41 if (!registry_key_ || wait_event_ || !callback_) {
42 return false;
43 }
44
45 bool result = false;
46 wait_event_ = CreateEvent(NULL,
47 FALSE, // Auto-resets
48 FALSE, // Initially non-signalled
49 kRegistryWatcherEventName);
50 if (wait_event_ != NULL) {
51 LONG notify_result = RegNotifyChangeKeyValue(
52 registry_key_,
53 TRUE, // Watch subtree
54 REG_NOTIFY_CHANGE_NAME, // Notifies if a subkey is added.
55 wait_event_,
56 TRUE); // Asynchronous, signal the event when a change occurs.
57
58 if (notify_result == ERROR_SUCCESS) {
59 if (RegisterWaitForSingleObject(&wait_handle_,
60 wait_event_,
61 callback_,
62 reinterpret_cast<void*>(this),
63 INFINITE,
64 WT_EXECUTEDEFAULT)) {
65 stopping_ = false;
66 result = true;
67 }
grt (UTC plus 2) 2011/05/26 17:08:58 else { CloseHandle(wait_event_); wait_event_ = NUL
robertshield 2011/05/27 03:34:59 Need to do this if either the RegisterWait..() or
68 }
69 }
70
71 return result;
72 }
73
74 void RegistryWatcher::StopWatching() {
75 stopping_ = true;
76 if (wait_handle_) {
77 // Unregister the wait and block until any current handlers have returned.
78 UnregisterWaitEx(wait_handle_, INVALID_HANDLE_VALUE);
79 wait_handle_ = NULL;
80 }
81 if (wait_event_) {
82 CloseHandle(wait_event_);
83 wait_event_ = NULL;
84 }
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698