refactor: use base::ObserverList::Notify() (#46897)

* refactor: use ObserverList::Notify() in shell/browser/window_list.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/web_contents_zoom_controller.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/usb/usb_chooser_context.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/usb/electron_usb_delegate.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/ui/views/menu_delegate.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/ui/tray_icon.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/ui/electron_menu_model.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/serial/serial_chooser_context.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/native_window.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/serial/electron_serial_delegate.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/browser.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/api/electron_api_web_contents.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/hid/electron_hid_delegate.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use ObserverList::Notify() in shell/browser/hid/hid_chooser_context.cc

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-05-02 07:51:05 -05:00 committed by GitHub
parent 1687b95849
commit 17e1ff2675
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 134 additions and 229 deletions

View file

@ -1299,8 +1299,7 @@ void WebContents::BeforeUnloadFired(content::WebContents* tab,
void WebContents::SetContentsBounds(content::WebContents* source, void WebContents::SetContentsBounds(content::WebContents* source,
const gfx::Rect& rect) { const gfx::Rect& rect) {
if (!Emit("content-bounds-updated", rect)) if (!Emit("content-bounds-updated", rect))
for (ExtendedWebContentsObserver& observer : observers_) observers_.Notify(&ExtendedWebContentsObserver::OnSetContentBounds, rect);
observer.OnSetContentBounds(rect);
} }
void WebContents::CloseContents(content::WebContents* source) { void WebContents::CloseContents(content::WebContents* source) {
@ -1316,8 +1315,7 @@ void WebContents::CloseContents(content::WebContents* source) {
} }
void WebContents::ActivateContents(content::WebContents* source) { void WebContents::ActivateContents(content::WebContents* source) {
for (ExtendedWebContentsObserver& observer : observers_) observers_.Notify(&ExtendedWebContentsObserver::OnActivateContents);
observer.OnActivateContents();
} }
void WebContents::UpdateTargetURL(content::WebContents* source, void WebContents::UpdateTargetURL(content::WebContents* source,
@ -2112,8 +2110,8 @@ void WebContents::TitleWasSet(content::NavigationEntry* entry) {
} else { } else {
final_title = web_contents()->GetTitle(); final_title = web_contents()->GetTitle();
} }
for (ExtendedWebContentsObserver& observer : observers_) observers_.Notify(&ExtendedWebContentsObserver::OnPageTitleUpdated,
observer.OnPageTitleUpdated(final_title, explicit_set); final_title, explicit_set);
Emit("page-title-updated", final_title, explicit_set); Emit("page-title-updated", final_title, explicit_set);
} }
@ -2169,8 +2167,7 @@ void WebContents::DevToolsClosed() {
} }
void WebContents::DevToolsResized() { void WebContents::DevToolsResized() {
for (ExtendedWebContentsObserver& observer : observers_) observers_.Notify(&ExtendedWebContentsObserver::OnDevToolsResized);
observer.OnDevToolsResized();
} }
void WebContents::SetOwnerWindow(NativeWindow* owner_window) { void WebContents::SetOwnerWindow(NativeWindow* owner_window) {

View file

@ -129,8 +129,7 @@ void Browser::Shutdown() {
is_shutdown_ = true; is_shutdown_ = true;
is_quitting_ = true; is_quitting_ = true;
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnQuit);
observer.OnQuit();
if (quit_main_message_loop_) { if (quit_main_message_loop_) {
RunQuitClosure(std::move(quit_main_message_loop_)); RunQuitClosure(std::move(quit_main_message_loop_));
@ -165,25 +164,20 @@ void Browser::SetName(const std::string& name) {
bool Browser::OpenFile(const std::string& file_path) { bool Browser::OpenFile(const std::string& file_path) {
bool prevent_default = false; bool prevent_default = false;
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnOpenFile, &prevent_default, file_path);
observer.OnOpenFile(&prevent_default, file_path);
return prevent_default; return prevent_default;
} }
void Browser::OpenURL(const std::string& url) { void Browser::OpenURL(const std::string& url) {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnOpenURL, url);
observer.OnOpenURL(url);
} }
void Browser::Activate(bool has_visible_windows) { void Browser::Activate(bool has_visible_windows) {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnActivate, has_visible_windows);
observer.OnActivate(has_visible_windows);
} }
void Browser::WillFinishLaunching() { void Browser::WillFinishLaunching() {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnWillFinishLaunching);
observer.OnWillFinishLaunching();
} }
void Browser::DidFinishLaunching(base::Value::Dict launch_info) { void Browser::DidFinishLaunching(base::Value::Dict launch_info) {
@ -201,6 +195,7 @@ void Browser::DidFinishLaunching(base::Value::Dict launch_info) {
if (ready_promise_) { if (ready_promise_) {
ready_promise_->Resolve(); ready_promise_->Resolve();
} }
for (BrowserObserver& observer : observers_) for (BrowserObserver& observer : observers_)
observer.OnFinishLaunching(launch_info.Clone()); observer.OnFinishLaunching(launch_info.Clone());
} }
@ -216,20 +211,15 @@ v8::Local<v8::Value> Browser::WhenReady(v8::Isolate* isolate) {
} }
void Browser::OnAccessibilitySupportChanged() { void Browser::OnAccessibilitySupportChanged() {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnAccessibilitySupportChanged);
observer.OnAccessibilitySupportChanged();
} }
void Browser::PreMainMessageLoopRun() { void Browser::PreMainMessageLoopRun() {
for (BrowserObserver& observer : observers_) { observers_.Notify(&BrowserObserver::OnPreMainMessageLoopRun);
observer.OnPreMainMessageLoopRun();
}
} }
void Browser::PreCreateThreads() { void Browser::PreCreateThreads() {
for (BrowserObserver& observer : observers_) { observers_.Notify(&BrowserObserver::OnPreCreateThreads);
observer.OnPreCreateThreads();
}
} }
void Browser::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) { void Browser::SetMainMessageLoopQuitClosure(base::OnceClosure quit_closure) {
@ -244,9 +234,7 @@ void Browser::NotifyAndShutdown() {
return; return;
bool prevent_default = false; bool prevent_default = false;
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnWillQuit, &prevent_default);
observer.OnWillQuit(&prevent_default);
if (prevent_default) { if (prevent_default) {
is_quitting_ = false; is_quitting_ = false;
return; return;
@ -257,9 +245,7 @@ void Browser::NotifyAndShutdown() {
bool Browser::HandleBeforeQuit() { bool Browser::HandleBeforeQuit() {
bool prevent_default = false; bool prevent_default = false;
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnBeforeQuit, &prevent_default);
observer.OnBeforeQuit(&prevent_default);
return !prevent_default; return !prevent_default;
} }
@ -276,25 +262,21 @@ void Browser::OnWindowAllClosed() {
} else if (is_quitting_) { } else if (is_quitting_) {
NotifyAndShutdown(); NotifyAndShutdown();
} else { } else {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnWindowAllClosed);
observer.OnWindowAllClosed();
} }
} }
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
void Browser::NewWindowForTab() { void Browser::NewWindowForTab() {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnNewWindowForTab);
observer.OnNewWindowForTab();
} }
void Browser::DidBecomeActive() { void Browser::DidBecomeActive() {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnDidBecomeActive);
observer.OnDidBecomeActive();
} }
void Browser::DidResignActive() { void Browser::DidResignActive() {
for (BrowserObserver& observer : observers_) observers_.Notify(&BrowserObserver::OnDidResignActive);
observer.OnDidResignActive();
} }
#endif #endif

