Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <windows.h> | 9 #include <windows.h> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 25 #include "base/scoped_native_library.h" | 25 #include "base/scoped_native_library.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 28 #include "base/win/registry.h" | 28 #include "base/win/registry.h" |
| 29 #include "base/win/win_util.h" | 29 #include "base/win/win_util.h" |
| 30 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
| 31 #include "base/win/wrapped_window_proc.h" | 31 #include "base/win/wrapped_window_proc.h" |
| 32 #include "chrome/browser/conflicts/module_database_win.h" | |
| 33 #include "chrome/browser/conflicts/module_event_sink_impl_win.h" | |
| 32 #include "chrome/browser/first_run/first_run.h" | 34 #include "chrome/browser/first_run/first_run.h" |
| 33 #include "chrome/browser/install_verification/win/install_verification.h" | 35 #include "chrome/browser/install_verification/win/install_verification.h" |
| 34 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 36 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 35 #include "chrome/browser/shell_integration.h" | 37 #include "chrome/browser/shell_integration.h" |
| 36 #include "chrome/browser/ui/simple_message_box.h" | 38 #include "chrome/browser/ui/simple_message_box.h" |
| 37 #include "chrome/browser/ui/uninstall_browser_prompt.h" | 39 #include "chrome/browser/ui/uninstall_browser_prompt.h" |
| 38 #include "chrome/browser/win/browser_util.h" | 40 #include "chrome/browser/win/browser_util.h" |
| 39 #include "chrome/browser/win/chrome_elf_init.h" | 41 #include "chrome/browser/win/chrome_elf_init.h" |
| 40 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 42 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 41 #include "chrome/common/chrome_constants.h" | 43 #include "chrome/common/chrome_constants.h" |
| 44 #include "chrome/common/chrome_features.h" | |
| 42 #include "chrome/common/chrome_paths.h" | 45 #include "chrome/common/chrome_paths.h" |
| 43 #include "chrome/common/chrome_result_codes.h" | 46 #include "chrome/common/chrome_result_codes.h" |
| 44 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/chrome_utility_messages.h" | 48 #include "chrome/common/chrome_utility_messages.h" |
| 46 #include "chrome/common/crash_keys.h" | 49 #include "chrome/common/crash_keys.h" |
| 47 #include "chrome/common/env_vars.h" | 50 #include "chrome/common/env_vars.h" |
| 48 #include "chrome/grit/chromium_strings.h" | 51 #include "chrome/grit/chromium_strings.h" |
| 49 #include "chrome/grit/generated_resources.h" | 52 #include "chrome/grit/generated_resources.h" |
| 50 #include "chrome/installer/util/browser_distribution.h" | 53 #include "chrome/installer/util/browser_distribution.h" |
| 51 #include "chrome/installer/util/helper.h" | 54 #include "chrome/installer/util/helper.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 198 |
| 196 // Look for the DLLs used to implement the FTH and other compat hacks. | 199 // Look for the DLLs used to implement the FTH and other compat hacks. |
| 197 if (GetModuleHandleW(L"AcLayers.dll") != NULL) | 200 if (GetModuleHandleW(L"AcLayers.dll") != NULL) |
| 198 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); | 201 detected = static_cast<FTHFlags>(detected | FTH_ACLAYERS_LOADED); |
| 199 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) | 202 if (GetModuleHandleW(L"AcXtrnal.dll") != NULL) |
| 200 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); | 203 detected = static_cast<FTHFlags>(detected | FTH_ACXTRNAL_LOADED); |
| 201 | 204 |
| 202 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); | 205 UMA_HISTOGRAM_ENUMERATION("FaultTolerantHeap", detected, FTH_FLAGS_COUNT); |
| 203 } | 206 } |
| 204 | 207 |
| 208 // Helper function for getting the time date stamp associated with a module in | |
| 209 // this process. Similar to implementation in ModuleEventSinkImpl, but doesn't | |
| 210 // use remote process reads. | |
| 211 uint32_t GetModuleTimeDateStamp(const void* module_load_address) { | |
| 212 auto* base = reinterpret_cast<const uint8_t*>(module_load_address); | |
|
grt (UTC plus 2)
2017/01/06 09:44:57
can you use base::win::PEImage for this?
chrisha
2017/01/10 21:01:45
Yeah, should be fine. I forget that thing exists.
| |
| 213 auto* dos_header = reinterpret_cast<const IMAGE_DOS_HEADER*>(base); | |
| 214 auto* nt_headers = | |
| 215 reinterpret_cast<const IMAGE_NT_HEADERS*>(base + dos_header->e_lfanew); | |
| 216 return nt_headers->FileHeader.TimeDateStamp; | |
| 217 } | |
| 218 | |
| 219 // Used as the callback for ModuleWatcher events in this process. Dispatches | |
| 220 // them to the ModuleDatabase. | |
| 221 void OnModuleEvent(uint32_t process_id, | |
| 222 uint64_t creation_time, | |
| 223 const ModuleWatcher::ModuleEvent& event) { | |
| 224 auto* module_database = ModuleDatabase::GetInstance(); | |
| 225 uintptr_t load_address = | |
| 226 reinterpret_cast<uintptr_t>(event.module_load_address); | |
| 227 | |
| 228 switch (event.event_type) { | |
| 229 case mojom::ModuleEventType::MODULE_ALREADY_LOADED: | |
| 230 case mojom::ModuleEventType::MODULE_LOADED: { | |
| 231 module_database->OnModuleLoad( | |
| 232 process_id, creation_time, event.module_path, event.module_size, | |
| 233 GetModuleTimeDateStamp(event.module_load_address), load_address); | |
| 234 return; | |
| 235 } | |
| 236 | |
| 237 case mojom::ModuleEventType::MODULE_UNLOADED: { | |
| 238 module_database->OnModuleUnload(process_id, creation_time, load_address); | |
| 239 return; | |
| 240 } | |
| 241 } | |
| 242 } | |
| 243 | |
| 205 } // namespace | 244 } // namespace |
| 206 | 245 |
| 207 void ShowCloseBrowserFirstMessageBox() { | 246 void ShowCloseBrowserFirstMessageBox() { |
| 208 int message_id = IDS_UNINSTALL_CLOSE_APP; | 247 int message_id = IDS_UNINSTALL_CLOSE_APP; |
| 209 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && | 248 if (base::win::GetVersion() >= base::win::VERSION_WIN8 && |
| 210 (shell_integration::GetDefaultBrowser() == | 249 (shell_integration::GetDefaultBrowser() == |
| 211 shell_integration::IS_DEFAULT)) { | 250 shell_integration::IS_DEFAULT)) { |
| 212 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; | 251 message_id = IDS_UNINSTALL_CLOSE_APP_IMMERSIVE; |
| 213 } | 252 } |
| 214 chrome::ShowWarningMessageBox(NULL, | 253 chrome::ShowWarningMessageBox(NULL, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 ChromeBrowserMainParts::PostProfileInit(); | 358 ChromeBrowserMainParts::PostProfileInit(); |
| 320 | 359 |
| 321 // TODO(kulshin): remove this cleanup code in 2017. http://crbug.com/603718 | 360 // TODO(kulshin): remove this cleanup code in 2017. http://crbug.com/603718 |
| 322 // Attempt to delete the font cache and ignore any errors. | 361 // Attempt to delete the font cache and ignore any errors. |
| 323 base::FilePath path( | 362 base::FilePath path( |
| 324 profile()->GetPath().AppendASCII("ChromeDWriteFontCache")); | 363 profile()->GetPath().AppendASCII("ChromeDWriteFontCache")); |
| 325 content::BrowserThread::PostAfterStartupTask( | 364 content::BrowserThread::PostAfterStartupTask( |
| 326 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread( | 365 FROM_HERE, content::BrowserThread::GetTaskRunnerForThread( |
| 327 content::BrowserThread::FILE), | 366 content::BrowserThread::FILE), |
| 328 base::Bind(base::IgnoreResult(&base::DeleteFile), path, false)); | 367 base::Bind(base::IgnoreResult(&base::DeleteFile), path, false)); |
| 368 | |
| 369 // Create the module database and hook up the in-process module watcher. This | |
| 370 // needs to be done before any child processes are initialized as the | |
| 371 // ModuleDatabase is an endpoint for IPC from child processes. | |
| 372 if (base::FeatureList::IsEnabled(features::kModuleDatabase)) { | |
|
grt (UTC plus 2)
2017/01/06 09:44:57
nit: pull this out into a function in the unnamed
chrisha
2017/01/10 21:01:45
Done.
| |
| 373 uint64_t creation_time = 0; | |
|
grt (UTC plus 2)
2017/01/06 09:44:58
#include <stdint.h>
chrisha
2017/01/10 21:01:46
Done.
| |
| 374 ModuleEventSinkImpl::GetProcessCreationTime(::GetCurrentProcess(), | |
|
grt (UTC plus 2)
2017/01/06 09:44:57
TIL: base::CurrentProcessInfo::CreationTime()!
chrisha
2017/01/10 21:01:45
Is there any guarantee that base::Time is lossless
| |
| 375 &creation_time); | |
| 376 | |
| 377 ModuleDatabase::SetInstance(base::MakeUnique<ModuleDatabase>( | |
| 378 content::BrowserThread::GetTaskRunnerForThread( | |
| 379 content::BrowserThread::UI))); | |
| 380 auto* module_database = ModuleDatabase::GetInstance(); | |
| 381 uint32_t process_id = ::GetCurrentProcessId(); | |
| 382 module_database->OnProcessStarted(process_id, creation_time, | |
| 383 content::PROCESS_TYPE_BROWSER); | |
| 384 module_watcher_ = ModuleWatcher::Create( | |
| 385 base::Bind(&OnModuleEvent, process_id, creation_time)); | |
| 386 } | |
| 329 } | 387 } |
| 330 | 388 |
| 331 void ChromeBrowserMainPartsWin::PostBrowserStart() { | 389 void ChromeBrowserMainPartsWin::PostBrowserStart() { |
| 332 ChromeBrowserMainParts::PostBrowserStart(); | 390 ChromeBrowserMainParts::PostBrowserStart(); |
| 333 | 391 |
| 334 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice(nullptr)); | 392 UMA_HISTOGRAM_BOOLEAN("Windows.Tablet", base::win::IsTabletDevice(nullptr)); |
| 335 | 393 |
| 336 // Set up a task to verify installed modules in the current process. | 394 // Set up a task to verify installed modules in the current process. |
| 337 content::BrowserThread::PostAfterStartupTask( | 395 content::BrowserThread::PostAfterStartupTask( |
| 338 FROM_HERE, content::BrowserThread::GetBlockingPool(), | 396 FROM_HERE, content::BrowserThread::GetBlockingPool(), |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 if (resource_id) | 583 if (resource_id) |
| 526 return l10n_util::GetStringUTF16(resource_id); | 584 return l10n_util::GetStringUTF16(resource_id); |
| 527 return base::string16(); | 585 return base::string16(); |
| 528 } | 586 } |
| 529 | 587 |
| 530 // static | 588 // static |
| 531 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { | 589 void ChromeBrowserMainPartsWin::SetupInstallerUtilStrings() { |
| 532 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); | 590 CR_DEFINE_STATIC_LOCAL(TranslationDelegate, delegate, ()); |
| 533 installer::SetTranslationDelegate(&delegate); | 591 installer::SetTranslationDelegate(&delegate); |
| 534 } | 592 } |
| OLD | NEW |