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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc

Issue 2790603003: Make CUPS USB printing play better with the settings page. This change does several things: (Closed)
Patch Set: Address xdai@ comments Created 3 years, 8 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 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
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_ = chromeos::PrinterDiscoverer::Create(profile_);
383 }
383 384
384 printer_discoverer_->AddObserver(this); 385 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 } 386 }
391 387
392 void CupsPrintersHandler::HandleStopDiscovery(const base::ListValue* args) { 388 void CupsPrintersHandler::HandleStopDiscovery(const base::ListValue* args) {
393 if (printer_discoverer_.get()) { 389 printer_discoverer_.reset();
394 printer_discoverer_->RemoveObserver(this);
395 printer_discoverer_->StopDiscovery();
396 printer_discoverer_.reset();
397 }
398 } 390 }
399 391
400 void CupsPrintersHandler::OnPrintersFound( 392 void CupsPrintersHandler::OnPrintersFound(
401 const std::vector<Printer>& printers) { 393 const std::vector<Printer>& printers) {
402 std::unique_ptr<base::ListValue> printers_list = 394 std::unique_ptr<base::ListValue> printers_list =
403 base::MakeUnique<base::ListValue>(); 395 base::MakeUnique<base::ListValue>();
404 for (const auto& printer : printers) { 396 for (const auto& printer : printers) {
405 std::unique_ptr<base::DictionaryValue> printer_info = 397 printers_list->Append(GetPrinterInfo(printer));
406 GetPrinterInfo(printer);
407 printers_list->Append(std::move(printer_info));
408 } 398 }
409 399
410 CallJavascriptFunction("cr.webUIListenerCallback", 400 CallJavascriptFunction("cr.webUIListenerCallback",
411 base::Value("on-printer-discovered"), *printers_list); 401 base::Value("on-printer-discovered"), *printers_list);
412 } 402 }
413 403
414 void CupsPrintersHandler::OnDiscoveryDone() { 404 void CupsPrintersHandler::OnDiscoveryInitialScanDone() {
415 CallJavascriptFunction("cr.webUIListenerCallback", 405 CallJavascriptFunction("cr.webUIListenerCallback",
416 base::Value("on-printer-discovery-done")); 406 base::Value("on-printer-discovery-done"));
417 } 407 }
418 408
419 } // namespace settings 409 } // namespace settings
420 } // namespace chromeos 410 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698