View file

@ -56,25 +56,25 @@ class ElectronHidDelegate::ContextObservation
// HidChooserContext::DeviceObserver: // HidChooserContext::DeviceObserver:
void OnDeviceAdded(const device::mojom::HidDeviceInfo& device_info) override { void OnDeviceAdded(const device::mojom::HidDeviceInfo& device_info) override {
for (auto& observer : observer_list_) observer_list_.Notify(&content::HidDelegate::Observer::OnDeviceAdded,
observer.OnDeviceAdded(device_info); device_info);
} }
void OnDeviceRemoved( void OnDeviceRemoved(
const device::mojom::HidDeviceInfo& device_info) override { const device::mojom::HidDeviceInfo& device_info) override {
for (auto& observer : observer_list_) observer_list_.Notify(&content::HidDelegate::Observer::OnDeviceRemoved,
observer.OnDeviceRemoved(device_info); device_info);
} }
void OnDeviceChanged( void OnDeviceChanged(
const device::mojom::HidDeviceInfo& device_info) override { const device::mojom::HidDeviceInfo& device_info) override {
for (auto& observer : observer_list_) observer_list_.Notify(&content::HidDelegate::Observer::OnDeviceChanged,
observer.OnDeviceChanged(device_info); device_info);
} }
void OnHidManagerConnectionError() override { void OnHidManagerConnectionError() override {
for (auto& observer : observer_list_) observer_list_.Notify(
observer.OnHidManagerConnectionError(); &content::HidDelegate::Observer::OnHidManagerConnectionError);
} }
void OnHidChooserContextShutdown() override { void OnHidChooserContextShutdown() override {

View file

@ -247,8 +247,7 @@ void HidChooserContext::DeviceAdded(device::mojom::HidDeviceInfoPtr device) {
devices_.insert({device->guid, device->Clone()}); devices_.insert({device->guid, device->Clone()});
// Notify all observers. // Notify all observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnDeviceAdded, *device);
observer.OnDeviceAdded(*device);
} }
void HidChooserContext::DeviceRemoved(device::mojom::HidDeviceInfoPtr device) { void HidChooserContext::DeviceRemoved(device::mojom::HidDeviceInfoPtr device) {
@ -259,8 +258,7 @@ void HidChooserContext::DeviceRemoved(device::mojom::HidDeviceInfoPtr device) {
DCHECK_EQ(n_erased, 1U); DCHECK_EQ(n_erased, 1U);
// Notify all device observers. // Notify all device observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnDeviceRemoved, *device);
observer.OnDeviceRemoved(*device);
// Next we'll notify observers for revoked permissions. If the device does not // Next we'll notify observers for revoked permissions. If the device does not
// support persistent permissions then device permissions are revoked on // support persistent permissions then device permissions are revoked on
@ -281,8 +279,7 @@ void HidChooserContext::DeviceChanged(device::mojom::HidDeviceInfoPtr device) {
mapped = device->Clone(); mapped = device->Clone();
// Notify all observers. // Notify all observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnDeviceChanged, *device);
observer.OnDeviceChanged(*device);
} }
void HidChooserContext::EnsureHidManagerConnection() { void HidChooserContext::EnsureHidManagerConnection() {
@ -332,8 +329,7 @@ void HidChooserContext::OnHidManagerConnectionError() {
ephemeral_devices_.clear(); ephemeral_devices_.clear();
// Notify all device observers. // Notify all device observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnHidManagerConnectionError);
observer.OnHidManagerConnectionError();
} }
} // namespace electron } // namespace electron

View file

@ -500,23 +500,21 @@ void NativeWindow::SetWindowControlsOverlayRect(const gfx::Rect& overlay_rect) {
} }
void NativeWindow::NotifyWindowRequestPreferredWidth(int* width) { void NativeWindow::NotifyWindowRequestPreferredWidth(int* width) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::RequestPreferredWidth, width);
observer.RequestPreferredWidth(width);
} }
void NativeWindow::NotifyWindowCloseButtonClicked() { void NativeWindow::NotifyWindowCloseButtonClicked() {
// First ask the observers whether we want to close. // First ask the observers whether we want to close.
bool prevent_default = false; bool prevent_default = false;
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::WillCloseWindow, &prevent_default);
observer.WillCloseWindow(&prevent_default);
if (prevent_default) { if (prevent_default) {
WindowList::WindowCloseCancelled(this); WindowList::WindowCloseCancelled(this);
return; return;
} }
// Then ask the observers how should we close the window. // Then ask the observers how should we close the window.
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnCloseButtonClicked,
observer.OnCloseButtonClicked(&prevent_default); &prevent_default);
if (prevent_default) if (prevent_default)
return; return;
@ -528,8 +526,7 @@ void NativeWindow::NotifyWindowClosed() {
return; return;
is_closed_ = true; is_closed_ = true;
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowClosed);
observer.OnWindowClosed();
WindowList::RemoveWindow(this); WindowList::RemoveWindow(this);
} }
@ -537,180 +534,153 @@ void NativeWindow::NotifyWindowClosed() {
void NativeWindow::NotifyWindowQueryEndSession( void NativeWindow::NotifyWindowQueryEndSession(
const std::vector<std::string>& reasons, const std::vector<std::string>& reasons,
bool* prevent_default) { bool* prevent_default) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowQueryEndSession, reasons,
observer.OnWindowQueryEndSession(reasons, prevent_default); prevent_default);
} }
void NativeWindow::NotifyWindowEndSession( void NativeWindow::NotifyWindowEndSession(
const std::vector<std::string>& reasons) { const std::vector<std::string>& reasons) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowEndSession, reasons);
observer.OnWindowEndSession(reasons);
} }
void NativeWindow::NotifyWindowBlur() { void NativeWindow::NotifyWindowBlur() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowBlur);
observer.OnWindowBlur();
} }
void NativeWindow::NotifyWindowFocus() { void NativeWindow::NotifyWindowFocus() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowFocus);
observer.OnWindowFocus();
} }
void NativeWindow::NotifyWindowIsKeyChanged(bool is_key) { void NativeWindow::NotifyWindowIsKeyChanged(bool is_key) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowIsKeyChanged, is_key);
observer.OnWindowIsKeyChanged(is_key);
} }
void NativeWindow::NotifyWindowShow() { void NativeWindow::NotifyWindowShow() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowShow);
observer.OnWindowShow();
} }
void NativeWindow::NotifyWindowHide() { void NativeWindow::NotifyWindowHide() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowHide);
observer.OnWindowHide();
} }
void NativeWindow::NotifyWindowMaximize() { void NativeWindow::NotifyWindowMaximize() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowMaximize);
observer.OnWindowMaximize();
} }
void NativeWindow::NotifyWindowUnmaximize() { void NativeWindow::NotifyWindowUnmaximize() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowUnmaximize);
observer.OnWindowUnmaximize();
} }
void NativeWindow::NotifyWindowMinimize() { void NativeWindow::NotifyWindowMinimize() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowMinimize);
observer.OnWindowMinimize();
} }
void NativeWindow::NotifyWindowRestore() { void NativeWindow::NotifyWindowRestore() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowRestore);
observer.OnWindowRestore();
} }
void NativeWindow::NotifyWindowWillResize(const gfx::Rect& new_bounds, void NativeWindow::NotifyWindowWillResize(const gfx::Rect& new_bounds,
const gfx::ResizeEdge& edge, const gfx::ResizeEdge& edge,
bool* prevent_default) { bool* prevent_default) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowWillResize, new_bounds, edge,
observer.OnWindowWillResize(new_bounds, edge, prevent_default); prevent_default);
} }
void NativeWindow::NotifyWindowWillMove(const gfx::Rect& new_bounds, void NativeWindow::NotifyWindowWillMove(const gfx::Rect& new_bounds,
bool* prevent_default) { bool* prevent_default) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowWillMove, new_bounds,
observer.OnWindowWillMove(new_bounds, prevent_default); prevent_default);
} }
void NativeWindow::NotifyWindowResize() { void NativeWindow::NotifyWindowResize() {
NotifyLayoutWindowControlsOverlay(); NotifyLayoutWindowControlsOverlay();
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowResize);
observer.OnWindowResize();
} }
void NativeWindow::NotifyWindowResized() { void NativeWindow::NotifyWindowResized() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowResized);
observer.OnWindowResized();
} }
void NativeWindow::NotifyWindowMove() { void NativeWindow::NotifyWindowMove() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowMove);
observer.OnWindowMove();
} }
void NativeWindow::NotifyWindowMoved() { void NativeWindow::NotifyWindowMoved() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowMoved);
observer.OnWindowMoved();
} }
void NativeWindow::NotifyWindowEnterFullScreen() { void NativeWindow::NotifyWindowEnterFullScreen() {
NotifyLayoutWindowControlsOverlay(); NotifyLayoutWindowControlsOverlay();
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowEnterFullScreen);
observer.OnWindowEnterFullScreen();
} }
void NativeWindow::NotifyWindowSwipe(const std::string& direction) { void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowSwipe, direction);
observer.OnWindowSwipe(direction);
} }
void NativeWindow::NotifyWindowRotateGesture(float rotation) { void NativeWindow::NotifyWindowRotateGesture(float rotation) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowRotateGesture, rotation);
observer.OnWindowRotateGesture(rotation);
} }
void NativeWindow::NotifyWindowSheetBegin() { void NativeWindow::NotifyWindowSheetBegin() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowSheetBegin);
observer.OnWindowSheetBegin();
} }
void NativeWindow::NotifyWindowSheetEnd() { void NativeWindow::NotifyWindowSheetEnd() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowSheetEnd);
observer.OnWindowSheetEnd();
} }
void NativeWindow::NotifyWindowLeaveFullScreen() { void NativeWindow::NotifyWindowLeaveFullScreen() {
NotifyLayoutWindowControlsOverlay(); NotifyLayoutWindowControlsOverlay();
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowLeaveFullScreen);
observer.OnWindowLeaveFullScreen();
} }
void NativeWindow::NotifyWindowEnterHtmlFullScreen() { void NativeWindow::NotifyWindowEnterHtmlFullScreen() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowEnterHtmlFullScreen);
observer.OnWindowEnterHtmlFullScreen();
} }
void NativeWindow::NotifyWindowLeaveHtmlFullScreen() { void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowLeaveHtmlFullScreen);
observer.OnWindowLeaveHtmlFullScreen();
} }
void NativeWindow::NotifyWindowAlwaysOnTopChanged() { void NativeWindow::NotifyWindowAlwaysOnTopChanged() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowAlwaysOnTopChanged);
observer.OnWindowAlwaysOnTopChanged();
} }
void NativeWindow::NotifyWindowExecuteAppCommand( void NativeWindow::NotifyWindowExecuteAppCommand(
const std::string_view command_name) { const std::string_view command_name) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnExecuteAppCommand, command_name);
observer.OnExecuteAppCommand(command_name);
} }
void NativeWindow::NotifyTouchBarItemInteraction(const std::string& item_id, void NativeWindow::NotifyTouchBarItemInteraction(const std::string& item_id,
base::Value::Dict details) { base::Value::Dict details) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnTouchBarItemResult, item_id,
observer.OnTouchBarItemResult(item_id, details); details);
} }
void NativeWindow::NotifyNewWindowForTab() { void NativeWindow::NotifyNewWindowForTab() {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnNewWindowForTab);
observer.OnNewWindowForTab();
} }
void NativeWindow::NotifyWindowSystemContextMenu(int x, void NativeWindow::NotifyWindowSystemContextMenu(int x,
int y, int y,
bool* prevent_default) { bool* prevent_default) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnSystemContextMenu, x, y,
observer.OnSystemContextMenu(x, y, prevent_default); prevent_default);
} }
void NativeWindow::NotifyLayoutWindowControlsOverlay() { void NativeWindow::NotifyLayoutWindowControlsOverlay() {
auto bounding_rect = GetWindowControlsOverlayRect(); if (const auto bounds = GetWindowControlsOverlayRect())
if (bounding_rect.has_value()) { observers_.Notify(&NativeWindowObserver::UpdateWindowControlsOverlay,
for (NativeWindowObserver& observer : observers_) *bounds);
observer.UpdateWindowControlsOverlay(bounding_rect.value());
}
} }
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
void NativeWindow::NotifyWindowMessage(UINT message, void NativeWindow::NotifyWindowMessage(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
for (NativeWindowObserver& observer : observers_) observers_.Notify(&NativeWindowObserver::OnWindowMessage, message, w_param,
observer.OnWindowMessage(message, w_param, l_param); l_param);
} }
#endif #endif

