Simplify PrinterDetector Observer APIs.
This cl does several things. First, It removes the PrinterDetector::Observer::OnPrinterScanComplete API hook. That hook exists because we expected zeroconf printer detection to take a non-trivial amount of time and we wanted to be able to enable some UI indication that we were still looking for printers until the scan was complete. However, it turns out that mdns/dns-sd traffic is all cached anyways by the ServiceDiscovery, so we get initial printers back for zeroconf almost instantly, making this hook pointless. Second, the Observer API is changed so that it no longer guarantees an OnPrintersFound callback to the caller after registration; instead the client observing printer change events is responsible for calling PrinterDetector::GetPrinters() to do the initial population of the printer list. This removes a lot of weird hacks to get thread safety right. This change also removes CupsPrintersManager::Start() and PrinterDetector::StartObservers(), as these are no longer needed to make startup safe. These calls were added out of concerns that we would encounter something like: (in class Foo's constructor): my_detector_->AddObserver(this); ->OBSERVER CALLBACK HAPPENS BEFORE Foo::Foo() IS FINISHED<- ...rest of Foo's constructor... However, this isn't a real problem for the API AFAICT. Since the observer callbacks are on the same sequence as the constructor, they can't start until after the constructor finishes, meaning this is a non-issue. I think. I would appreciate reviewers taking a bit of time to think this through and see if they also believe this is now safe without the Start() calls, as concurrency is sometimes hard to reason about. This cl also removes some tests around StartObservers() that are no longer relevant with the API changes. Bug: 754834 Change-Id: Ia2e4c34b82ddf99a7551756c2bc037889f52df5b Reviewed-on: https://chromium-review.googlesource.com/871660 Commit-Queue: Justin Carlson <justincarlson@chromium.org> Reviewed-by:Sean Kau <skau@chromium.org> Reviewed-by:
Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#531673}
Showing
Please register or sign in to comment