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

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

Issue 2576843002: [win] Create ModuleDatabase and ModuleEventSinkImpl. (Closed)
Patch Set: Rework OnProcessStarted. 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..e5e3d3595a30507f414652737f359c8bbb4bebe5 100644
--- a/chrome/common/conflicts/module_watcher_win.cc
+++ b/chrome/common/conflicts/module_watcher_win.cc
@@ -96,27 +96,33 @@ 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::string16(str->Buffer, str->Length / sizeof(wchar_t)));
grt (UTC plus 2) 2016/12/20 11:11:35 nit: base::StringPiece16(str->Buffer, str->Length
chrisha 2016/12/20 19:46:24 Done.
}
template <typename NotificationDataType>
-void OnModuleEvent(mojom::ModuleEventType event_type,
+void OnModuleEvent(const mojom::ModuleEventType& event_type,
grt (UTC plus 2) 2016/12/20 11:11:35 passing an enum by constref?
chrisha 2016/12/20 19:46:24 Errr.... oops? Done.
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);
}
} // namespace
+ModuleWatcher::ModuleEvent::ModuleEvent(mojom::ModuleEventType event_type,
grt (UTC plus 2) 2016/12/20 11:11:35 is this sufficiently trivial that it could be inli
chrisha 2016/12/20 19:46:24 Done.
+ const base::FilePath& module_path,
+ void* module_load_address,
+ size_t module_size)
+ : event_type(event_type),
+ module_path(module_path),
+ module_load_address(module_load_address),
+ module_size(module_size) {}
+
// static
std::unique_ptr<ModuleWatcher> ModuleWatcher::Create(
const OnModuleEventCallback& callback) {
@@ -178,11 +184,9 @@ void ModuleWatcher::EnumerateAlreadyLoadedModules() {
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(base::UTF8ToWide(path)),
grt (UTC plus 2) 2016/12/20 11:11:35 while i loves me a good conversion, how about usin
chrisha 2016/12/20 19:46:24 Oops, remnants of when this was being stored as as
+ module.modBaseAddr, module.modBaseSize);
callback_.Run(event);
grt (UTC plus 2) 2016/12/20 11:11:35 nit: i'd be inclined to inline the ModuleEvent, bu
chrisha 2016/12/20 19:46:24 I lean towards verbosity, as I personally find it
grt (UTC plus 2) 2016/12/20 21:09:53 Acknowledged.
}

Powered by Google App Engine
This is Rietveld 408576698