View file

@ -128,20 +128,19 @@ void ElectronSerialDelegate::DeleteControllerForFrame(
// SerialChooserContext::PortObserver: // SerialChooserContext::PortObserver:
void ElectronSerialDelegate::OnPortAdded( void ElectronSerialDelegate::OnPortAdded(
const device::mojom::SerialPortInfo& port) { const device::mojom::SerialPortInfo& port) {
for (auto& observer : observer_list_) observer_list_.Notify(&content::SerialDelegate::Observer::OnPortAdded, port);
observer.OnPortAdded(port);
} }
void ElectronSerialDelegate::OnPortRemoved( void ElectronSerialDelegate::OnPortRemoved(
const device::mojom::SerialPortInfo& port) { const device::mojom::SerialPortInfo& port) {
for (auto& observer : observer_list_) observer_list_.Notify(&content::SerialDelegate::Observer::OnPortRemoved,
observer.OnPortRemoved(port); port);
} }
void ElectronSerialDelegate::OnPortManagerConnectionError() { void ElectronSerialDelegate::OnPortManagerConnectionError() {
port_observation_.Reset(); port_observation_.Reset();
for (auto& observer : observer_list_) observer_list_.Notify(
observer.OnPortManagerConnectionError(); &content::SerialDelegate::Observer::OnPortManagerConnectionError);
} }
void ElectronSerialDelegate::OnSerialChooserContextShutdown() { void ElectronSerialDelegate::OnSerialChooserContextShutdown() {

View file

@ -233,15 +233,12 @@ void SerialChooserContext::OnPortAdded(device::mojom::SerialPortInfoPtr port) {
ports.erase(port->token); ports.erase(port->token);
} }
for (auto& observer : port_observer_list_) port_observer_list_.Notify(&PortObserver::OnPortAdded, *port);
observer.OnPortAdded(*port);
} }
void SerialChooserContext::OnPortRemoved( void SerialChooserContext::OnPortRemoved(
device::mojom::SerialPortInfoPtr port) { device::mojom::SerialPortInfoPtr port) {
for (auto& observer : port_observer_list_) port_observer_list_.Notify(&PortObserver::OnPortRemoved, *port);
observer.OnPortRemoved(*port);
port_info_.erase(port->token); port_info_.erase(port->token);
} }

