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

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

Issue 1630923002: Remove PRODUCT_STRING_PATH from chrome_constants.h on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@c2_rm_PSP_profile_resetter
Patch Set: use source_set Created 4 years, 8 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) 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"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; 54 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } };
55 55
56 // The amount of time we wait around for a WM_ENDSESSION or a process exit. 56 // The amount of time we wait around for a WM_ENDSESSION or a process exit.
57 const int kDelayTimeSeconds = 30; 57 const int kDelayTimeSeconds = 30;
58 58
59 // Takes care of monitoring a browser. This class watches for a browser's exit 59 // Takes care of monitoring a browser. This class watches for a browser's exit
60 // code, as well as listening for WM_ENDSESSION messages. Events are recorded in 60 // code, as well as listening for WM_ENDSESSION messages. Events are recorded in
61 // an exit funnel, for reporting the next time Chrome runs. 61 // an exit funnel, for reporting the next time Chrome runs.
62 class BrowserMonitor { 62 class BrowserMonitor {
63 public: 63 public:
64 BrowserMonitor(base::RunLoop* run_loop, const base::char16* registry_path); 64 BrowserMonitor(base::StringPiece16 registry_path, base::RunLoop* run_loop);
65 ~BrowserMonitor(); 65 ~BrowserMonitor();
66 66
67 // Initiates the asynchronous monitoring process, returns true on success. 67 // Initiates the asynchronous monitoring process, returns true on success.
68 // |on_initialized_event| will be signaled immediately before blocking on the 68 // |on_initialized_event| will be signaled immediately before blocking on the
69 // exit of |process|. 69 // exit of |process|.
70 bool StartWatching(const base::char16* registry_path, 70 bool StartWatching(base::Process process,
71 base::Process process,
72 base::win::ScopedHandle on_initialized_event); 71 base::win::ScopedHandle on_initialized_event);
73 72
74 private: 73 private:
75 // Called from EndSessionWatcherWindow on a end session messages. 74 // Called from EndSessionWatcherWindow on a end session messages.
76 void OnEndSessionMessage(UINT message, LPARAM lparam); 75 void OnEndSessionMessage(UINT message, LPARAM lparam);
77 76
78 // Blocking function that runs on |background_thread_|. Signals 77 // Blocking function that runs on |background_thread_|. Signals
79 // |on_initialized_event| before waiting for the browser process to exit. 78 // |on_initialized_event| before waiting for the browser process to exit.
80 void Watch(base::win::ScopedHandle on_initialized_event); 79 void Watch(base::win::ScopedHandle on_initialized_event);
81 80
(...skipping 10 matching lines...) Expand all
92 // when WM_ENDSESSION occurs before browser exit. 91 // when WM_ENDSESSION occurs before browser exit.
93 base::WaitableEvent browser_exited_; 92 base::WaitableEvent browser_exited_;
94 93
95 // The run loop for the main thread and its task runner. 94 // The run loop for the main thread and its task runner.
96 base::RunLoop* run_loop_; 95 base::RunLoop* run_loop_;
97 scoped_refptr<base::SequencedTaskRunner> main_thread_; 96 scoped_refptr<base::SequencedTaskRunner> main_thread_;
98 97
99 DISALLOW_COPY_AND_ASSIGN(BrowserMonitor); 98 DISALLOW_COPY_AND_ASSIGN(BrowserMonitor);
100 }; 99 };
101 100
102 BrowserMonitor::BrowserMonitor(base::RunLoop* run_loop, 101 BrowserMonitor::BrowserMonitor(base::StringPiece16 registry_path,
103 const base::char16* registry_path) 102 base::RunLoop* run_loop)
104 : exit_code_watcher_(registry_path), 103 : exit_code_watcher_(registry_path),
105 end_session_watcher_window_( 104 end_session_watcher_window_(
106 base::Bind(&BrowserMonitor::OnEndSessionMessage, 105 base::Bind(&BrowserMonitor::OnEndSessionMessage,
107 base::Unretained(this))), 106 base::Unretained(this))),
108 background_thread_("BrowserWatcherThread"), 107 background_thread_("BrowserWatcherThread"),
109 browser_exited_(true, false), // manual reset, initially non-signalled. 108 browser_exited_(true, false), // manual reset, initially non-signalled.
110 run_loop_(run_loop), 109 run_loop_(run_loop),
111 main_thread_(base::ThreadTaskRunnerHandle::Get()) { 110 main_thread_(base::ThreadTaskRunnerHandle::Get()) {}
112 }
113 111
114 BrowserMonitor::~BrowserMonitor() { 112 BrowserMonitor::~BrowserMonitor() {
115 } 113 }
116 114
117 bool BrowserMonitor::StartWatching( 115 bool BrowserMonitor::StartWatching(
118 const base::char16* registry_path,
119 base::Process process, 116 base::Process process,
120 base::win::ScopedHandle on_initialized_event) { 117 base::win::ScopedHandle on_initialized_event) {
121 if (!exit_code_watcher_.Initialize(std::move(process))) 118 if (!exit_code_watcher_.Initialize(std::move(process)))
122 return false; 119 return false;
123 120
124 if (!background_thread_.StartWithOptions( 121 if (!background_thread_.StartWithOptions(
125 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) { 122 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) {
126 return false; 123 return false;
127 } 124 }
128 125
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // The browser exited abnormally, wait around for a little bit to see 177 // The browser exited abnormally, wait around for a little bit to see
181 // whether this instance will get a logoff message. 178 // whether this instance will get a logoff message.
182 main_thread_->PostDelayedTask( 179 main_thread_->PostDelayedTask(
183 FROM_HERE, 180 FROM_HERE,
184 run_loop_->QuitClosure(), 181 run_loop_->QuitClosure(),
185 base::TimeDelta::FromSeconds(kDelayTimeSeconds)); 182 base::TimeDelta::FromSeconds(kDelayTimeSeconds));
186 } 183 }
187 } 184 }
188 185
189 void OnWindowEvent( 186 void OnWindowEvent(
190 const base::string16& registry_path,
191 base::Process process, 187 base::Process process,
192 const base::Callback<void(const base::Process&)>& on_hung_callback, 188 const base::Callback<void(const base::Process&)>& on_hung_callback,
193 browser_watcher::WindowHangMonitor::WindowEvent window_event) { 189 browser_watcher::WindowHangMonitor::WindowEvent window_event) {
194 if (window_event == browser_watcher::WindowHangMonitor::WINDOW_HUNG && 190 if (window_event == browser_watcher::WindowHangMonitor::WINDOW_HUNG &&
195 !on_hung_callback.is_null()) { 191 !on_hung_callback.is_null()) {
196 on_hung_callback.Run(process); 192 on_hung_callback.Run(process);
197 } 193 }
198 } 194 }
199 195
200 #if BUILDFLAG(ENABLE_KASKO) 196 #if BUILDFLAG(ENABLE_KASKO)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 base::Bind(&DumpHungBrowserProcess, main_thread_id, channel_name); 402 base::Bind(&DumpHungBrowserProcess, main_thread_id, channel_name);
407 } 403 }
408 #endif // BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) 404 #endif // BUILDFLAG(ENABLE_KASKO_HANG_REPORTS)
409 #endif // BUILDFLAG(ENABLE_KASKO) 405 #endif // BUILDFLAG(ENABLE_KASKO)
410 406
411 // Run a UI message loop on the main thread. 407 // Run a UI message loop on the main thread.
412 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); 408 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI);
413 msg_loop.set_thread_name("WatcherMainThread"); 409 msg_loop.set_thread_name("WatcherMainThread");
414 410
415 base::RunLoop run_loop; 411 base::RunLoop run_loop;
416 BrowserMonitor monitor(&run_loop, registry_path); 412 BrowserMonitor monitor(registry_path, &run_loop);
417 if (!monitor.StartWatching(registry_path, process.Duplicate(), 413 if (!monitor.StartWatching(process.Duplicate(),
418 std::move(on_initialized_event))) { 414 std::move(on_initialized_event))) {
419 return 1; 415 return 1;
420 } 416 }
421 417
422 { 418 {
423 // Scoped to force |hang_monitor| destruction before Kasko is shut down. 419 // Scoped to force |hang_monitor| destruction before Kasko is shut down.
424 browser_watcher::WindowHangMonitor hang_monitor( 420 browser_watcher::WindowHangMonitor hang_monitor(
425 base::TimeDelta::FromSeconds(60), base::TimeDelta::FromSeconds(20), 421 base::TimeDelta::FromSeconds(60), base::TimeDelta::FromSeconds(20),
426 base::Bind(&OnWindowEvent, registry_path, 422 base::Bind(&OnWindowEvent, base::Passed(process.Duplicate()),
427 base::Passed(process.Duplicate()), on_hung_callback)); 423 on_hung_callback));
428 hang_monitor.Initialize(process.Duplicate()); 424 hang_monitor.Initialize(process.Duplicate());
429 425
430 run_loop.Run(); 426 run_loop.Run();
431 } 427 }
432 428
433 #if BUILDFLAG(ENABLE_KASKO) 429 #if BUILDFLAG(ENABLE_KASKO)
434 if (launched_kasko) 430 if (launched_kasko)
435 kasko::api::ShutdownReporter(); 431 kasko::api::ShutdownReporter();
436 #endif // BUILDFLAG(ENABLE_KASKO) 432 #endif // BUILDFLAG(ENABLE_KASKO)
437 433
438 // Wind logging down. 434 // Wind logging down.
439 logging::LogEventProvider::Uninitialize(); 435 logging::LogEventProvider::Uninitialize();
440 436
441 return 0; 437 return 0;
442 } 438 }
443 439
444 static_assert( 440 static_assert(
445 std::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, 441 std::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value,
446 "WatcherMain() has wrong type"); 442 "WatcherMain() has wrong type");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698