OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/webui/settings/chromeos/cups_printers_handler.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/threading/sequenced_task_runner_handle.h" | 17 #include "base/threading/sequenced_task_runner_handle.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" | 20 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" |
20 #include "chrome/browser/chromeos/printing/printer_configurer.h" | 21 #include "chrome/browser/chromeos/printing/printer_configurer.h" |
21 #include "chrome/browser/chromeos/printing/printer_discoverer.h" | 22 #include "chrome/browser/chromeos/printing/printer_discoverer.h" |
22 #include "chrome/browser/chromeos/printing/printers_manager_factory.h" | 23 #include "chrome/browser/chromeos/printing/printers_manager_factory.h" |
23 #include "chrome/browser/download/download_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
37 #include "net/base/filename_util.h" | 38 #include "net/base/filename_util.h" |
38 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
39 #include "printing/backend/print_backend.h" | 40 #include "printing/backend/print_backend.h" |
40 #include "url/third_party/mozilla/url_parse.h" | 41 #include "url/third_party/mozilla/url_parse.h" |
41 | 42 |
42 namespace chromeos { | 43 namespace chromeos { |
43 namespace settings { | 44 namespace settings { |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 void OnRemovedPrinter(bool success) {} | 48 void OnRemovedPrinter(const Printer::PrinterProtocol& protocol, bool success) { |
49 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterRemoved", protocol, | |
50 Printer::PrinterProtocol::kProtocolMax); | |
51 } | |
48 | 52 |
49 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { | 53 std::unique_ptr<base::DictionaryValue> GetPrinterInfo(const Printer& printer) { |
50 std::unique_ptr<base::DictionaryValue> printer_info = | 54 std::unique_ptr<base::DictionaryValue> printer_info = |
51 base::MakeUnique<base::DictionaryValue>(); | 55 base::MakeUnique<base::DictionaryValue>(); |
52 printer_info->SetString("printerId", printer.id()); | 56 printer_info->SetString("printerId", printer.id()); |
53 printer_info->SetString("printerName", printer.display_name()); | 57 printer_info->SetString("printerName", printer.display_name()); |
54 printer_info->SetString("printerDescription", printer.description()); | 58 printer_info->SetString("printerDescription", printer.description()); |
55 printer_info->SetString("printerManufacturer", printer.manufacturer()); | 59 printer_info->SetString("printerManufacturer", printer.manufacturer()); |
56 printer_info->SetString("printerModel", printer.model()); | 60 printer_info->SetString("printerModel", printer.model()); |
57 // Get protocol, ip address and queue from the printer's URI. | 61 // Get protocol, ip address and queue from the printer's URI. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 printer->set_display_name(printer_name); | 172 printer->set_display_name(printer_name); |
169 PrintersManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( | 173 PrintersManagerFactory::GetForBrowserContext(profile_)->RegisterPrinter( |
170 std::move(printer)); | 174 std::move(printer)); |
171 } | 175 } |
172 | 176 |
173 void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { | 177 void CupsPrintersHandler::HandleRemoveCupsPrinter(const base::ListValue* args) { |
174 std::string printer_id; | 178 std::string printer_id; |
175 std::string printer_name; | 179 std::string printer_name; |
176 CHECK(args->GetString(0, &printer_id)); | 180 CHECK(args->GetString(0, &printer_id)); |
177 CHECK(args->GetString(1, &printer_name)); | 181 CHECK(args->GetString(1, &printer_name)); |
178 PrintersManagerFactory::GetForBrowserContext(profile_)->RemovePrinter( | 182 PrintersManager* prefs = |
179 printer_id); | 183 PrintersManagerFactory::GetForBrowserContext(profile_); |
184 auto printer = prefs->GetPrinter(printer_id); | |
185 | |
186 if (!printer) { | |
187 LOG(WARNING) << "Tried to remove non-existant printer"; | |
Dan Beam
2017/05/31 18:06:17
do we really need this LOG()?
Dan Beam
2017/05/31 18:06:17
existent
skau
2017/05/31 18:34:06
Now that you mention it, it's not that useful. Re
| |
188 return; | |
189 } | |
190 Printer::PrinterProtocol protocol = printer->GetProtocol(); | |
191 | |
192 prefs->RemovePrinter(printer_id); | |
180 | 193 |
181 chromeos::DebugDaemonClient* client = | 194 chromeos::DebugDaemonClient* client = |
182 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 195 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
183 client->CupsRemovePrinter(printer_name, base::Bind(&OnRemovedPrinter), | 196 client->CupsRemovePrinter(printer_name, |
197 base::Bind(&OnRemovedPrinter, protocol), | |
184 base::Bind(&base::DoNothing)); | 198 base::Bind(&base::DoNothing)); |
185 } | 199 } |
186 | 200 |
187 void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) { | 201 void CupsPrintersHandler::HandleAddCupsPrinter(const base::ListValue* args) { |
188 AllowJavascript(); | 202 AllowJavascript(); |
189 | 203 |
190 const base::DictionaryValue* printer_dict = nullptr; | 204 const base::DictionaryValue* printer_dict = nullptr; |
191 CHECK(args->GetDictionary(0, &printer_dict)); | 205 CHECK(args->GetDictionary(0, &printer_dict)); |
192 | 206 |
193 std::string printer_id; | 207 std::string printer_id; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 base::Bind(&CupsPrintersHandler::OnAddedPrinter, | 264 base::Bind(&CupsPrintersHandler::OnAddedPrinter, |
251 weak_factory_.GetWeakPtr(), base::Passed(&printer))); | 265 weak_factory_.GetWeakPtr(), base::Passed(&printer))); |
252 } | 266 } |
253 | 267 |
254 void CupsPrintersHandler::OnAddedPrinter( | 268 void CupsPrintersHandler::OnAddedPrinter( |
255 std::unique_ptr<Printer> printer, | 269 std::unique_ptr<Printer> printer, |
256 chromeos::PrinterSetupResult result_code) { | 270 chromeos::PrinterSetupResult result_code) { |
257 std::string printer_name = printer->display_name(); | 271 std::string printer_name = printer->display_name(); |
258 switch (result_code) { | 272 switch (result_code) { |
259 case chromeos::PrinterSetupResult::kSuccess: { | 273 case chromeos::PrinterSetupResult::kSuccess: { |
274 UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.PrinterAdded", | |
275 printer->GetProtocol(), Printer::kProtocolMax); | |
260 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); | 276 auto* manager = PrintersManagerFactory::GetForBrowserContext(profile_); |
261 manager->PrinterInstalled(*printer); | 277 manager->PrinterInstalled(*printer); |
262 manager->RegisterPrinter(std::move(printer)); | 278 manager->RegisterPrinter(std::move(printer)); |
263 break; | 279 break; |
264 } | 280 } |
265 case chromeos::PrinterSetupResult::kPpdNotFound: | 281 case chromeos::PrinterSetupResult::kPpdNotFound: |
266 LOG(WARNING) << "Could not locate requested PPD"; | 282 LOG(WARNING) << "Could not locate requested PPD"; |
267 break; | 283 break; |
268 case chromeos::PrinterSetupResult::kPpdTooLarge: | 284 case chromeos::PrinterSetupResult::kPpdTooLarge: |
269 LOG(WARNING) << "PPD is too large"; | 285 LOG(WARNING) << "PPD is too large"; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 | 428 |
413 FireWebUIListener("on-printer-discovered", *printers_list); | 429 FireWebUIListener("on-printer-discovered", *printers_list); |
414 } | 430 } |
415 | 431 |
416 void CupsPrintersHandler::OnDiscoveryInitialScanDone() { | 432 void CupsPrintersHandler::OnDiscoveryInitialScanDone() { |
417 FireWebUIListener("on-printer-discovery-done"); | 433 FireWebUIListener("on-printer-discovery-done"); |
418 } | 434 } |
419 | 435 |
420 } // namespace settings | 436 } // namespace settings |
421 } // namespace chromeos | 437 } // namespace chromeos |
OLD | NEW |