Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #ifndef CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ | |
| 6 #define CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "chrome/common/conflicts/module_event_win.mojom.h" | |
| 10 | |
| 11 namespace conflicts { | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
don't put this in a namespace; see https://groups.
chrisha
2016/11/08 21:45:21
Done.
| |
| 12 | |
| 13 class ModuleWatcherTest; | |
| 14 | |
| 15 // This class observes modules as they are loaded and unloaded into a process' | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
process's
chrisha
2016/11/08 21:45:22
Oh sweet jebus, you just opened a can of worms:
h
| |
| 16 // address space. It works by installing a DllNotification callback, and | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
is this documenting an implementation detail, or d
chrisha
2016/11/08 21:45:21
Done.
| |
| 17 // also enumerating all currently loaded modules at the time of its creation. | |
| 18 // It doesn't really make sense to create more than one of these in a process, | |
| 19 // although it's entirely possible. | |
| 20 // | |
| 21 // This class is safe to be created on any thread. Similarly, it is safe to be | |
| 22 // destroyed on any thread, independent of the thread on which the instance was | |
| 23 // created. The only constraint is that the constructor and destructor do not | |
| 24 // run concurrently on two separate threads (a bad idea anyways). | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
are you saying i shouldn't use this foot gun i hav
chrisha
2016/11/08 21:45:22
Acknowledged.
| |
| 25 class ModuleWatcher { | |
| 26 public: | |
| 27 using OnModuleEventCallback = | |
| 28 base::Callback<void(const mojom::ModuleEvent& event)>; | |
| 29 | |
| 30 // Creates and starts a watcher. This enumerates all loaded modules | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
does this mean that |callback| is invoked synchron
chrisha
2016/11/08 21:45:22
Done.
| |
| 31 // synchronously on the current thread, and then registers a DllNotification | |
| 32 // callback for continued notifications. Notifications originating from the | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
is this saying that |callback| may be invoked from
chrisha
2016/11/08 21:45:22
Done.
| |
| 33 // DllNotification API can arrive from any thread. Note that it is possible to | |
| 34 // receive two modifications for some modules as the initial loaded module | |
| 35 // enumeration races with the installation of the callback. In this case both | |
| 36 // a MODULE_LOADED and a MODULE_ALREADY_LOADED event will be received for the | |
| 37 // same module. Since the callback is installed first no modules can be | |
| 38 // missed, however. This can be called on any thread. | |
| 39 explicit ModuleWatcher(const OnModuleEventCallback& callback); | |
| 40 | |
| 41 // Destructor. Unregisters the DllNotification callback if it was successfully | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
"Destructor" is obvious, remove it.
chrisha
2016/11/08 21:45:21
Done.
| |
| 42 // registered in the constructor. This need not be called on the same thread | |
| 43 // as the constructor as the OS provides synchronization via the | |
| 44 // DllNotification API. This can be called on any thread. | |
| 45 ~ModuleWatcher(); | |
| 46 | |
| 47 protected: | |
| 48 // Used as a bridge between the operating system notifications and this class. | |
| 49 class Bridge; | |
| 50 | |
| 51 // The Bridge requires access to Notify. | |
| 52 friend class Bridge; | |
| 53 // For unittesting. | |
| 54 friend class ModuleWatcherTest; | |
| 55 | |
| 56 // Registers a DllNotification callback with the OS. Returns true on success, | |
| 57 // false otherwise. Modifies |dll_notification_cookie_|. Can be called on any | |
| 58 // thread. Invoked by the constructor. | |
| 59 bool RegisterDllNotificationCallback(); | |
| 60 | |
| 61 // Removes the installed DllNotification callback. Returns true on success, | |
| 62 // false otherwise. Modifies |dll_notification_cookie_|. Can be called on any | |
| 63 // thread. Invoked by the destructor. | |
| 64 bool UnregisterDllNotificationCallback(); | |
| 65 | |
| 66 // Enumerates all currently loaded modules, synchonously invoking callbacks on | |
| 67 // the current thread. Returns true on success, false otherwise. Can be | |
| 68 // called on any thread. Invoked by the constructor. | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
"Invoked by the constructor." is it necessary to d
chrisha
2016/11/08 21:45:21
Done.
| |
| 69 bool EnumerateAlreadyLoadedModules(); | |
| 70 | |
| 71 // Invoked by ModuleWatcher::Bridge. Dispatches the notification via | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
"Invoked by..." same comment
chrisha
2016/11/08 21:45:22
Done.
| |
| 72 // |callback_|. | |
| 73 void Notify(const mojom::ModuleEvent& event); | |
| 74 | |
| 75 private: | |
| 76 // The current callback. Can end up being invoked on any thread. | |
| 77 OnModuleEventCallback callback_; | |
| 78 // Used by the DllNotification mechanism. | |
| 79 void* dll_notification_cookie_; | |
|
grt (UTC plus 2)
2016/11/08 14:07:52
= nullptr; here rather than in the ctor
chrisha
2016/11/08 21:45:21
I'm not 100% a fan of that, as it leaves construct
| |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(ModuleWatcher); | |
| 82 }; | |
| 83 | |
| 84 } // namespace conflicts | |
| 85 | |
| 86 #endif // CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ | |
| OLD | NEW |