| 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/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/sequenced_task_runner_handle.h" | 16 #include "base/threading/sequenced_task_runner_handle.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/printing/fake_printer_discoverer.h" | |
| 20 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" | 19 #include "chrome/browser/chromeos/printing/ppd_provider_factory.h" |
| 21 #include "chrome/browser/chromeos/printing/printer_configurer.h" | 20 #include "chrome/browser/chromeos/printing/printer_configurer.h" |
| 21 #include "chrome/browser/chromeos/printing/printer_discoverer.h" |
| 22 #include "chrome/browser/chromeos/printing/printers_manager_factory.h" | 22 #include "chrome/browser/chromeos/printing/printers_manager_factory.h" |
| 23 #include "chrome/browser/download/download_prefs.h" | 23 #include "chrome/browser/download/download_prefs.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/chrome_select_file_policy.h" | 27 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 28 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 29 #include "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
| 30 #include "chromeos/dbus/debug_daemon_client.h" | 30 #include "chromeos/dbus/debug_daemon_client.h" |
| 31 #include "chromeos/printing/ppd_cache.h" | 31 #include "chromeos/printing/ppd_cache.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 void CupsPrintersHandler::FileSelected(const base::FilePath& path, | 371 void CupsPrintersHandler::FileSelected(const base::FilePath& path, |
| 372 int index, | 372 int index, |
| 373 void* params) { | 373 void* params) { |
| 374 DCHECK(!webui_callback_id_.empty()); | 374 DCHECK(!webui_callback_id_.empty()); |
| 375 ResolveJavascriptCallback(base::Value(webui_callback_id_), | 375 ResolveJavascriptCallback(base::Value(webui_callback_id_), |
| 376 base::Value(path.value())); | 376 base::Value(path.value())); |
| 377 webui_callback_id_.clear(); | 377 webui_callback_id_.clear(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void CupsPrintersHandler::HandleStartDiscovery(const base::ListValue* args) { | 380 void CupsPrintersHandler::HandleStartDiscovery(const base::ListValue* args) { |
| 381 if (!printer_discoverer_.get()) | 381 if (!printer_discoverer_.get()) { |
| 382 printer_discoverer_ = chromeos::PrinterDiscoverer::Create(); | 382 printer_discoverer_ = |
| 383 chromeos::PrinterDiscoverer::CreateForProfile(profile_); |
| 384 } |
| 383 | 385 |
| 384 printer_discoverer_->AddObserver(this); | 386 printer_discoverer_->AddObserver(this); |
| 385 if (!printer_discoverer_->StartDiscovery()) { | |
| 386 CallJavascriptFunction("cr.webUIListenerCallback", | |
| 387 base::Value("on-printer-discovery-failed")); | |
| 388 printer_discoverer_->RemoveObserver(this); | |
| 389 } | |
| 390 } | 387 } |
| 391 | 388 |
| 392 void CupsPrintersHandler::HandleStopDiscovery(const base::ListValue* args) { | 389 void CupsPrintersHandler::HandleStopDiscovery(const base::ListValue* args) { |
| 393 if (printer_discoverer_.get()) { | 390 printer_discoverer_.reset(); |
| 394 printer_discoverer_->RemoveObserver(this); | |
| 395 printer_discoverer_->StopDiscovery(); | |
| 396 printer_discoverer_.reset(); | |
| 397 } | |
| 398 } | 391 } |
| 399 | 392 |
| 400 void CupsPrintersHandler::OnPrintersFound( | 393 void CupsPrintersHandler::OnPrintersFound( |
| 401 const std::vector<Printer>& printers) { | 394 const std::vector<Printer>& printers) { |
| 402 std::unique_ptr<base::ListValue> printers_list = | 395 std::unique_ptr<base::ListValue> printers_list = |
| 403 base::MakeUnique<base::ListValue>(); | 396 base::MakeUnique<base::ListValue>(); |
| 404 for (const auto& printer : printers) { | 397 for (const auto& printer : printers) { |
| 405 std::unique_ptr<base::DictionaryValue> printer_info = | 398 printers_list->Append(GetPrinterInfo(printer)); |
| 406 GetPrinterInfo(printer); | |
| 407 printers_list->Append(std::move(printer_info)); | |
| 408 } | 399 } |
| 409 | 400 |
| 410 CallJavascriptFunction("cr.webUIListenerCallback", | 401 CallJavascriptFunction("cr.webUIListenerCallback", |
| 411 base::Value("on-printer-discovered"), *printers_list); | 402 base::Value("on-printer-discovered"), *printers_list); |
| 412 } | 403 } |
| 413 | 404 |
| 414 void CupsPrintersHandler::OnDiscoveryDone() { | 405 void CupsPrintersHandler::OnDiscoveryInitialScanDone() { |
| 415 CallJavascriptFunction("cr.webUIListenerCallback", | 406 CallJavascriptFunction("cr.webUIListenerCallback", |
| 416 base::Value("on-printer-discovery-done")); | 407 base::Value("on-printer-discovery-done")); |
| 417 } | 408 } |
| 418 | 409 |
| 419 } // namespace settings | 410 } // namespace settings |
| 420 } // namespace chromeos | 411 } // namespace chromeos |
| OLD | NEW |