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) {
QuirksClient::QuirksClient(int64_t product_id,
const std::string& display_name,
const RequestFinishedCallback& on_request_finished,
RequestFinishedCallback on_request_finished,
QuirksManager* manager)
: product_id_(product_id),
display_name_(display_name),
on_request_finished_(on_request_finished),
on_request_finished_(std::move(on_request_finished)),
manager_(manager),
icc_path_(manager->delegate()->GetDisplayProfileDirectory().Append(
IdToFileName(product_id))),
......@@ -164,13 +164,14 @@ void QuirksClient::OnDownloadComplete(
base::PostTaskAndReplyWithResult(
manager_->task_runner(), FROM_HERE,
base::Bind(&WriteIccFile, icc_path_, data),
base::Bind(&QuirksClient::Shutdown, weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&WriteIccFile, icc_path_, data),
base::BindOnce(&QuirksClient::Shutdown, weak_ptr_factory_.GetWeakPtr()));
}
void QuirksClient::Shutdown(bool success) {
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);
}
......
......@@ -23,14 +23,14 @@ class QuirksManager;
// See declaration in quirks_manager.h.
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.
class QuirksClient {
public:
QuirksClient(int64_t product_id,
const std::string& display_name,
const RequestFinishedCallback& on_request_finished,
RequestFinishedCallback on_request_finished,
QuirksManager* manager);
~QuirksClient();
......@@ -57,7 +57,7 @@ class QuirksClient {
const std::string display_name_;
// Callback supplied by caller.
const RequestFinishedCallback on_request_finished_;
RequestFinishedCallback on_request_finished_;
// Weak pointer owned by manager, guaranteed to outlive this client object.
QuirksManager* manager_;
......
......@@ -120,29 +120,29 @@ void QuirksManager::OnLoginCompleted() {
void QuirksManager::RequestIccProfilePath(
int64_t product_id,
const std::string& display_name,
const RequestFinishedCallback& on_request_finished) {
RequestFinishedCallback on_request_finished) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!QuirksEnabled()) {
VLOG(1) << "Quirks Client disabled.";
on_request_finished.Run(base::FilePath(), false);
std::move(on_request_finished).Run(base::FilePath(), false);
return;
}
if (!product_id) {
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;
}
std::string name = IdToFileName(product_id);
base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE,
base::Bind(&CheckForIccFile,
delegate_->GetDisplayProfileDirectory().Append(name)),
base::Bind(&QuirksManager::OnIccFilePathRequestCompleted,
weak_ptr_factory_.GetWeakPtr(), product_id, display_name,
on_request_finished));
base::BindOnce(&CheckForIccFile,
delegate_->GetDisplayProfileDirectory().Append(name)),
base::BindOnce(&QuirksManager::OnIccFilePathRequestCompleted,
weak_ptr_factory_.GetWeakPtr(), product_id, display_name,
std::move(on_request_finished)));
}
void QuirksManager::ClientFinished(QuirksClient* client) {
......@@ -156,13 +156,13 @@ void QuirksManager::ClientFinished(QuirksClient* client) {
void QuirksManager::OnIccFilePathRequestCompleted(
int64_t product_id,
const std::string& display_name,
const RequestFinishedCallback& on_request_finished,
RequestFinishedCallback on_request_finished,
base::FilePath path) {
DCHECK(thread_checker_.CalledOnValidThread());
// If we found a file, just inform requester.
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
// to modify this logic to check for updates. See crbug.com/595024.
return;
......@@ -180,13 +180,13 @@ void QuirksManager::OnIccFilePathRequestCompleted(
VLOG(2) << time_since.InDays()
<< " days since last Quirks Server check for display "
<< IdToHexString(product_id);
on_request_finished.Run(base::FilePath(), false);
std::move(on_request_finished).Run(base::FilePath(), false);
return;
}
// Create and start a client to download file.
QuirksClient* client =
new QuirksClient(product_id, display_name, on_request_finished, this);
QuirksClient* client = new QuirksClient(product_id, display_name,
std::move(on_request_finished), this);
clients_.insert(base::WrapUnique(client));
if (!waiting_for_login_)
client->StartDownload();
......
......@@ -33,7 +33,7 @@ class QuirksClient;
// First parameter - path found, or empty if no file.
// Second parameter - true if file was just downloaded.
using RequestFinishedCallback =
base::Callback<void(const base::FilePath&, bool)>;
base::OnceCallback<void(const base::FilePath&, bool)>;
// Format int as hex string for filename.
QUIRKS_EXPORT std::string IdToHexString(int64_t product_id);
......@@ -80,10 +80,9 @@ class QUIRKS_EXPORT QuirksManager {
void OnLoginCompleted();
// Entry point into manager. Finds or downloads icc file.
void RequestIccProfilePath(
int64_t product_id,
const std::string& display_name,
const RequestFinishedCallback& on_request_finished);
void RequestIccProfilePath(int64_t product_id,
const std::string& display_name,
RequestFinishedCallback on_request_finished);
void ClientFinished(QuirksClient* client);
......@@ -112,7 +111,7 @@ class QUIRKS_EXPORT QuirksManager {
void OnIccFilePathRequestCompleted(
int64_t product_id,
const std::string& display_name,
const RequestFinishedCallback& on_request_finished,
RequestFinishedCallback on_request_finished,
base::FilePath path);
// 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