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

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

Issue 2634073002: Revert of [win] Create ModuleDatabase and ModuleEventSinkImpl. (Closed)
Patch Set: Created 3 years, 11 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 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 fca97a36658fc16b36c95df2cf087ad9104f5d69..424fd134ec78875c4fae6e7443c1d6fe467579de 100644
--- a/chrome/common/conflicts/module_watcher_win.cc
+++ b/chrome/common/conflicts/module_watcher_win.cc
@@ -9,11 +9,9 @@
#include <winternl.h> // For UNICODE_STRING.
#include <string>
-#include <utility>
#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"
@@ -98,19 +96,22 @@
constexpr char kLdrRegisterDllNotification[] = "LdrRegisterDllNotification";
constexpr char kLdrUnregisterDllNotification[] = "LdrUnregisterDllNotification";
-// 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)));
+// 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;
}
template <typename NotificationDataType>
void OnModuleEvent(mojom::ModuleEventType event_type,
const NotificationDataType& notification_data,
const ModuleWatcher::OnModuleEventCallback& callback) {
- ModuleWatcher::ModuleEvent event(
- event_type, ToFilePath(notification_data.FullDllName),
- notification_data.DllBase, notification_data.SizeOfImage);
+ 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;
callback.Run(event);
}
@@ -118,14 +119,14 @@
// static
std::unique_ptr<ModuleWatcher> ModuleWatcher::Create(
- OnModuleEventCallback callback) {
+ const OnModuleEventCallback& callback) {
// If a ModuleWatcher already exists then bail out.
base::AutoLock lock(g_module_watcher_lock.Get());
if (g_module_watcher_instance)
return nullptr;
// This thread acquired the right to create a ModuleWatcher, so do so.
- g_module_watcher_instance = new ModuleWatcher(std::move(callback));
+ g_module_watcher_instance = new ModuleWatcher(callback);
return base::WrapUnique(g_module_watcher_instance);
}
@@ -173,11 +174,15 @@
// 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)) {
- ModuleEvent event(mojom::ModuleEventType::MODULE_ALREADY_LOADED,
- base::FilePath(module.szExePath), module.modBaseAddr,
- module.modBaseSize);
+ 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;
callback_.Run(event);
}
@@ -220,8 +225,8 @@
}
}
-ModuleWatcher::ModuleWatcher(OnModuleEventCallback callback)
- : callback_(std::move(callback)) {
+ModuleWatcher::ModuleWatcher(const OnModuleEventCallback& callback)
+ : callback_(callback) {
RegisterDllNotificationCallback();
EnumerateAlreadyLoadedModules();
}
« no previous file with comments | « chrome/common/conflicts/module_watcher_win.h ('k') | chrome/common/conflicts/module_watcher_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698