Skip to content

Commit

Permalink
chore: remove observers when SerialChooserContext is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
jkleinsc committed Jul 19, 2022
1 parent f9d69e3 commit 6222cab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 4 additions & 1 deletion shell/browser/serial/serial_chooser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ base::Value PortInfoToValue(const device::mojom::SerialPortInfo& port) {
SerialChooserContext::SerialChooserContext(ElectronBrowserContext* context)
: browser_context_(context) {}

SerialChooserContext::~SerialChooserContext() = default;
SerialChooserContext::~SerialChooserContext() {
for (auto& observer : port_observer_list_)
port_observer_list_.RemoveObserver(&observer);
}

void SerialChooserContext::OnPermissionRevoked(const url::Origin& origin) {
for (auto& observer : port_observer_list_)
Expand Down
5 changes: 1 addition & 4 deletions shell/browser/serial/serial_chooser_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ SerialChooserController::SerialChooserController(

SerialChooserController::~SerialChooserController() {
RunCallback(/*port=*/nullptr);
if (chooser_context_) {
chooser_context_->RemovePortObserver(this);
}
}

api::Session* SerialChooserController::GetSession() {
Expand Down Expand Up @@ -118,7 +115,7 @@ void SerialChooserController::OnPortRemoved(
}

void SerialChooserController::OnPortManagerConnectionError() {
// TODO(nornagon/jkleinsc): report event
observation_.Reset();
}

void SerialChooserController::OnDeviceChosen(const std::string& port_id) {
Expand Down

0 comments on commit 6222cab

Please sign in to comment.