Commit 5ddc014e authored by Sean Kau's avatar Sean Kau Committed by Commit Bot

Only refresh the printer list when we disconnect from a network

Currently, we're clearing the printers list anytime we get a network
change event.  This is fine, except this can include completing
connection to a network and a change in signal strength.  This can get
out-of-sync with the ZeroconfPrinterDetector and cause our list of
printers to be in an invalid state.

Manifests as entries in settings that are reported as having
"disappeared".

Bug: 1137999
Change-Id: Ic89ce0e3e65a70d98a027019cd8b4e1fd626946a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480825Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Sean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818985}
parent 77b20633
......@@ -264,11 +264,21 @@ class CupsPrintersManagerImpl
void OnActiveNetworksChanged(
std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
networks) override {
if (!HasNetworkDisconnected(networks)) {
// We only update the discovered list if we disconnected from our previous
// default network.
return;
}
PRINTER_LOG(DEBUG) << "Network change. Refresh printers list.";
// Clear the network detected printers when the active network changes.
// This ensures that connecting to a new network will give us only newly
// detected printers.
ClearNetworkDetectedPrinters();
// Notify observers that the printer list has changed.
RebuildDetectedLists();
}
void OnNetworkStateChanged(
......@@ -603,6 +613,33 @@ class CupsPrintersManagerImpl
}
}
// Returns true if we've disconnected from our current network. Updates
// the current active network. This method is not reentrant.
bool HasNetworkDisconnected(
const std::vector<
chromeos::network_config::mojom::NetworkStatePropertiesPtr>&
networks) {
// An empty current_network indicates that we're not connected to a valid
// network right now.
std::string current_network;
if (!networks.empty()) {
// The first network is the default network which receives mDNS
// multicasts.
current_network = networks.front()->guid;
}
// If we attach to a network after being disconnected, we do not want to
// forcibly clear our detected list. It is either already empty or contains
// valid entries because we missed the original connection event.
bool network_disconnected =
!active_network_.empty() && current_network != active_network_;
// Ensure that we don't register network state updates as network changes.
active_network_ = std::move(current_network);
return network_disconnected;
}
// Record in UMA the appropriate event with a setup attempt for a printer is
// abandoned.
void RecordSetupAbandoned(const Printer& printer) override {
......@@ -710,6 +747,9 @@ class CupsPrintersManagerImpl
// is initialized and configured correctly.
bool enterprise_printers_are_ready_ = false;
// GUID of the current default network.
std::string active_network_;
// Tracks PpdReference resolution. Also stores USB manufacturer string if
// available.
PpdResolutionTracker ppd_resolution_tracker_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment