Guard against bad events in screen module

It can happen that the DisplayObserver methods are called without a
valid Display object passed.
This commit is contained in:
Cheng Zhao 2015-01-19 14:46:29 -08:00
parent 0933a7d1b2
commit 3d858bee95

View file

@ -86,13 +86,21 @@ void Screen::OnDisplayAdded(const gfx::Display& new_display) {
}
void Screen::OnDisplayRemoved(const gfx::Display& old_display) {
displays_.erase(FindById(&displays_, old_display.id()));
auto iter = FindById(&displays_, old_display.id());
if (iter == displays_.end())
return;
displays_.erase(iter);
Emit("display-removed", old_display);
}
void Screen::OnDisplayMetricsChanged(const gfx::Display& display,
uint32_t changed_metrics) {
*FindById(&displays_, display.id()) = display;
auto iter = FindById(&displays_, display.id());
if (iter == displays_.end())
return;
*iter = display;
Emit("display-metrics-changed", display, MetricsToArray(changed_metrics));
}