View file

@ -101,16 +101,12 @@ void ElectronMenuModel::SetSharingItem(SharingItem item) {
void ElectronMenuModel::MenuWillClose() { void ElectronMenuModel::MenuWillClose() {
ui::SimpleMenuModel::MenuWillClose(); ui::SimpleMenuModel::MenuWillClose();
for (Observer& observer : observers_) { observers_.Notify(&Observer::OnMenuWillClose);
observer.OnMenuWillClose();
}
} }
void ElectronMenuModel::MenuWillShow() { void ElectronMenuModel::MenuWillShow() {
ui::SimpleMenuModel::MenuWillShow(); ui::SimpleMenuModel::MenuWillShow();
for (Observer& observer : observers_) { observers_.Notify(&Observer::OnMenuWillShow);
observer.OnMenuWillShow();
}
} }
ElectronMenuModel* ElectronMenuModel::GetSubmenuModelAt(size_t index) { ElectronMenuModel* ElectronMenuModel::GetSubmenuModelAt(size_t index) {

View file

@ -19,93 +19,75 @@ gfx::Rect TrayIcon::GetBounds() {
void TrayIcon::NotifyClicked(const gfx::Rect& bounds, void TrayIcon::NotifyClicked(const gfx::Rect& bounds,
const gfx::Point& location, const gfx::Point& location,
int modifiers) { int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnClicked, bounds, location, modifiers);
observer.OnClicked(bounds, location, modifiers);
} }
void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) { void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDoubleClicked, bounds, modifiers);
observer.OnDoubleClicked(bounds, modifiers);
} }
void TrayIcon::NotifyMiddleClicked(const gfx::Rect& bounds, int modifiers) { void TrayIcon::NotifyMiddleClicked(const gfx::Rect& bounds, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnMiddleClicked, bounds, modifiers);
observer.OnMiddleClicked(bounds, modifiers);
} }
void TrayIcon::NotifyBalloonShow() { void TrayIcon::NotifyBalloonShow() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnBalloonShow);
observer.OnBalloonShow();
} }
void TrayIcon::NotifyBalloonClicked() { void TrayIcon::NotifyBalloonClicked() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnBalloonClicked);
observer.OnBalloonClicked();
} }
void TrayIcon::NotifyBalloonClosed() { void TrayIcon::NotifyBalloonClosed() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnBalloonClosed);
observer.OnBalloonClosed();
} }
void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds, int modifiers) { void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnRightClicked, bounds, modifiers);
observer.OnRightClicked(bounds, modifiers);
} }
void TrayIcon::NotifyDrop() { void TrayIcon::NotifyDrop() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDrop);
observer.OnDrop();
} }
void TrayIcon::NotifyDropFiles(const std::vector<std::string>& files) { void TrayIcon::NotifyDropFiles(const std::vector<std::string>& files) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDropFiles, files);
observer.OnDropFiles(files);
} }
void TrayIcon::NotifyDropText(const std::string& text) { void TrayIcon::NotifyDropText(const std::string& text) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDropText, text);
observer.OnDropText(text);
} }
void TrayIcon::NotifyMouseUp(const gfx::Point& location, int modifiers) { void TrayIcon::NotifyMouseUp(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnMouseUp, location, modifiers);
observer.OnMouseUp(location, modifiers);
} }
void TrayIcon::NotifyMouseDown(const gfx::Point& location, int modifiers) { void TrayIcon::NotifyMouseDown(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnMouseDown, location, modifiers);
observer.OnMouseDown(location, modifiers);
} }
void TrayIcon::NotifyMouseEntered(const gfx::Point& location, int modifiers) { void TrayIcon::NotifyMouseEntered(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnMouseEntered, location, modifiers);
observer.OnMouseEntered(location, modifiers);
} }
void TrayIcon::NotifyMouseExited(const gfx::Point& location, int modifiers) { void TrayIcon::NotifyMouseExited(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnMouseExited, location, modifiers);
observer.OnMouseExited(location, modifiers);
} }
void TrayIcon::NotifyMouseMoved(const gfx::Point& location, int modifiers) { void TrayIcon::NotifyMouseMoved(const gfx::Point& location, int modifiers) {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnMouseMoved, location, modifiers);
observer.OnMouseMoved(location, modifiers);
} }
void TrayIcon::NotifyDragEntered() { void TrayIcon::NotifyDragEntered() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDragEntered);
observer.OnDragEntered();
} }
void TrayIcon::NotifyDragExited() { void TrayIcon::NotifyDragExited() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDragExited);
observer.OnDragExited();
} }
void TrayIcon::NotifyDragEnded() { void TrayIcon::NotifyDragEnded() {
for (TrayIconObserver& observer : observers_) observers_.Notify(&TrayIconObserver::OnDragEnded);
observer.OnDragEnded();
} }
} // namespace electron } // namespace electron

