Commit 71da3cbb authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Convert base::Bind and base::Callback in components/quirks to Once/Repeating

Bug: 1007721
Change-Id: I227e7a9eb2d98f7650410443aa4cab3b544d3bab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1934517
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720178}
parent c58cd777
...@@ -55,11 +55,11 @@ bool WriteIccFile(const base::FilePath file_path, const std::string& data) { ...@@ -55,11 +55,11 @@ bool WriteIccFile(const base::FilePath file_path, const std::string& data) {
QuirksClient::QuirksClient(int64_t product_id, QuirksClient::QuirksClient(int64_t product_id,
const std::string& display_name, const std::string& display_name,
const RequestFinishedCallback& on_request_finished, RequestFinishedCallback on_request_finished,
QuirksManager* manager) QuirksManager* manager)
: product_id_(product_id), : product_id_(product_id),
display_name_(display_name), display_name_(display_name),
on_request_finished_(on_request_finished), on_request_finished_(std::move(on_request_finished)),
manager_(manager), manager_(manager),
icc_path_(manager->delegate()->GetDisplayProfileDirectory().Append( icc_path_(manager->delegate()->GetDisplayProfileDirectory().Append(
IdToFileName(product_id))), IdToFileName(product_id))),
...@@ -164,13 +164,14 @@ void QuirksClient::OnDownloadComplete( ...@@ -164,13 +164,14 @@ void QuirksClient::OnDownloadComplete(
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
manager_->task_runner(), FROM_HERE, manager_->task_runner(), FROM_HERE,
base::Bind(&WriteIccFile, icc_path_, data), base::BindOnce(&WriteIccFile, icc_path_, data),
base::Bind(&QuirksClient::Shutdown, weak_ptr_factory_.GetWeakPtr())); base::BindOnce(&QuirksClient::Shutdown, weak_ptr_factory_.GetWeakPtr()));
} }
void QuirksClient::Shutdown(bool success) { void QuirksClient::Shutdown(bool success) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
on_request_finished_.Run(success ? icc_path_ : base::FilePath(), true); std::move(on_request_finished_)
.Run(success ? icc_path_ : base::FilePath(), true);
manager_->ClientFinished(this); manager_->ClientFinished(this);
} }
......
...@@ -23,14 +23,14 @@ class QuirksManager; ...@@ -23,14 +23,14 @@ class QuirksManager;
// See declaration in quirks_manager.h. // See declaration in quirks_manager.h.
using RequestFinishedCallback = using RequestFinishedCallback =
base::Callback<void(const base::FilePath&, bool)>; base::OnceCallback<void(const base::FilePath&, bool)>;
// Handles downloading icc and other display data files from Quirks Server. // Handles downloading icc and other display data files from Quirks Server.
class QuirksClient { class QuirksClient {
public: public:
QuirksClient(int64_t product_id, QuirksClient(int64_t product_id,
const std::string& display_name, const std::string& display_name,
const RequestFinishedCallback& on_request_finished, RequestFinishedCallback on_request_finished,
QuirksManager* manager); QuirksManager* manager);
~QuirksClient(); ~QuirksClient();
...@@ -57,7 +57,7 @@ class QuirksClient { ...@@ -57,7 +57,7 @@ class QuirksClient {
const std::string display_name_; const std::string display_name_;
// Callback supplied by caller. // Callback supplied by caller.
const RequestFinishedCallback on_request_finished_; RequestFinishedCallback on_request_finished_;
// Weak pointer owned by manager, guaranteed to outlive this client object. // Weak pointer owned by manager, guaranteed to outlive this client object.
QuirksManager* manager_; QuirksManager* manager_;
......
...@@ -120,29 +120,29 @@ void QuirksManager::OnLoginCompleted() { ...@@ -120,29 +120,29 @@ void QuirksManager::OnLoginCompleted() {
void QuirksManager::RequestIccProfilePath( void QuirksManager::RequestIccProfilePath(
int64_t product_id, int64_t product_id,
const std::string& display_name, const std::string& display_name,
const RequestFinishedCallback& on_request_finished) { RequestFinishedCallback on_request_finished) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!QuirksEnabled()) { if (!QuirksEnabled()) {
VLOG(1) << "Quirks Client disabled."; VLOG(1) << "Quirks Client disabled.";
on_request_finished.Run(base::FilePath(), false); std::move(on_request_finished).Run(base::FilePath(), false);
return; return;
} }
if (!product_id) { if (!product_id) {
VLOG(1) << "Could not determine display information (product id = 0)"; VLOG(1) << "Could not determine display information (product id = 0)";
on_request_finished.Run(base::FilePath(), false); std::move(on_request_finished).Run(base::FilePath(), false);
return; return;
} }
std::string name = IdToFileName(product_id); std::string name = IdToFileName(product_id);
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE, task_runner_.get(), FROM_HERE,
base::Bind(&CheckForIccFile, base::BindOnce(&CheckForIccFile,
delegate_->GetDisplayProfileDirectory().Append(name)), delegate_->GetDisplayProfileDirectory().Append(name)),
base::Bind(&QuirksManager::OnIccFilePathRequestCompleted, base::BindOnce(&QuirksManager::OnIccFilePathRequestCompleted,
weak_ptr_factory_.GetWeakPtr(), product_id, display_name, weak_ptr_factory_.GetWeakPtr(), product_id, display_name,
on_request_finished)); std::move(on_request_finished)));
} }
void QuirksManager::ClientFinished(QuirksClient* client) { void QuirksManager::ClientFinished(QuirksClient* client) {
...@@ -156,13 +156,13 @@ void QuirksManager::ClientFinished(QuirksClient* client) { ...@@ -156,13 +156,13 @@ void QuirksManager::ClientFinished(QuirksClient* client) {
void QuirksManager::OnIccFilePathRequestCompleted( void QuirksManager::OnIccFilePathRequestCompleted(
int64_t product_id, int64_t product_id,
const std::string& display_name, const std::string& display_name,
const RequestFinishedCallback& on_request_finished, RequestFinishedCallback on_request_finished,
base::FilePath path) { base::FilePath path) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
// If we found a file, just inform requester. // If we found a file, just inform requester.
if (!path.empty()) { if (!path.empty()) {
on_request_finished.Run(path, false); std::move(on_request_finished).Run(path, false);
// TODO(glevin): If Quirks files are ever modified on the server, we'll need // TODO(glevin): If Quirks files are ever modified on the server, we'll need
// to modify this logic to check for updates. See crbug.com/595024. // to modify this logic to check for updates. See crbug.com/595024.
return; return;
...@@ -180,13 +180,13 @@ void QuirksManager::OnIccFilePathRequestCompleted( ...@@ -180,13 +180,13 @@ void QuirksManager::OnIccFilePathRequestCompleted(
VLOG(2) << time_since.InDays() VLOG(2) << time_since.InDays()
<< " days since last Quirks Server check for display " << " days since last Quirks Server check for display "
<< IdToHexString(product_id); << IdToHexString(product_id);
on_request_finished.Run(base::FilePath(), false); std::move(on_request_finished).Run(base::FilePath(), false);
return; return;
} }
// Create and start a client to download file. // Create and start a client to download file.
QuirksClient* client = QuirksClient* client = new QuirksClient(product_id, display_name,
new QuirksClient(product_id, display_name, on_request_finished, this); std::move(on_request_finished), this);
clients_.insert(base::WrapUnique(client)); clients_.insert(base::WrapUnique(client));
if (!waiting_for_login_) if (!waiting_for_login_)
client->StartDownload(); client->StartDownload();
......
...@@ -33,7 +33,7 @@ class QuirksClient; ...@@ -33,7 +33,7 @@ class QuirksClient;
// First parameter - path found, or empty if no file. // First parameter - path found, or empty if no file.
// Second parameter - true if file was just downloaded. // Second parameter - true if file was just downloaded.
using RequestFinishedCallback = using RequestFinishedCallback =
base::Callback<void(const base::FilePath&, bool)>; base::OnceCallback<void(const base::FilePath&, bool)>;
// Format int as hex string for filename. // Format int as hex string for filename.
QUIRKS_EXPORT std::string IdToHexString(int64_t product_id); QUIRKS_EXPORT std::string IdToHexString(int64_t product_id);
...@@ -80,10 +80,9 @@ class QUIRKS_EXPORT QuirksManager { ...@@ -80,10 +80,9 @@ class QUIRKS_EXPORT QuirksManager {
void OnLoginCompleted(); void OnLoginCompleted();
// Entry point into manager. Finds or downloads icc file. // Entry point into manager. Finds or downloads icc file.
void RequestIccProfilePath( void RequestIccProfilePath(int64_t product_id,
int64_t product_id, const std::string& display_name,
const std::string& display_name, RequestFinishedCallback on_request_finished);
const RequestFinishedCallback& on_request_finished);
void ClientFinished(QuirksClient* client); void ClientFinished(QuirksClient* client);
...@@ -112,7 +111,7 @@ class QUIRKS_EXPORT QuirksManager { ...@@ -112,7 +111,7 @@ class QUIRKS_EXPORT QuirksManager {
void OnIccFilePathRequestCompleted( void OnIccFilePathRequestCompleted(
int64_t product_id, int64_t product_id,
const std::string& display_name, const std::string& display_name,
const RequestFinishedCallback& on_request_finished, RequestFinishedCallback on_request_finished,
base::FilePath path); base::FilePath path);
// Whether downloads allowed by cmd line flag and device policy. // Whether downloads allowed by cmd line flag and device policy.
......
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