Commit 0f7c9249 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Switch CloudPrintProxyService::PrintersCallback to OnceCallback.

Change-Id: I1c3ad2db29d6f5446a045990036f467054d735d8
Reviewed-on: https://chromium-review.googlesource.com/1179307
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584674}
parent 0f20148b
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
...@@ -110,7 +111,7 @@ ExtensionFunction::ResponseAction CloudPrintPrivateGetPrintersFunction::Run() { ...@@ -110,7 +111,7 @@ ExtensionFunction::ResponseAction CloudPrintPrivateGetPrintersFunction::Run() {
return RespondNow(Error(kErrorIncognito)); return RespondNow(Error(kErrorIncognito));
service->GetPrinters( service->GetPrinters(
base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this)); base::BindOnce(&CloudPrintPrivateGetPrintersFunction::SendResults, this));
return RespondLater(); return RespondLater();
} }
......
...@@ -34,14 +34,13 @@ using content::BrowserThread; ...@@ -34,14 +34,13 @@ using content::BrowserThread;
namespace { namespace {
void ForwardGetPrintersResult( void ForwardGetPrintersResult(CloudPrintProxyService::PrintersCallback callback,
const CloudPrintProxyService::PrintersCallback& callback, const std::vector<std::string>& printers) {
const std::vector<std::string>& printers) {
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
ServiceProcessControl::SERVICE_PRINTERS_REPLY, ServiceProcessControl::SERVICE_PRINTERS_REPLY,
ServiceProcessControl::SERVICE_EVENT_MAX); ServiceProcessControl::SERVICE_EVENT_MAX);
UMA_HISTOGRAM_COUNTS_10000("CloudPrint.AvailablePrinters", printers.size()); UMA_HISTOGRAM_COUNTS_10000("CloudPrint.AvailablePrinters", printers.size());
callback.Run(printers); std::move(callback).Run(printers);
} }
std::string ReadCloudPrintSetupProxyList(const base::FilePath& path) { std::string ReadCloudPrintSetupProxyList(const base::FilePath& path) {
...@@ -140,11 +139,12 @@ bool CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() { ...@@ -140,11 +139,12 @@ bool CloudPrintProxyService::ApplyCloudPrintConnectorPolicy() {
return true; return true;
} }
void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) { void CloudPrintProxyService::GetPrinters(PrintersCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { if (!profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, std::vector<std::string>())); FROM_HERE,
base::BindOnce(std::move(callback), std::vector<std::string>()));
return; return;
} }
...@@ -154,7 +154,7 @@ void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) { ...@@ -154,7 +154,7 @@ void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) {
if (list_path.empty()) { if (list_path.empty()) {
InvokeServiceTask( InvokeServiceTask(
base::BindOnce(&CloudPrintProxyService::GetCloudPrintProxyPrinters, base::BindOnce(&CloudPrintProxyService::GetCloudPrintProxyPrinters,
weak_factory_.GetWeakPtr(), callback)); weak_factory_.GetWeakPtr(), std::move(callback)));
return; return;
} }
...@@ -162,11 +162,11 @@ void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) { ...@@ -162,11 +162,11 @@ void CloudPrintProxyService::GetPrinters(const PrintersCallback& callback) {
extensions::GetExtensionFileTaskRunner().get(), FROM_HERE, extensions::GetExtensionFileTaskRunner().get(), FROM_HERE,
base::BindOnce(&ReadCloudPrintSetupProxyList, list_path), base::BindOnce(&ReadCloudPrintSetupProxyList, list_path),
base::BindOnce(&CloudPrintProxyService::OnReadCloudPrintSetupProxyList, base::BindOnce(&CloudPrintProxyService::OnReadCloudPrintSetupProxyList,
weak_factory_.GetWeakPtr(), callback)); weak_factory_.GetWeakPtr(), std::move(callback)));
} }
void CloudPrintProxyService::GetCloudPrintProxyPrinters( void CloudPrintProxyService::GetCloudPrintProxyPrinters(
const PrintersCallback& callback) { PrintersCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
ServiceProcessControl::SERVICE_PRINTERS_REQUEST, ServiceProcessControl::SERVICE_PRINTERS_REQUEST,
...@@ -174,7 +174,7 @@ void CloudPrintProxyService::GetCloudPrintProxyPrinters( ...@@ -174,7 +174,7 @@ void CloudPrintProxyService::GetCloudPrintProxyPrinters(
ServiceProcessControl* process_control = GetServiceProcessControl(); ServiceProcessControl* process_control = GetServiceProcessControl();
DCHECK(process_control->IsConnected()); DCHECK(process_control->IsConnected());
GetCloudPrintProxy().GetPrinters( GetCloudPrintProxy().GetPrinters(
base::BindOnce(&ForwardGetPrintersResult, callback)); base::BindOnce(&ForwardGetPrintersResult, std::move(callback)));
} }
void CloudPrintProxyService::RefreshCloudPrintProxyStatus() { void CloudPrintProxyService::RefreshCloudPrintProxyStatus() {
...@@ -241,7 +241,7 @@ cloud_print::mojom::CloudPrint& CloudPrintProxyService::GetCloudPrintProxy() { ...@@ -241,7 +241,7 @@ cloud_print::mojom::CloudPrint& CloudPrintProxyService::GetCloudPrintProxy() {
} }
void CloudPrintProxyService::OnReadCloudPrintSetupProxyList( void CloudPrintProxyService::OnReadCloudPrintSetupProxyList(
const PrintersCallback& callback, PrintersCallback callback,
const std::string& printers_json) { const std::string& printers_json) {
std::unique_ptr<base::Value> list_value = std::unique_ptr<base::Value> list_value =
base::ListValue::From(base::JSONReader::Read(printers_json)); base::ListValue::From(base::JSONReader::Read(printers_json));
...@@ -255,5 +255,5 @@ void CloudPrintProxyService::OnReadCloudPrintSetupProxyList( ...@@ -255,5 +255,5 @@ void CloudPrintProxyService::OnReadCloudPrintSetupProxyList(
UMA_HISTOGRAM_COUNTS_10000("CloudPrint.AvailablePrintersList", UMA_HISTOGRAM_COUNTS_10000("CloudPrint.AvailablePrintersList",
printers.size()); printers.size());
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, printers)); FROM_HERE, base::BindOnce(std::move(callback), printers));
} }
...@@ -33,15 +33,15 @@ class CloudPrintProxyService : public KeyedService { ...@@ -33,15 +33,15 @@ class CloudPrintProxyService : public KeyedService {
explicit CloudPrintProxyService(Profile* profile); explicit CloudPrintProxyService(Profile* profile);
~CloudPrintProxyService() override; ~CloudPrintProxyService() override;
typedef base::Callback<void(const std::vector<std::string>&)> using PrintersCallback =
PrintersCallback; base::OnceCallback<void(const std::vector<std::string>&)>;
// Initializes the object. This should be called every time an object of this // Initializes the object. This should be called every time an object of this
// class is constructed. // class is constructed.
void Initialize(); void Initialize();
// Returns list of printer names available for registration. // Returns list of printer names available for registration.
void GetPrinters(const PrintersCallback& callback); void GetPrinters(PrintersCallback callback);
// Enables/disables cloud printing for the user // Enables/disables cloud printing for the user
virtual void EnableForUserWithRobot(const std::string& robot_auth_code, virtual void EnableForUserWithRobot(const std::string& robot_auth_code,
...@@ -54,7 +54,7 @@ class CloudPrintProxyService : public KeyedService { ...@@ -54,7 +54,7 @@ class CloudPrintProxyService : public KeyedService {
// update the browser prefs. // update the browser prefs.
void RefreshStatusFromService(); void RefreshStatusFromService();
std::string proxy_id() const { return proxy_id_; } const std::string& proxy_id() const { return proxy_id_; }
private: private:
// NotificationDelegate implementation for the token expired notification. // NotificationDelegate implementation for the token expired notification.
...@@ -62,7 +62,7 @@ class CloudPrintProxyService : public KeyedService { ...@@ -62,7 +62,7 @@ class CloudPrintProxyService : public KeyedService {
friend class TokenExpiredNotificationDelegate; friend class TokenExpiredNotificationDelegate;
// Methods that send an IPC to the service. // Methods that send an IPC to the service.
void GetCloudPrintProxyPrinters(const PrintersCallback& callback); void GetCloudPrintProxyPrinters(PrintersCallback callback);
void RefreshCloudPrintProxyStatus(); void RefreshCloudPrintProxyStatus();
void EnableCloudPrintProxyWithRobot(const std::string& robot_auth_code, void EnableCloudPrintProxyWithRobot(const std::string& robot_auth_code,
const std::string& robot_email, const std::string& robot_email,
...@@ -89,7 +89,7 @@ class CloudPrintProxyService : public KeyedService { ...@@ -89,7 +89,7 @@ class CloudPrintProxyService : public KeyedService {
// Virtual for testing. // Virtual for testing.
virtual ServiceProcessControl* GetServiceProcessControl(); virtual ServiceProcessControl* GetServiceProcessControl();
void OnReadCloudPrintSetupProxyList(const PrintersCallback& callback, void OnReadCloudPrintSetupProxyList(PrintersCallback callback,
const std::string& printers_json); const std::string& printers_json);
Profile* const profile_; Profile* const profile_;
......
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