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

Side by Side Diff: chrome/chrome_watcher/chrome_watcher_main.cc

Issue 2737263004: Ensure chrome watcher exits cleanly on unexpected errors (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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 <windows.h> 5 #include <windows.h>
6 #include <sddl.h> 6 #include <sddl.h>
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/environment.h" 15 #include "base/environment.h"
16 #include "base/file_version_info.h" 16 #include "base/file_version_info.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/logging_win.h" 18 #include "base/logging_win.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/process/memory.h"
21 #include "base/process/process.h" 22 #include "base/process/process.h"
22 #include "base/run_loop.h" 23 #include "base/run_loop.h"
23 #include "base/sequenced_task_runner.h" 24 #include "base/sequenced_task_runner.h"
24 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
25 #include "base/strings/string16.h" 26 #include "base/strings/string16.h"
26 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
27 #include "base/strings/string_piece.h" 28 #include "base/strings/string_piece.h"
28 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
29 #include "base/synchronization/waitable_event.h" 30 #include "base/synchronization/waitable_event.h"
30 #include "base/threading/platform_thread.h" 31 #include "base/threading/platform_thread.h"
31 #include "base/threading/thread.h" 32 #include "base/threading/thread.h"
32 #include "base/threading/thread_task_runner_handle.h" 33 #include "base/threading/thread_task_runner_handle.h"
33 #include "base/time/time.h" 34 #include "base/time/time.h"
35 #include "base/win/process_startup_helper.h"
34 #include "base/win/scoped_handle.h" 36 #include "base/win/scoped_handle.h"
35 #include "base/win/win_util.h" 37 #include "base/win/win_util.h"
36 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" 38 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
37 #include "chrome/install_static/initialize_from_primary_module.h" 39 #include "chrome/install_static/initialize_from_primary_module.h"
38 #include "components/browser_watcher/endsession_watcher_window_win.h" 40 #include "components/browser_watcher/endsession_watcher_window_win.h"
39 #include "components/browser_watcher/exit_code_watcher_win.h" 41 #include "components/browser_watcher/exit_code_watcher_win.h"
40 #include "components/browser_watcher/window_hang_monitor_win.h" 42 #include "components/browser_watcher/window_hang_monitor_win.h"
41 43
42 namespace { 44 namespace {
43 45
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 base::AtExitManager exit_manager; 197 base::AtExitManager exit_manager;
196 // Initialize the commandline singleton from the environment. 198 // Initialize the commandline singleton from the environment.
197 base::CommandLine::Init(0, nullptr); 199 base::CommandLine::Init(0, nullptr);
198 200
199 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); 201 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName);
200 202
201 // Arrange to be shut down as late as possible, as we want to outlive 203 // Arrange to be shut down as late as possible, as we want to outlive
202 // chrome.exe in order to report its exit status. 204 // chrome.exe in order to report its exit status.
203 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); 205 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY);
204 206
207 // Make sure the process exits cleanly on unexpected errors.
208 base::EnableTerminationOnHeapCorruption();
209 base::EnableTerminationOnOutOfMemory();
210 base::win::RegisterInvalidParamHandler();
211 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess();
212 base::win::SetupCRT(cmd_line);
213
205 // Run a UI message loop on the main thread. 214 // Run a UI message loop on the main thread.
206 base::PlatformThread::SetName("WatcherMainThread"); 215 base::PlatformThread::SetName("WatcherMainThread");
207 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); 216 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI);
208 217
209 base::RunLoop run_loop; 218 base::RunLoop run_loop;
210 BrowserMonitor monitor(registry_path, &run_loop); 219 BrowserMonitor monitor(registry_path, &run_loop);
211 if (!monitor.StartWatching(process.Duplicate(), 220 if (!monitor.StartWatching(process.Duplicate(),
212 std::move(on_initialized_event))) { 221 std::move(on_initialized_event))) {
213 return 1; 222 return 1;
214 } 223 }
215 run_loop.Run(); 224 run_loop.Run();
216 // TODO(manzagop): hang monitoring using WindowHangMonitor. 225 // TODO(manzagop): hang monitoring using WindowHangMonitor.
217 226
218 // Wind logging down. 227 // Wind logging down.
219 logging::LogEventProvider::Uninitialize(); 228 logging::LogEventProvider::Uninitialize();
220 229
221 return 0; 230 return 0;
222 } 231 }
223 232
224 static_assert( 233 static_assert(
225 std::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, 234 std::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value,
226 "WatcherMain() has wrong type"); 235 "WatcherMain() has wrong type");
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698