Chromium Code Reviews| Index: chrome/common/conflicts/module_watcher_win.h |
| diff --git a/chrome/common/conflicts/module_watcher_win.h b/chrome/common/conflicts/module_watcher_win.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..31b0a19c49238fd1cb031e4fcb96bd410b333783 |
| --- /dev/null |
| +++ b/chrome/common/conflicts/module_watcher_win.h |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ |
| +#define CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ |
| + |
| +#include "base/callback.h" |
| +#include "chrome/common/conflicts/module_event_win.mojom.h" |
| + |
| +class ModuleWatcherTest; |
| + |
| +// This class observes modules as they are loaded and unloaded into a process's |
| +// address space. |
| +// |
| +// This class is safe to be created on any thread. Similarly, it is safe to be |
| +// destroyed on any thread, independent of the thread on which the instance was |
| +// created. |
| +class ModuleWatcher { |
| + public: |
| + using OnModuleEventCallback = |
|
grt (UTC plus 2)
2016/11/10 08:52:13
please add a doc comment explaining the restrictio
chrisha
2016/11/14 16:06:45
Done.
|
| + base::Callback<void(const mojom::ModuleEvent& event)>; |
| + |
| + // Creates and starts a watcher. This enumerates all loaded modules |
| + // synchronously on the current thread during construction, and provides |
| + // synchronous notifications as modules are loaded and unloaded. The callback |
| + // is invoked in the context of the thread that is loading a module (under the |
| + // loader's lock!), and as such may be invoked on any thread in the process. |
|
grt (UTC plus 2)
2016/11/10 08:52:12
is it under the loader's lock? i thought your disc
chrisha
2016/11/14 16:06:45
Removed the loader lock discussion entirely, as pe
|
| + // Note that it is possible to receive two modifications for some modules as |
|
grt (UTC plus 2)
2016/11/10 08:52:13
modifications -> notifications?
chrisha
2016/11/14 16:06:45
Done.
|
| + // the initial loaded module enumeration races briefly with the callback |
| + // mechanism. In this case both a MODULE_LOADED and a MODULE_ALREADY_LOADED |
| + // event will be received for the same module. Since the callback is installed |
| + // first no modules can be missed, however. This factory function may be |
| + // called on any thread. |
| + // |
| + // Only a single instance of a watcher may exist at any moment. This will |
| + // return nullptr when trying to create a second watcher. |
| + static std::unique_ptr<ModuleWatcher> Create( |
| + const OnModuleEventCallback& callback); |
| + |
| + // This can be called on any thread. After destruction the |callback| |
| + // provided to the constructor will no longer be invoked with module events. |
| + ~ModuleWatcher(); |
| + |
| + protected: |
| + // For unittesting. |
| + friend class ModuleWatcherTest; |
| + |
| + // Registers a DllNotification callback with the OS. Returns true on success, |
| + // false otherwise. Modifies |dll_notification_cookie_|. Can be called on any |
| + // thread. |
| + bool RegisterDllNotificationCallback(); |
| + |
| + // Removes the installed DllNotification callback. Returns true on success, |
| + // false otherwise. Modifies |dll_notification_cookie_|. Can be called on any |
| + // thread. |
| + bool UnregisterDllNotificationCallback(); |
| + |
| + // Enumerates all currently loaded modules, synchonously invoking callbacks on |
| + // the current thread. Returns true on success, false otherwise. Can be |
| + // called on any thread. |
| + bool EnumerateAlreadyLoadedModules(); |
| + |
| + // The loader notification callback. |
| + static void __stdcall LoaderNotificationCallback( |
| + uint32_t notification_reason, |
| + const void* notification_data, |
|
grt (UTC plus 2)
2016/11/10 08:52:12
can you forward-decl LDR_DLL_NOTIFICATION_DATA in
chrisha
2016/11/14 16:06:45
Done.
|
| + void* context); |
| + |
| + private: |
| + // Private to enforce Singleton semantics. See Create above. |
| + explicit ModuleWatcher(const OnModuleEventCallback& callback); |
| + |
| + // The current callback. Can end up being invoked on any thread. |
| + OnModuleEventCallback callback_; |
| + // Used by the DllNotification mechanism. |
| + void* dll_notification_cookie_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ModuleWatcher); |
| +}; |
| + |
| +#endif // CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_ |