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

Side by Side Diff: chrome/browser/chrome_browser_main_win.cc

Issue 2613803005: [win] Enable ModuleDatabase behind a flag. (Closed)
Patch Set: Address grt's nits, more comments. 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_browser_main_win.h" 5 #include "chrome/browser/chrome_browser_main_win.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h>
9 #include <windows.h> 10 #include <windows.h>
10 11
11 #include <algorithm> 12 #include <algorithm>
12 #include <memory> 13 #include <memory>
13 14
14 #include "base/base_switches.h" 15 #include "base/base_switches.h"
15 #include "base/command_line.h" 16 #include "base/command_line.h"
16 #include "base/environment.h" 17 #include "base/environment.h"
17 #include "base/files/file_enumerator.h" 18 #include "base/files/file_enumerator.h"
18 #include "base/files/file_path.h" 19 #include "base/files/file_path.h"
19 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
20 #include "base/i18n/rtl.h" 21 #include "base/i18n/rtl.h"
21 #include "base/location.h" 22 #include "base/location.h"
22 #include "base/macros.h" 23 #include "base/macros.h"
23 #include "base/metrics/histogram_macros.h" 24 #include "base/metrics/histogram_macros.h"
24 #include "base/path_service.h" 25 #include "base/path_service.h"
25 #include "base/scoped_native_library.h" 26 #include "base/scoped_native_library.h"
26 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
27 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "base/win/pe_image.h"
28 #include "base/win/registry.h" 30 #include "base/win/registry.h"
29 #include "base/win/win_util.h" 31 #include "base/win/win_util.h"
30 #include "base/win/windows_version.h" 32 #include "base/win/windows_version.h"
31 #include "base/win/wrapped_window_proc.h" 33 #include "base/win/wrapped_window_proc.h"
34 #include "chrome/browser/conflicts/module_database_win.h"
35 #include "chrome/browser/conflicts/module_event_sink_impl_win.h"
32 #include "chrome/browser/first_run/first_run.h" 36 #include "chrome/browser/first_run/first_run.h"
33 #include "chrome/browser/install_verification/win/install_verification.h" 37 #include "chrome/browser/install_verification/win/install_verification.h"
34 #include "chrome/browser/profiles/profile_shortcut_manager.h" 38 #include "chrome/browser/profiles/profile_shortcut_manager.h"
35 #include "chrome/browser/shell_integration.h" 39 #include "chrome/browser/shell_integration.h"
36 #include "chrome/browser/ui/simple_message_box.h" 40 #include "chrome/browser/ui/simple_message_box.h"
37 #include "chrome/browser/ui/uninstall_browser_prompt.h" 41 #include "chrome/browser/ui/uninstall_browser_prompt.h"
38 #include "chrome/browser/win/browser_util.h" 42 #include "chrome/browser/win/browser_util.h"
39 #include "chrome/browser/win/chrome_elf_init.h" 43 #include "chrome/browser/win/chrome_elf_init.h"
40 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" 44 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
41 #include "chrome/common/chrome_constants.h" 45 #include "chrome/common/chrome_constants.h"
46 #include "chrome/common/chrome_features.h"
42 #include "chrome/common/chrome_paths.h" 47 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_result_codes.h" 48 #include "chrome/common/chrome_result_codes.h"
44 #include "chrome/common/chrome_switches.h" 49 #include "chrome/common/chrome_switches.h"
45 #include "chrome/common/chrome_utility_messages.h" 50 #include "chrome/common/chrome_utility_messages.h"
46 #include "chrome/common/crash_keys.h" 51 #include "chrome/common/crash_keys.h"
47 #include "chrome/common/env_vars.h" 52 #include "chrome/common/env_vars.h"
48 #include "chrome/grit/chromium_strings.h" 53 #include "chrome/grit/chromium_strings.h"
49 #include "chrome/grit/generated_resources.h" 54 #include "chrome/grit/generated_resources.h"
50 #include "chrome/installer/util/browser_distribution.h" 55 #include "chrome/installer/util/browser_distribution.h"
51 #include "chrome/installer/util/helper.h" 56 #include "chrome/installer/util/helper.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 200
196 // Look for the DLLs used to implement the FTH and other compat hacks. 201 // Look for the DLLs used to implement the FTH and other compat hacks.
197 if (GetModuleHandleW(L"AcLayers.dll") != NULL) 202 if (GetModuleHandleW(L"AcLayers.dll") != NULL)
198 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); 203 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED);
199 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) 204 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL)
200 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); 205 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED);
201 206
202 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); 207 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT);
203 } 208 }
204 209
210 // Helper function for getting the time date stamp associated with a module in
211 // this process.
212 uint32_t GetModuleTimeDateStamp(const void* module_load_address) {
213 base::win::PEImage pe_image(module_load_address);
214 return pe_image.GetNTHeaders()->FileHeader.TimeDateStamp;
215 }
216
217 // Used as the callback for ModuleWatcher events in this process. Dispatches
218 // them to the ModuleDatabase.
219 void OnModuleEvent(uint32_t process_id,
220 uint64_t creation_time,
221 const ModuleWatcher::ModuleEvent& event) {
222 auto* module_database = ModuleDatabase::GetInstance();
223 uintptr_t load_address =
224 reinterpret_cast<uintptr_t>(event.module_load_address);
225
226 switch (event.event_type) {
227 case mojom::ModuleEventType::MODULE_ALREADY_LOADED:
228 case mojom::ModuleEventType::MODULE_LOADED: {
229 module_database->OnModuleLoad(
230 process_id, creation_time, event.module_path, event.module_size,
231 GetModuleTimeDateStamp(event.module_load_address), load_address);
232 return;
233 }
234
235 case mojom::ModuleEventType::MODULE_UNLOADED: {
236 module_database->OnModuleUnload(process_id, creation_time, load_address);
237 return;
238 }
239 }
240 }
241
242 // Helper function for initializing the module database subsystem. Populates
243 // the provided |module_watcher|.
244 void SetupModuleDatabase(std::unique_ptr<ModuleWatcher>* module_watcher) {
245 uint64_t creation_time = 0;
246 ModuleEventSinkImpl::GetProcessCreationTime(::GetCurrentProcess(),
247 &creation_time);
248 ModuleDatabase::SetInstance(base::MakeUnique<ModuleDatabase>(
249 content::BrowserThread::GetTaskRunnerForThread(
250 content::BrowserThread::UI)));
251 auto* module_database = ModuleDatabase::GetInstance();
252 uint32_t process_id = ::GetCurrentProcessId();
253
254 // The ModuleWatcher will immediately start emitting module events, but the
255 // ModuleDatabase expects an OnProcessStarted event prior to that. For child
256 // processes this is handled via the ModuleEventSinkImpl. For the browser
257 // process a manual notification is sent before wiring up the ModuleWatcher.
258 module_database->OnProcessStarted(process_id, creation_time,
259 content::PROCESS_TYPE_BROWSER);
260 *module_watcher = ModuleWatcher::Create(
261 base::Bind(&OnModuleEvent, process_id, creation_time));
262 }
263
205 } // namespace 264 } // namespace
206 265
207 void ShowCloseBrowserFirstMessageBox() { 266 void ShowCloseBrowserFirstMessageBox() {
208 int message_id = IDS_UNINSTALL_CLOSE_APP; 267 int message_id = IDS_UNINSTALL_CLOSE_APP;
209 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && 268 if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
210 (shell_integration::GetDefaultBrowser() == 269 (shell_integration::GetDefaultBrowser() ==
211 shell_integration::IS_DEFAULT)) { 270 shell_integration::IS_DEFAULT)) {
212 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; 271 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE;
213 } 272 }
214 chrome::ShowWarningMessageBox(NULL, 273 chrome::ShowWarningMessageBox(NULL,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 ChromeBrowserMainParts::PostProfileInit(); 378 ChromeBrowserMainParts::PostProfileInit();
320 379
321 // TODO(kulshin): remove this cleanup code in 2017. http://crbug.com/603718 380 // TODO(kulshin): remove this cleanup code in 2017. http://crbug.com/603718
322 // Attempt to delete the font cache and ignore any errors. 381 // Attempt to delete the font cache and ignore any errors.
323 base::FilePath path( 382 base::FilePath path(
324 profile()->GetPath().AppendASCII("ChromeDWriteFontCache")); 383 profile()->GetPath().AppendASCII("ChromeDWriteFontCache"));
325 content::BrowserThread::PostAfterStartupTask( 384 content::BrowserThread::PostAfterStartupTask(
326 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread( 385 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread(
327 content::BrowserThread::FILE), 386 content::BrowserThread::FILE),
328 base::Bind(base::IgnoreResult(&base::DeleteFile), path, false)); 387 base::Bind(base::IgnoreResult(&base::DeleteFile), path, false));
388
389 // Create the module database and hook up the in-process module watcher. This
390 // needs to be done before any child processes are initialized as the
391 // ModuleDatabase is an endpoint for IPC from child processes.
392 if (base::FeatureList::IsEnabled(features::kModuleDatabase))
393 SetupModuleDatabase(&module_watcher_);
329 } 394 }
330 395
331 void ChromeBrowserMainPartsWin::PostBrowserStart() { 396 void ChromeBrowserMainPartsWin::PostBrowserStart() {
332 ChromeBrowserMainParts::PostBrowserStart(); 397 ChromeBrowserMainParts::PostBrowserStart();
333 398
334 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice(nullptr)); 399 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice(nullptr));
335 400
336 // Set up a task to verify installed modules in the current process. 401 // Set up a task to verify installed modules in the current process.
337 content::BrowserThread::PostAfterStartupTask( 402 content::BrowserThread::PostAfterStartupTask(
338 FROM_HERE, content::BrowserThread::GetBlockingPool(), 403 FROM_HERE, content::BrowserThread::GetBlockingPool(),
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (resource_id) 590 if (resource_id)
526 return l10n_util::GetStringUTF16(resource_id); 591 return l10n_util::GetStringUTF16(resource_id);
527 return base::string16(); 592 return base::string16();
528 } 593 }
529 594
530 // static 595 // static
531 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { 596 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() {
532 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); 597 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ());
533 installer::SetTranslationDelegate(&delegate); 598 installer::SetTranslationDelegate(&delegate);
534 } 599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698