View file

@ -51,14 +51,12 @@ void MenuDelegate::RunMenu(ElectronMenuModel* model,
} }
void MenuDelegate::ExecuteCommand(int id) { void MenuDelegate::ExecuteCommand(int id) {
for (Observer& obs : observers_) observers_.Notify(&Observer::OnBeforeExecuteCommand);
obs.OnBeforeExecuteCommand();
adapter_->ExecuteCommand(id); adapter_->ExecuteCommand(id);
} }
void MenuDelegate::ExecuteCommand(int id, int mouse_event_flags) { void MenuDelegate::ExecuteCommand(int id, int mouse_event_flags) {
for (Observer& obs : observers_) observers_.Notify(&Observer::OnBeforeExecuteCommand);
obs.OnBeforeExecuteCommand();
adapter_->ExecuteCommand(id, mouse_event_flags); adapter_->ExecuteCommand(id, mouse_event_flags);
} }
@ -104,8 +102,7 @@ void MenuDelegate::WillHideMenu(views::MenuItemView* menu) {
} }
void MenuDelegate::OnMenuClosed(views::MenuItemView* menu) { void MenuDelegate::OnMenuClosed(views::MenuItemView* menu) {
for (Observer& obs : observers_) observers_.Notify(&Observer::OnMenuClosed);
obs.OnMenuClosed();
// Only switch to new menu when current menu is closed. // Only switch to new menu when current menu is closed.
if (button_to_open_) if (button_to_open_)

View file

@ -102,19 +102,19 @@ class ElectronUsbDelegate::ContextObservation
// UsbChooserContext::DeviceObserver: // UsbChooserContext::DeviceObserver:
void OnDeviceAdded(const device::mojom::UsbDeviceInfo& device_info) override { void OnDeviceAdded(const device::mojom::UsbDeviceInfo& device_info) override {
for (auto& observer : observer_list_) observer_list_.Notify(&content::UsbDelegate::Observer::OnDeviceAdded,
observer.OnDeviceAdded(device_info); device_info);
} }
void OnDeviceRemoved( void OnDeviceRemoved(
const device::mojom::UsbDeviceInfo& device_info) override { const device::mojom::UsbDeviceInfo& device_info) override {
for (auto& observer : observer_list_) observer_list_.Notify(&content::UsbDelegate::Observer::OnDeviceRemoved,
observer.OnDeviceRemoved(device_info); device_info);
} }
void OnDeviceManagerConnectionError() override { void OnDeviceManagerConnectionError() override {
for (auto& observer : observer_list_) observer_list_.Notify(
observer.OnDeviceManagerConnectionError(); &content::UsbDelegate::Observer::OnDeviceManagerConnectionError);
} }
void OnBrowserContextShutdown() override { void OnBrowserContextShutdown() override {

View file

@ -286,8 +286,7 @@ void UsbChooserContext::OnDeviceAdded(
devices_.try_emplace(device_info->guid, device_info->Clone()); devices_.try_emplace(device_info->guid, device_info->Clone());
// Notify all observers. // Notify all observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnDeviceAdded, *device_info);
observer.OnDeviceAdded(*device_info);
} }
void UsbChooserContext::OnDeviceRemoved( void UsbChooserContext::OnDeviceRemoved(
@ -304,8 +303,7 @@ void UsbChooserContext::OnDeviceRemoved(
DCHECK_EQ(n_erased, 1U); DCHECK_EQ(n_erased, 1U);
// Notify all device observers. // Notify all device observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnDeviceRemoved, *device_info);
observer.OnDeviceRemoved(*device_info);
// If the device was persistent, return. Otherwise, notify all permission // If the device was persistent, return. Otherwise, notify all permission
// observers that its permissions were revoked. // observers that its permissions were revoked.
@ -327,8 +325,7 @@ void UsbChooserContext::OnDeviceManagerConnectionError() {
ephemeral_devices_.clear(); ephemeral_devices_.clear();
// Notify all device observers. // Notify all device observers.
for (auto& observer : device_observer_list_) device_observer_list_.Notify(&DeviceObserver::OnDeviceManagerConnectionError);
observer.OnDeviceManagerConnectionError();
} }
} // namespace electron } // namespace electron

View file

@ -48,9 +48,7 @@ WebContentsZoomController::WebContentsZoomController(
WebContentsZoomController::~WebContentsZoomController() { WebContentsZoomController::~WebContentsZoomController() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
for (auto& observer : observers_) { observers_.Notify(&WebContentsZoomObserver::OnZoomControllerDestroyed, this);
observer.OnZoomControllerDestroyed(this);
}
} }
void WebContentsZoomController::AddObserver(WebContentsZoomObserver* observer) { void WebContentsZoomController::AddObserver(WebContentsZoomObserver* observer) {
@ -90,8 +88,8 @@ bool WebContentsZoomController::SetZoomLevel(double level) {
ZoomChangedEventData zoom_change_data(web_contents(), old_zoom_level, ZoomChangedEventData zoom_change_data(web_contents(), old_zoom_level,
zoom_level_, true /* temporary */, zoom_level_, true /* temporary */,
zoom_mode_); zoom_mode_);
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged,
observer.OnZoomChanged(zoom_change_data); zoom_change_data);
return true; return true;
} }
@ -110,8 +108,8 @@ bool WebContentsZoomController::SetZoomLevel(double level) {
zoom_map->SetTemporaryZoomLevel(rfh_id, level); zoom_map->SetTemporaryZoomLevel(rfh_id, level);
ZoomChangedEventData zoom_change_data(web_contents(), zoom_level_, level, ZoomChangedEventData zoom_change_data(web_contents(), zoom_level_, level,
true /* temporary */, zoom_mode_); true /* temporary */, zoom_mode_);
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged,
observer.OnZoomChanged(zoom_change_data); zoom_change_data);
} else { } else {
const GURL url = content::HostZoomMap::GetURLForRenderFrameHost(rfh_id); const GURL url = content::HostZoomMap::GetURLForRenderFrameHost(rfh_id);
if (url.is_empty()) { if (url.is_empty()) {
@ -148,8 +146,7 @@ void WebContentsZoomController::SetTemporaryZoomLevel(double level) {
// Notify observers of zoom level changes. // Notify observers of zoom level changes.
ZoomChangedEventData zoom_change_data(web_contents(), zoom_level_, level, ZoomChangedEventData zoom_change_data(web_contents(), zoom_level_, level,
true /* temporary */, zoom_mode_); true /* temporary */, zoom_mode_);
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged, zoom_change_data);
observer.OnZoomChanged(zoom_change_data);
} }
bool WebContentsZoomController::UsesTemporaryZoomLevel() { bool WebContentsZoomController::UsesTemporaryZoomLevel() {
@ -213,8 +210,8 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
} else { } else {
// When we don't call any HostZoomMap set functions, we send the event // When we don't call any HostZoomMap set functions, we send the event
// manually. // manually.
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged,
observer.OnZoomChanged(*event_data_); *event_data_);
event_data_.reset(); event_data_.reset();
} }
break; break;
@ -229,8 +226,8 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
} else { } else {
// When we don't call any HostZoomMap set functions, we send the event // When we don't call any HostZoomMap set functions, we send the event
// manually. // manually.
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged,
observer.OnZoomChanged(*event_data_); *event_data_);
event_data_.reset(); event_data_.reset();
} }
break; break;
@ -303,9 +300,7 @@ void WebContentsZoomController::WebContentsDestroyed() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// At this point we should no longer be sending any zoom events with this // At this point we should no longer be sending any zoom events with this
// WebContents. // WebContents.
for (auto& observer : observers_) { observers_.Notify(&WebContentsZoomObserver::OnZoomControllerDestroyed, this);
observer.OnZoomControllerDestroyed(this);
}
embedder_zoom_controller_ = nullptr; embedder_zoom_controller_ = nullptr;
} }
@ -389,14 +384,14 @@ void WebContentsZoomController::UpdateState(const std::string& host) {
// the change should be sent. // the change should be sent.
ZoomChangedEventData zoom_change_data = *event_data_; ZoomChangedEventData zoom_change_data = *event_data_;
event_data_.reset(); event_data_.reset();
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged,
observer.OnZoomChanged(zoom_change_data); zoom_change_data);
} else { } else {
double zoom_level = GetZoomLevel(); double zoom_level = GetZoomLevel();
ZoomChangedEventData zoom_change_data(web_contents(), zoom_level, ZoomChangedEventData zoom_change_data(web_contents(), zoom_level,
zoom_level, false, zoom_mode_); zoom_level, false, zoom_mode_);
for (auto& observer : observers_) observers_.Notify(&WebContentsZoomObserver::OnZoomChanged,
observer.OnZoomChanged(zoom_change_data); zoom_change_data);
} }
} }

View file

@ -57,16 +57,13 @@ void WindowList::RemoveWindow(NativeWindow* window) {
WindowVector& windows = GetInstance()->windows_; WindowVector& windows = GetInstance()->windows_;
std::erase(windows, window); std::erase(windows, window);
if (windows.empty()) { if (windows.empty())
for (WindowListObserver& observer : GetObservers()) GetObservers().Notify(&WindowListObserver::OnWindowAllClosed);
observer.OnWindowAllClosed();
}
} }
// static // static
void WindowList::WindowCloseCancelled(NativeWindow* window) { void WindowList::WindowCloseCancelled(NativeWindow* window) {
for (WindowListObserver& observer : GetObservers()) GetObservers().Notify(&WindowListObserver::OnWindowCloseCancelled, window);
observer.OnWindowCloseCancelled(window);
} }
// static // static