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

Unified Diff: chrome/common/conflicts/module_watcher_win.cc

Issue 2576843002: [win] Create ModuleDatabase and ModuleEventSinkImpl. (Closed)
Patch Set: Moar comments, fix typos. Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/conflicts/module_watcher_win.cc
diff --git a/chrome/common/conflicts/module_watcher_win.cc b/chrome/common/conflicts/module_watcher_win.cc
index 424fd134ec78875c4fae6e7443c1d6fe467579de..9fd3d6b58849c56d493b5c2c6133c494fabdda4e 100644
--- a/chrome/common/conflicts/module_watcher_win.cc
+++ b/chrome/common/conflicts/module_watcher_win.cc
@@ -12,6 +12,7 @@
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
+#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/win/scoped_handle.h"
@@ -96,22 +97,19 @@ constexpr wchar_t kNtDll[] = L"ntdll.dll";
constexpr char kLdrRegisterDllNotification[] = "LdrRegisterDllNotification";
constexpr char kLdrUnregisterDllNotification[] = "LdrUnregisterDllNotification";
-// Helper function for converting a UNICODE_STRING to a UTF8 std::string.
-std::string ToString(const UNICODE_STRING* str) {
- std::string s;
- base::WideToUTF8(str->Buffer, str->Length / sizeof(wchar_t), &s);
- return s;
+// Helper function for converting a UNICODE_STRING to a FilePath.
+base::FilePath ToFilePath(const UNICODE_STRING* str) {
+ return base::FilePath(
+ base::StringPiece16(str->Buffer, str->Length / sizeof(wchar_t)));
}
template <typename NotificationDataType>
void OnModuleEvent(mojom::ModuleEventType event_type,
const NotificationDataType& notification_data,
const ModuleWatcher::OnModuleEventCallback& callback) {
- mojom::ModuleEvent event;
- event.event_type = event_type;
- event.module_path = ToString(notification_data.FullDllName);
- event.load_address = reinterpret_cast<uintptr_t>(notification_data.DllBase);
- event.size = notification_data.SizeOfImage;
+ ModuleWatcher::ModuleEvent event(
+ event_type, ToFilePath(notification_data.FullDllName),
+ notification_data.DllBase, notification_data.SizeOfImage);
callback.Run(event);
}
@@ -119,7 +117,7 @@ void OnModuleEvent(mojom::ModuleEventType event_type,
// static
std::unique_ptr<ModuleWatcher> ModuleWatcher::Create(
- const OnModuleEventCallback& callback) {
+ OnModuleEventCallback callback) {
// If a ModuleWatcher already exists then bail out.
base::AutoLock lock(g_module_watcher_lock.Get());
if (g_module_watcher_instance)
@@ -174,15 +172,11 @@ void ModuleWatcher::EnumerateAlreadyLoadedModules() {
// Walk the module list.
MODULEENTRY32 module = {sizeof(module)};
- std::string path;
for (BOOL result = ::Module32First(snap.Get(), &module); result != FALSE;
result = ::Module32Next(snap.Get(), &module)) {
- base::WideToUTF8(module.szExePath, ::wcslen(module.szExePath), &path);
- mojom::ModuleEvent event;
- event.event_type = mojom::ModuleEventType::MODULE_ALREADY_LOADED;
- event.module_path = path;
- event.load_address = reinterpret_cast<uintptr_t>(module.modBaseAddr);
- event.size = module.modBaseSize;
+ ModuleEvent event(mojom::ModuleEventType::MODULE_ALREADY_LOADED,
+ base::FilePath(module.szExePath), module.modBaseAddr,
+ module.modBaseSize);
callback_.Run(event);
}
@@ -225,7 +219,7 @@ void __stdcall ModuleWatcher::LoaderNotificationCallback(
}
}
-ModuleWatcher::ModuleWatcher(const OnModuleEventCallback& callback)
+ModuleWatcher::ModuleWatcher(OnModuleEventCallback callback)
: callback_(callback) {
grt (UTC plus 2) 2016/12/22 14:19:07 std::move
chrisha 2017/01/03 21:34:48 Done.
RegisterDllNotificationCallback();
EnumerateAlreadyLoadedModules();

Powered by Google App Engine
This is Rietveld 408576698