Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/chromeos/printing/printer_discoverer.cc

Issue 2904243003: Add Printing.CUPS.PrintersDiscovered to our metrics. (Closed)
Patch Set: generalized comment Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/printing/printer_discoverer.h" 5 #include "chrome/browser/chromeos/printing/printer_discoverer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 void RemoveObserver(PrinterDiscoverer::Observer* observer) override { 52 void RemoveObserver(PrinterDiscoverer::Observer* observer) override {
53 observer_list_.RemoveObserver(observer); 53 observer_list_.RemoveObserver(observer);
54 } 54 }
55 55
56 // PrinterDetector::Observer interface function. 56 // PrinterDetector::Observer interface function.
57 void OnAvailableUsbPrintersChanged( 57 void OnAvailableUsbPrintersChanged(
58 const std::vector<Printer>& printers) override { 58 const std::vector<Printer>& printers) override {
59 usb_printers_ = printers; 59 usb_printers_ = printers;
60 std::vector<Printer> all_printers = GetAvailablePrinters(); 60 std::vector<Printer> all_printers = GetAvailablePrinters();
61 for (PrinterDiscoverer::Observer& observer : observer_list_) { 61 for (PrinterDiscoverer::Observer& observer : observer_list_) {
62 observer.OnPrintersFound(all_printers); 62 // We get all USB printers the first time so the scan is completed.
63 observer.OnPrintersFound(true /*scan_done*/, all_printers);
dpapad 2017/05/26 21:02:03 When is OnPrintersFound called with |false|? I don
skau 2017/05/26 21:20:10 It's not called with false right now. The interfa
63 } 64 }
64 } 65 }
65 66
66 private: 67 private:
67 // Wrapper for doing the initial OnPrintersFound call on an observer of this 68 // Wrapper for doing the initial OnPrintersFound call on an observer of this
68 // object. 69 // object.
69 void WrappedOnPrintersFound(PrinterDiscoverer::Observer* observer, 70 void WrappedOnPrintersFound(PrinterDiscoverer::Observer* observer,
70 const std::vector<Printer>& printers) { 71 const std::vector<Printer>& printers) {
71 if (observer_list_.HasObserver(observer)) { 72 if (observer_list_.HasObserver(observer)) {
72 observer->OnPrintersFound(printers);
73 // Since USB is the only thing we're worried about at the moment, and we 73 // Since USB is the only thing we're worried about at the moment, and we
74 // don't have to wait for those printers to be scanned, we can just tell 74 // don't have to wait for those printers to be scanned, we can just tell
75 // the observer the initial scan is done now. This will change when we're 75 // the observer the initial scan is done now. This will change when we're
76 // also doing network discovery -- we'll hold off on issuing this callback 76 // also doing network discovery -- we'll hold off on issuing this callback
77 // until the network discovery is done as well. 77 // until the network discovery is done as well.
78 observer->OnDiscoveryInitialScanDone(); 78 observer->OnPrintersFound(true, printers);
79 } 79 }
80 } 80 }
81 81
82 // Get the current set of discovered printers that are not already known 82 // Get the current set of discovered printers that are not already known
83 // to the user's PrintersManager. 83 // to the user's PrintersManager.
84 std::vector<Printer> GetAvailablePrinters() { 84 std::vector<Printer> GetAvailablePrinters() {
85 // Only know about usb printers for now. Eventually we'll add discovered 85 // Only know about usb printers for now. Eventually we'll add discovered
86 // network printers as well. 86 // network printers as well.
87 std::vector<Printer> ret; 87 std::vector<Printer> ret;
88 PrintersManager* printers_manager = 88 PrintersManager* printers_manager =
(...skipping 21 matching lines...) Expand all
110 110
111 } // namespace 111 } // namespace
112 112
113 // static 113 // static
114 std::unique_ptr<PrinterDiscoverer> PrinterDiscoverer::CreateForProfile( 114 std::unique_ptr<PrinterDiscoverer> PrinterDiscoverer::CreateForProfile(
115 Profile* profile) { 115 Profile* profile) {
116 return base::MakeUnique<PrinterDiscovererImpl>(profile); 116 return base::MakeUnique<PrinterDiscovererImpl>(profile);
117 } 117 }
118 118
119 } // namespace chromeos 119 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698