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

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

Issue 1103343003: [chrome/chrome_watcher] Replace MessageLoopProxy usage with ThreadTaskRunnerHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/file_version_info.h" 11 #include "base/file_version_info.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging_win.h" 13 #include "base/logging_win.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/message_loop/message_loop_proxy.h"
18 #include "base/process/process.h" 16 #include "base/process/process.h"
19 #include "base/run_loop.h" 17 #include "base/run_loop.h"
20 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
19 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
22 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_piece.h" 22 #include "base/strings/string_piece.h"
24 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
25 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
26 #include "base/template_util.h" 25 #include "base/template_util.h"
26 #include "base/thread_task_runner_handle.h"
27 #include "base/threading/thread.h" 27 #include "base/threading/thread.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "base/win/scoped_handle.h" 29 #include "base/win/scoped_handle.h"
30 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" 30 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
31 #include "chrome/installer/util/util_constants.h" 31 #include "chrome/installer/util/util_constants.h"
32 #include "components/browser_watcher/endsession_watcher_window_win.h" 32 #include "components/browser_watcher/endsession_watcher_window_win.h"
33 #include "components/browser_watcher/exit_code_watcher_win.h" 33 #include "components/browser_watcher/exit_code_watcher_win.h"
34 #include "components/browser_watcher/exit_funnel_win.h" 34 #include "components/browser_watcher/exit_funnel_win.h"
35 #include "components/browser_watcher/window_hang_monitor_win.h" 35 #include "components/browser_watcher/window_hang_monitor_win.h"
36 36
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 BrowserMonitor::BrowserMonitor(base::RunLoop* run_loop, 98 BrowserMonitor::BrowserMonitor(base::RunLoop* run_loop,
99 const base::char16* registry_path) : 99 const base::char16* registry_path) :
100 browser_exited_(true, false), // manual reset, initially non-signalled. 100 browser_exited_(true, false), // manual reset, initially non-signalled.
101 exit_code_watcher_(registry_path), 101 exit_code_watcher_(registry_path),
102 end_session_watcher_window_( 102 end_session_watcher_window_(
103 base::Bind(&BrowserMonitor::OnEndSessionMessage, 103 base::Bind(&BrowserMonitor::OnEndSessionMessage,
104 base::Unretained(this))), 104 base::Unretained(this))),
105 background_thread_("BrowserWatcherThread"), 105 background_thread_("BrowserWatcherThread"),
106 run_loop_(run_loop), 106 run_loop_(run_loop),
107 main_thread_(base::MessageLoopProxy::current()) { 107 main_thread_(base::ThreadTaskRunnerHandle::Get()) {
108 } 108 }
109 109
110 BrowserMonitor::~BrowserMonitor() { 110 BrowserMonitor::~BrowserMonitor() {
111 } 111 }
112 112
113 bool BrowserMonitor::StartWatching( 113 bool BrowserMonitor::StartWatching(
114 const base::char16* registry_path, 114 const base::char16* registry_path,
115 base::Process process, 115 base::Process process,
116 base::win::ScopedHandle on_initialized_event) { 116 base::win::ScopedHandle on_initialized_event) {
117 if (!exit_code_watcher_.Initialize(process.Pass())) 117 if (!exit_code_watcher_.Initialize(process.Pass()))
(...skipping 13 matching lines...) Expand all
131 FROM_HERE, base::Bind(&BrowserMonitor::Watch, base::Unretained(this), 131 FROM_HERE, base::Bind(&BrowserMonitor::Watch, base::Unretained(this),
132 base::Passed(on_initialized_event.Pass())))) { 132 base::Passed(on_initialized_event.Pass())))) {
133 background_thread_.Stop(); 133 background_thread_.Stop();
134 return false; 134 return false;
135 } 135 }
136 136
137 return true; 137 return true;
138 } 138 }
139 139
140 void BrowserMonitor::OnEndSessionMessage(UINT message, LPARAM lparam) { 140 void BrowserMonitor::OnEndSessionMessage(UINT message, LPARAM lparam) {
141 DCHECK_EQ(main_thread_, base::MessageLoopProxy::current()); 141 DCHECK_EQ(main_thread_, base::ThreadTaskRunnerHandle::Get());
142 142
143 if (message == WM_QUERYENDSESSION) { 143 if (message == WM_QUERYENDSESSION) {
144 exit_funnel_.RecordEvent(L"WatcherQueryEndSession"); 144 exit_funnel_.RecordEvent(L"WatcherQueryEndSession");
145 } else if (message == WM_ENDSESSION) { 145 } else if (message == WM_ENDSESSION) {
146 exit_funnel_.RecordEvent(L"WatcherEndSession"); 146 exit_funnel_.RecordEvent(L"WatcherEndSession");
147 } 147 }
148 if (lparam & ENDSESSION_CLOSEAPP) 148 if (lparam & ENDSESSION_CLOSEAPP)
149 exit_funnel_.RecordEvent(L"ES_CloseApp"); 149 exit_funnel_.RecordEvent(L"ES_CloseApp");
150 if (lparam & ENDSESSION_CRITICAL) 150 if (lparam & ENDSESSION_CRITICAL)
151 exit_funnel_.RecordEvent(L"ES_Critical"); 151 exit_funnel_.RecordEvent(L"ES_Critical");
152 if (lparam & ENDSESSION_LOGOFF) 152 if (lparam & ENDSESSION_LOGOFF)
153 exit_funnel_.RecordEvent(L"ES_Logoff"); 153 exit_funnel_.RecordEvent(L"ES_Logoff");
154 const LPARAM kKnownBits = 154 const LPARAM kKnownBits =
155 ENDSESSION_CLOSEAPP | ENDSESSION_CRITICAL | ENDSESSION_LOGOFF; 155 ENDSESSION_CLOSEAPP | ENDSESSION_CRITICAL | ENDSESSION_LOGOFF;
156 if (lparam & ~kKnownBits) 156 if (lparam & ~kKnownBits)
157 exit_funnel_.RecordEvent(L"ES_Other"); 157 exit_funnel_.RecordEvent(L"ES_Other");
158 158
159 // If the browser hasn't exited yet, dally for a bit to try and stretch this 159 // If the browser hasn't exited yet, dally for a bit to try and stretch this
160 // process' lifetime to give it some more time to capture the browser exit. 160 // process' lifetime to give it some more time to capture the browser exit.
161 browser_exited_.TimedWait(base::TimeDelta::FromSeconds(kDelayTimeSeconds)); 161 browser_exited_.TimedWait(base::TimeDelta::FromSeconds(kDelayTimeSeconds));
162 162
163 run_loop_->Quit(); 163 run_loop_->Quit();
164 } 164 }
165 165
166 void BrowserMonitor::Watch(base::win::ScopedHandle on_initialized_event) { 166 void BrowserMonitor::Watch(base::win::ScopedHandle on_initialized_event) {
167 // This needs to run on an IO thread. 167 // This needs to run on an IO thread.
168 DCHECK_NE(main_thread_, base::MessageLoopProxy::current()); 168 DCHECK_NE(main_thread_, base::ThreadTaskRunnerHandle::Get());
169 169
170 // Signal our client now that the Kasko reporter is initialized and we have 170 // Signal our client now that the Kasko reporter is initialized and we have
171 // cleared all of the obstacles that might lead to an early exit. 171 // cleared all of the obstacles that might lead to an early exit.
172 ::SetEvent(on_initialized_event.Get()); 172 ::SetEvent(on_initialized_event.Get());
173 on_initialized_event.Close(); 173 on_initialized_event.Close();
174 174
175 exit_code_watcher_.WaitForExit(); 175 exit_code_watcher_.WaitForExit();
176 exit_funnel_.RecordEvent(L"BrowserExit"); 176 exit_funnel_.RecordEvent(L"BrowserExit");
177 177
178 // Note that the browser has exited. 178 // Note that the browser has exited.
179 browser_exited_.Signal(); 179 browser_exited_.Signal();
180 180
181 main_thread_->PostTask(FROM_HERE, 181 main_thread_->PostTask(FROM_HERE,
182 base::Bind(&BrowserMonitor::BrowserExited, base::Unretained(this))); 182 base::Bind(&BrowserMonitor::BrowserExited, base::Unretained(this)));
183 } 183 }
184 184
185 void BrowserMonitor::BrowserExited() { 185 void BrowserMonitor::BrowserExited() {
186 // This runs in the main thread. 186 // This runs in the main thread.
187 DCHECK_EQ(main_thread_, base::MessageLoopProxy::current()); 187 DCHECK_EQ(main_thread_, base::ThreadTaskRunnerHandle::Get());
188 188
189 // Our background thread has served it's purpose. 189 // Our background thread has served it's purpose.
190 background_thread_.Stop(); 190 background_thread_.Stop();
191 191
192 const int exit_code = exit_code_watcher_.exit_code(); 192 const int exit_code = exit_code_watcher_.exit_code();
193 if (exit_code >= 0 && exit_code <= 28) { 193 if (exit_code >= 0 && exit_code <= 28) {
194 // The browser exited with a well-known exit code, quit this process 194 // The browser exited with a well-known exit code, quit this process
195 // immediately. 195 // immediately.
196 run_loop_->Quit(); 196 run_loop_->Quit();
197 } else { 197 } else {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 350
351 // Wind logging down. 351 // Wind logging down.
352 logging::LogEventProvider::Uninitialize(); 352 logging::LogEventProvider::Uninitialize();
353 353
354 return 0; 354 return 0;
355 } 355 }
356 356
357 static_assert( 357 static_assert(
358 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, 358 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value,
359 "WatcherMain() has wrong type"); 359 "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