Commit 8f0e1346 authored by Piotr Pawliczek's avatar Piotr Pawliczek Committed by Commit Bot

External Print Servers: Logs in device-log

This patch adds new entries to chrome://device-log with information about:
- the length of a resultant list of print servers calculated from policies
- results of querying each print servers (number of printers or error)
- the length of a final list of server printers.

BUG=chromium:1018552
TEST=tested on nautilus

Change-Id: I73516f73e3608e87b59d2a6980fbb52367d45ea4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1882650Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarLuum Habtemariam <luum@chromium.org>
Commit-Queue: Piotr Pawliczek <pawliczek@chromium.org>
Auto-Submit: Piotr Pawliczek <pawliczek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710307}
parent 23e10188
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
#include "components/device_event_log/device_event_log.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
...@@ -282,8 +283,13 @@ class CupsPrintersManagerImpl ...@@ -282,8 +283,13 @@ class CupsPrintersManagerImpl
// Callback for ServerPrintersProvider. // Callback for ServerPrintersProvider.
void OnPrintersUpdated(bool complete) { void OnPrintersUpdated(bool complete) {
OnPrintersFound(kPrintServerDetector, const std::vector<PrinterDetector::DetectedPrinter> printers =
server_printers_provider_->GetPrinters()); server_printers_provider_->GetPrinters();
if (complete) {
PRINTER_LOG(EVENT) << "The list of server printers has been completed. "
<< "Number of server printers: " << printers.size();
}
OnPrintersFound(kPrintServerDetector, printers);
} }
private: private:
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
#include "base/hash/md5.h" #include "base/hash/md5.h"
#include "base/logging.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/net/system_network_context_manager.h"
#include "components/device_event_log/device_event_log.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
...@@ -42,9 +44,11 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -42,9 +44,11 @@ class ServerPrintersFetcher::PrivateImplementation
public: public:
PrivateImplementation(const ServerPrintersFetcher* owner, PrivateImplementation(const ServerPrintersFetcher* owner,
const GURL& server_url, const GURL& server_url,
const std::string& server_name,
ServerPrintersFetcher::OnPrintersFetchedCallback cb) ServerPrintersFetcher::OnPrintersFetchedCallback cb)
: owner_(owner), : owner_(owner),
server_url_(server_url), server_url_(server_url),
server_name_(server_name),
callback_(std::move(cb)), callback_(std::move(cb)),
task_runner_(base::CreateSequencedTaskRunner( task_runner_(base::CreateSequencedTaskRunner(
{base::ThreadPool(), base::TaskShutdownBehavior::BLOCK_SHUTDOWN})) { {base::ThreadPool(), base::TaskShutdownBehavior::BLOCK_SHUTDOWN})) {
...@@ -75,6 +79,9 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -75,6 +79,9 @@ class ServerPrintersFetcher::PrivateImplementation
void OnComplete(bool success) override { void OnComplete(bool success) override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!success) { if (!success) {
PRINTER_LOG(ERROR) << "Error when querying the print server "
<< server_name_
<< ": NetError=" << simple_url_loader_->NetError();
// Some error occurred. Call the callback with an empty vector. // Some error occurred. Call the callback with an empty vector.
PostResponse({}); PostResponse({});
return; return;
...@@ -87,11 +94,13 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -87,11 +94,13 @@ class ServerPrintersFetcher::PrivateImplementation
!client.ParseResponseAndSaveTo(&response)) { !client.ParseResponseAndSaveTo(&response)) {
// Parser has failed. Dump errors to the log. // Parser has failed. Dump errors to the log.
std::string message = "Cannot parse response from the print server " + std::string message = "Cannot parse response from the print server " +
server_url_.spec() + ". Parser log:"; server_name_ + ". Parser log:";
for (const auto& entry : client.GetErrorLog()) { for (const auto& entry : client.GetErrorLog()) {
message += "\n * " + entry.message; message += "\n * " + entry.message;
} }
LOG(WARNING) << message; LOG(WARNING) << message;
PRINTER_LOG(ERROR) << "Error when querying the print server "
<< server_name_ << ": unparsable IPP response.";
// Call the callback with an empty vector and exit. // Call the callback with an empty vector and exit.
PostResponse({}); PostResponse({});
return; return;
...@@ -105,6 +114,9 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -105,6 +114,9 @@ class ServerPrintersFetcher::PrivateImplementation
InitializePrinter(&(printers[i].printer), name); InitializePrinter(&(printers[i].printer), name);
} }
// Call the callback with queried printers. // Call the callback with queried printers.
PRINTER_LOG(DEBUG) << "The print server " << server_name_ << " returned "
<< printers.size() << " printer"
<< (printers.size() == 1 ? "." : "s.");
PostResponse(std::move(printers)); PostResponse(std::move(printers));
} }
...@@ -185,6 +197,7 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -185,6 +197,7 @@ class ServerPrintersFetcher::PrivateImplementation
const ServerPrintersFetcher* owner_; const ServerPrintersFetcher* owner_;
const GURL server_url_; const GURL server_url_;
const std::string server_name_;
scoped_refptr<base::SequencedTaskRunner> task_runner_for_callback_; scoped_refptr<base::SequencedTaskRunner> task_runner_for_callback_;
ServerPrintersFetcher::OnPrintersFetchedCallback callback_; ServerPrintersFetcher::OnPrintersFetchedCallback callback_;
...@@ -200,8 +213,12 @@ class ServerPrintersFetcher::PrivateImplementation ...@@ -200,8 +213,12 @@ class ServerPrintersFetcher::PrivateImplementation
}; };
ServerPrintersFetcher::ServerPrintersFetcher(const GURL& server_url, ServerPrintersFetcher::ServerPrintersFetcher(const GURL& server_url,
const std::string& server_name,
OnPrintersFetchedCallback cb) OnPrintersFetchedCallback cb)
: pim_(new PrivateImplementation(this, server_url, std::move(cb)), : pim_(new PrivateImplementation(this,
server_url,
server_name,
std::move(cb)),
PimDeleter()) {} PimDeleter()) {}
void ServerPrintersFetcher::PimDeleter::operator()( void ServerPrintersFetcher::PimDeleter::operator()(
......
...@@ -32,7 +32,9 @@ class ServerPrintersFetcher { ...@@ -32,7 +32,9 @@ class ServerPrintersFetcher {
const GURL& server_url, const GURL& server_url,
std::vector<PrinterDetector::DetectedPrinter>&& printers)>; std::vector<PrinterDetector::DetectedPrinter>&& printers)>;
ServerPrintersFetcher(const GURL& server_url, OnPrintersFetchedCallback cb); ServerPrintersFetcher(const GURL& server_url,
const std::string& server_name,
OnPrintersFetchedCallback cb);
virtual ~ServerPrintersFetcher(); virtual ~ServerPrintersFetcher();
private: private:
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/chromeos/printing/print_servers_provider_factory.h" #include "chrome/browser/chromeos/printing/print_servers_provider_factory.h"
#include "chrome/browser/chromeos/printing/server_printers_fetcher.h" #include "chrome/browser/chromeos/printing/server_printers_fetcher.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/device_event_log/device_event_log.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace chromeos { namespace chromeos {
...@@ -69,6 +70,11 @@ class ServerPrintersProviderImpl ...@@ -69,6 +70,11 @@ class ServerPrintersProviderImpl
void OnServersChanged(bool servers_are_complete, void OnServersChanged(bool servers_are_complete,
const std::vector<PrintServer>& servers) override { const std::vector<PrintServer>& servers) override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Create an entry in the device log.
if (servers_are_complete) {
PRINTER_LOG(EVENT) << "The list of print servers has been completed. "
<< "Number of print servers: " << servers.size();
}
// Save previous state. // Save previous state.
const bool previous_complete = IsComplete(); const bool previous_complete = IsComplete();
// Initialize new state. // Initialize new state.
...@@ -77,6 +83,7 @@ class ServerPrintersProviderImpl ...@@ -77,6 +83,7 @@ class ServerPrintersProviderImpl
std::map<GURL, PrintServerWithPrinters> new_servers; std::map<GURL, PrintServerWithPrinters> new_servers;
for (const auto& server : servers) { for (const auto& server : servers) {
const GURL& url = server.GetUrl(); const GURL& url = server.GetUrl();
const std::string& name = server.GetName();
auto it_new = new_servers.emplace(url, server).first; auto it_new = new_servers.emplace(url, server).first;
auto it_old = servers_.find(url); auto it_old = servers_.find(url);
if (it_old != servers_.end()) { if (it_old != servers_.end()) {
...@@ -88,7 +95,8 @@ class ServerPrintersProviderImpl ...@@ -88,7 +95,8 @@ class ServerPrintersProviderImpl
// This is a new print server: query for printers. // This is a new print server: query for printers.
fetchers_.emplace( fetchers_.emplace(
url, std::make_unique<ServerPrintersFetcher>( url, std::make_unique<ServerPrintersFetcher>(
url, base::BindRepeating( url, name,
base::BindRepeating(
&ServerPrintersProviderImpl::OnPrintersFetched, &ServerPrintersProviderImpl::OnPrintersFetched,
weak_ptr_factory_.GetWeakPtr()))); weak_ptr_factory_.GetWeakPtr())));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment