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

Side by Side Diff: chrome/common/conflicts/module_watcher_win.h

Issue 2473783005: [Win] Create ModuleWatcher. (Closed)
Patch Set: Small cleanup. Created 4 years, 1 month 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
OLDNEW
(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 class ModuleWatcherTest;
12
13 // This class observes modules as they are loaded and unloaded into a process's
14 // address space.
15 //
16 // This class is safe to be created on any thread. Similarly, it is safe to be
17 // destroyed on any thread, independent of the thread on which the instance was
18 // created.
19 class ModuleWatcher {
20 public:
21 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.
22 base::Callback<void(const mojom::ModuleEvent& event)>;
23
24 // Creates and starts a watcher. This enumerates all loaded modules
25 // synchronously on the current thread during construction, and provides
26 // synchronous notifications as modules are loaded and unloaded. The callback
27 // is invoked in the context of the thread that is loading a module (under the
28 // 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
29 // 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.
30 // the initial loaded module enumeration races briefly with the callback
31 // mechanism. In this case both a MODULE_LOADED and a MODULE_ALREADY_LOADED
32 // event will be received for the same module. Since the callback is installed
33 // first no modules can be missed, however. This factory function may be
34 // called on any thread.
35 //
36 // Only a single instance of a watcher may exist at any moment. This will
37 // return nullptr when trying to create a second watcher.
38 static std::unique_ptr<ModuleWatcher> Create(
39 const OnModuleEventCallback& callback);
40
41 // This can be called on any thread. After destruction the |callback|
42 // provided to the constructor will no longer be invoked with module events.
43 ~ModuleWatcher();
44
45 protected:
46 // For unittesting.
47 friend class ModuleWatcherTest;
48
49 // Registers a DllNotification callback with the OS. Returns true on success,
50 // false otherwise. Modifies |dll_notification_cookie_|. Can be called on any
51 // thread.
52 bool RegisterDllNotificationCallback();
53
54 // Removes the installed DllNotification callback. Returns true on success,
55 // false otherwise. Modifies |dll_notification_cookie_|. Can be called on any
56 // thread.
57 bool UnregisterDllNotificationCallback();
58
59 // Enumerates all currently loaded modules, synchonously invoking callbacks on
60 // the current thread. Returns true on success, false otherwise. Can be
61 // called on any thread.
62 bool EnumerateAlreadyLoadedModules();
63
64 // The loader notification callback.
65 static void __stdcall LoaderNotificationCallback(
66 uint32_t notification_reason,
67 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.
68 void* context);
69
70 private:
71 // Private to enforce Singleton semantics. See Create above.
72 explicit ModuleWatcher(const OnModuleEventCallback& callback);
73
74 // The current callback. Can end up being invoked on any thread.
75 OnModuleEventCallback callback_;
76 // Used by the DllNotification mechanism.
77 void* dll_notification_cookie_ = nullptr;
78
79 DISALLOW_COPY_AND_ASSIGN(ModuleWatcher);
80 };
81
82 #endif // CHROME_COMMON_CONFLICTS_MODULE_WATCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698