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

Side by Side Diff: chrome/browser/conflicts/module_event_sink_impl_win.cc

Issue 2613803005: [win] Enable ModuleDatabase behind a flag. (Closed)
Patch Set: Rebase. 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/conflicts/module_event_sink_impl_win.h ('k') | chrome/common/chrome_features.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/conflicts/module_event_sink_impl_win.h" 5 #include "chrome/browser/conflicts/module_event_sink_impl_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <psapi.h> 8 #include <psapi.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "chrome/browser/conflicts/module_database_win.h" 18 #include "chrome/browser/conflicts/module_database_win.h"
19 #include "chrome/common/conflicts/module_watcher_win.h" 19 #include "chrome/common/conflicts/module_watcher_win.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "mojo/public/cpp/bindings/strong_binding.h" 21 #include "mojo/public/cpp/bindings/strong_binding.h"
22 22
23 namespace { 23 namespace {
24 24
25 // Gets the process creation time associated with the given process.
26 bool GetProcessCreationTime(base::ProcessHandle process,
27 uint64_t* creation_time) {
28 FILETIME creation_ft = {};
29 FILETIME exit_ft = {};
30 FILETIME kernel_ft = {};
31 FILETIME user_ft = {};
32 if (!::GetProcessTimes(process, &creation_ft, &exit_ft, &kernel_ft,
33 &user_ft)) {
34 return false;
35 }
36 *creation_time = (static_cast<uint64_t>(creation_ft.dwHighDateTime) << 32) |
37 static_cast<uint64_t>(creation_ft.dwLowDateTime);
38 return true;
39 }
40
41 // Gets the path of the module in the provided remote process. Returns true on 25 // Gets the path of the module in the provided remote process. Returns true on
42 // success, false otherwise. 26 // success, false otherwise.
43 bool GetModulePath(base::ProcessHandle process, 27 bool GetModulePath(base::ProcessHandle process,
44 HMODULE module, 28 HMODULE module,
45 base::FilePath* path) { 29 base::FilePath* path) {
46 std::vector<wchar_t> temp_path(MAX_PATH); 30 std::vector<wchar_t> temp_path(MAX_PATH);
47 size_t length = 0; 31 size_t length = 0;
48 while (true) { 32 while (true) {
49 length = ::GetModuleFileNameEx(process, module, temp_path.data(), 33 length = ::GetModuleFileNameEx(process, module, temp_path.data(),
50 temp_path.size()); 34 temp_path.size());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (!GetProcessCreationTime(process_, &creation_time_)) { 109 if (!GetProcessCreationTime(process_, &creation_time_)) {
126 in_error_ = true; 110 in_error_ = true;
127 return; 111 return;
128 } 112 }
129 module_database->OnProcessStarted(process_id_, creation_time_, process_type); 113 module_database->OnProcessStarted(process_id_, creation_time_, process_type);
130 } 114 }
131 115
132 ModuleEventSinkImpl::~ModuleEventSinkImpl() = default; 116 ModuleEventSinkImpl::~ModuleEventSinkImpl() = default;
133 117
134 // static 118 // static
135 void ModuleEventSinkImpl::Create(base::ProcessHandle process, 119 void ModuleEventSinkImpl::Create(GetProcessHandleCallback get_process_handle,
136 content::ProcessType process_type, 120 content::ProcessType process_type,
137 ModuleDatabase* module_database, 121 ModuleDatabase* module_database,
138 mojom::ModuleEventSinkRequest request) { 122 mojom::ModuleEventSinkRequest request) {
139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
124 base::ProcessHandle process = get_process_handle.Run();
140 auto module_event_sink_impl = base::MakeUnique<ModuleEventSinkImpl>( 125 auto module_event_sink_impl = base::MakeUnique<ModuleEventSinkImpl>(
141 process, process_type, module_database); 126 process, process_type, module_database);
142 base::Closure error_handler = base::Bind( 127 base::Closure error_handler = base::Bind(
143 &ModuleDatabase::OnProcessEnded, base::Unretained(module_database), 128 &ModuleDatabase::OnProcessEnded, base::Unretained(module_database),
144 module_event_sink_impl->process_id_, 129 module_event_sink_impl->process_id_,
145 module_event_sink_impl->creation_time_); 130 module_event_sink_impl->creation_time_);
146 auto binding = mojo::MakeStrongBinding(std::move(module_event_sink_impl), 131 auto binding = mojo::MakeStrongBinding(std::move(module_event_sink_impl),
147 std::move(request)); 132 std::move(request));
148 binding->set_connection_error_handler(error_handler); 133 binding->set_connection_error_handler(error_handler);
149 } 134 }
(...skipping 12 matching lines...) Expand all
162 switch (event_type) { 147 switch (event_type) {
163 case mojom::ModuleEventType::MODULE_ALREADY_LOADED: 148 case mojom::ModuleEventType::MODULE_ALREADY_LOADED:
164 case mojom::ModuleEventType::MODULE_LOADED: 149 case mojom::ModuleEventType::MODULE_LOADED:
165 return OnModuleLoad(load_address); 150 return OnModuleLoad(load_address);
166 151
167 case mojom::ModuleEventType::MODULE_UNLOADED: 152 case mojom::ModuleEventType::MODULE_UNLOADED:
168 return OnModuleUnload(load_address); 153 return OnModuleUnload(load_address);
169 } 154 }
170 } 155 }
171 156
157 // static
158 bool ModuleEventSinkImpl::GetProcessCreationTime(base::ProcessHandle process,
159 uint64_t* creation_time) {
160 FILETIME creation_ft = {};
161 FILETIME exit_ft = {};
162 FILETIME kernel_ft = {};
163 FILETIME user_ft = {};
164 if (!::GetProcessTimes(process, &creation_ft, &exit_ft, &kernel_ft,
165 &user_ft)) {
166 return false;
167 }
168 *creation_time = (static_cast<uint64_t>(creation_ft.dwHighDateTime) << 32) |
169 static_cast<uint64_t>(creation_ft.dwLowDateTime);
170 return true;
171 }
172
172 void ModuleEventSinkImpl::OnModuleLoad(uint64_t load_address) { 173 void ModuleEventSinkImpl::OnModuleLoad(uint64_t load_address) {
173 if (in_error_) 174 if (in_error_)
174 return; 175 return;
175 176
176 // The |load_address| is a unique key to a module in a remote process. If 177 // The |load_address| is a unique key to a module in a remote process. If
177 // there is a valid module there then the following queries should all pass. 178 // there is a valid module there then the following queries should all pass.
178 // If any of them fail then the load event is silently swallowed. The entire 179 // If any of them fail then the load event is silently swallowed. The entire
179 // channel is not marked as being in an error mode, as later events may be 180 // channel is not marked as being in an error mode, as later events may be
180 // well formed. 181 // well formed.
181 182
(...skipping 19 matching lines...) Expand all
201 module_database_->OnModuleLoad(process_id_, creation_time_, module_path, 202 module_database_->OnModuleLoad(process_id_, creation_time_, module_path,
202 module_size, module_time_date_stamp, 203 module_size, module_time_date_stamp,
203 load_address); 204 load_address);
204 } 205 }
205 206
206 void ModuleEventSinkImpl::OnModuleUnload(uint64_t load_address) { 207 void ModuleEventSinkImpl::OnModuleUnload(uint64_t load_address) {
207 // Forward this directly to the module database. 208 // Forward this directly to the module database.
208 module_database_->OnModuleUnload(process_id_, creation_time_, 209 module_database_->OnModuleUnload(process_id_, creation_time_,
209 static_cast<uintptr_t>(load_address)); 210 static_cast<uintptr_t>(load_address));
210 } 211 }
OLDNEW
« no previous file with comments | « chrome/browser/conflicts/module_event_sink_impl_win.h ('k') | chrome/common/chrome_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698