Skip to content

Commit

Permalink
fix: delay emitting screen events by a tick to avoid re-entrancy crash
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jun 27, 2019
1 parent 6243dba commit a0f3b09
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions shell/browser/api/atom_api_screen.cc
Expand Up @@ -99,17 +99,38 @@ static gfx::Rect DIPToScreenRect(electron::NativeWindow* window,

#endif

void DelayEmit(Screen* screen,
const base::StringPiece& name,
const display::Display& display) {
screen->Emit(name, display);
}

void DelayEmitWithMetrics(Screen* screen,
const base::StringPiece& name,
const display::Display& display,
std::vector<std::string> metrics) {
screen->Emit(name, display);
}

void Screen::OnDisplayAdded(const display::Display& new_display) {
Emit("display-added", new_display);
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
base::Bind(&DelayEmit, base::Unretained(this),
"display-added", new_display));
}

void Screen::OnDisplayRemoved(const display::Display& old_display) {
Emit("display-removed", old_display);
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
base::Bind(&DelayEmit, base::Unretained(this),
"display-removed", old_display));
}

void Screen::OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) {
Emit("display-metrics-changed", display, MetricsToArray(changed_metrics));
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::Bind(&DelayEmitWithMetrics, base::Unretained(this),
"display-metrics-changed", display,
MetricsToArray(changed_metrics)));
}

// static
Expand Down

0 comments on commit a0f3b09

Please sign in to comment.