Commit 20803e28 authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

Migrate WebApkInstallService::FinishCallback to use OnceCallback.

Also fixed lint errors in modified files.

Bug: 714018
Change-Id: I1a5347e8adab28edabebb386e5e5ef20b6ebe938
Reviewed-on: https://chromium-review.googlesource.com/1117374Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571613}
parent 47da420f
......@@ -4,6 +4,8 @@
#include "chrome/browser/android/webapk/webapk_install_service.h"
#include <utility>
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
......@@ -60,9 +62,9 @@ void WebApkInstallService::InstallAsync(content::WebContents* web_contents,
void WebApkInstallService::UpdateAsync(
const base::FilePath& update_request_path,
const FinishCallback& finish_callback) {
FinishCallback finish_callback) {
WebApkInstaller::UpdateAsync(browser_context_, update_request_path,
finish_callback);
std::move(finish_callback));
}
void WebApkInstallService::OnFinishedInstall(
......
......@@ -54,7 +54,7 @@ class WebApkInstallService : public KeyedService {
// from the WebAPK server.
// - the package name of the WebAPK.
using FinishCallback =
base::Callback<void(WebApkInstallResult, bool, const std::string&)>;
base::OnceCallback<void(WebApkInstallResult, bool, const std::string&)>;
static WebApkInstallService* Get(content::BrowserContext* browser_context);
......@@ -78,7 +78,7 @@ class WebApkInstallService : public KeyedService {
// |update_request_path| is the path of the file with the update request.
// Calls |finish_callback| once the update completed or failed.
void UpdateAsync(const base::FilePath& update_request_path,
const FinishCallback& finish_callback);
FinishCallback finish_callback);
private:
// Observes the lifetime of a WebContents.
......
......@@ -312,20 +312,20 @@ void WebApkInstaller::InstallAsync(content::BrowserContext* context,
const ShortcutInfo& shortcut_info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon,
const FinishCallback& finish_callback) {
FinishCallback finish_callback) {
// The installer will delete itself when it is done.
WebApkInstaller* installer = new WebApkInstaller(context);
installer->InstallAsync(shortcut_info, primary_icon, badge_icon,
finish_callback);
std::move(finish_callback));
}
// static
void WebApkInstaller::UpdateAsync(content::BrowserContext* context,
const base::FilePath& update_request_path,
const FinishCallback& finish_callback) {
FinishCallback finish_callback) {
// The installer will delete itself when it is done.
WebApkInstaller* installer = new WebApkInstaller(context);
installer->UpdateAsync(update_request_path, finish_callback);
installer->UpdateAsync(update_request_path, std::move(finish_callback));
}
// static
......@@ -333,16 +333,17 @@ void WebApkInstaller::InstallAsyncForTesting(WebApkInstaller* installer,
const ShortcutInfo& shortcut_info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon,
const FinishCallback& callback) {
installer->InstallAsync(shortcut_info, primary_icon, badge_icon, callback);
FinishCallback callback) {
installer->InstallAsync(shortcut_info, primary_icon, badge_icon,
std::move(callback));
}
// static
void WebApkInstaller::UpdateAsyncForTesting(
WebApkInstaller* installer,
const base::FilePath& update_request_path,
const FinishCallback& finish_callback) {
installer->UpdateAsync(update_request_path, finish_callback);
FinishCallback finish_callback) {
installer->UpdateAsync(update_request_path, std::move(finish_callback));
}
void WebApkInstaller::SetTimeoutMs(int timeout_ms) {
......@@ -365,13 +366,14 @@ void WebApkInstaller::BuildProto(
const std::string& version,
const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
bool is_manifest_stale,
const base::Callback<void(std::unique_ptr<std::string>)>& callback) {
base::OnceCallback<void(std::unique_ptr<std::string>)> callback) {
base::PostTaskAndReplyWithResult(
GetBackgroundTaskRunner().get(), FROM_HERE,
base::Bind(&BuildProtoInBackground, shortcut_info, primary_icon,
badge_icon, package_name, version, icon_url_to_murmur2_hash,
is_manifest_stale, WebApkUpdateReason::NONE),
callback);
base::BindOnce(&BuildProtoInBackground, shortcut_info, primary_icon,
badge_icon, package_name, version,
icon_url_to_murmur2_hash, is_manifest_stale,
WebApkUpdateReason::NONE),
std::move(callback));
}
// static
......@@ -385,13 +387,14 @@ void WebApkInstaller::StoreUpdateRequestToFile(
const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
bool is_manifest_stale,
WebApkUpdateReason update_reason,
const base::Callback<void(bool)> callback) {
base::OnceCallback<void(bool)> callback) {
base::PostTaskAndReplyWithResult(
GetBackgroundTaskRunner().get(), FROM_HERE,
base::Bind(&StoreUpdateRequestToFileInBackground, update_request_path,
shortcut_info, primary_icon, badge_icon, package_name, version,
icon_url_to_murmur2_hash, is_manifest_stale, update_reason),
callback);
base::BindOnce(&StoreUpdateRequestToFileInBackground, update_request_path,
shortcut_info, primary_icon, badge_icon, package_name,
version, icon_url_to_murmur2_hash, is_manifest_stale,
update_reason),
std::move(callback));
}
void WebApkInstaller::InstallOrUpdateWebApk(const std::string& package_name,
......@@ -422,7 +425,7 @@ void WebApkInstaller::InstallOrUpdateWebApk(const std::string& package_name,
void WebApkInstaller::OnResult(WebApkInstallResult result) {
weak_ptr_factory_.InvalidateWeakPtrs();
finish_callback_.Run(result, relax_updates_, webapk_package_);
std::move(finish_callback_).Run(result, relax_updates_, webapk_package_);
if (task_type_ == WebApkInstaller::INSTALL) {
if (result == WebApkInstallResult::SUCCESS) {
......@@ -456,14 +459,14 @@ void WebApkInstaller::CreateJavaRef() {
void WebApkInstaller::InstallAsync(const ShortcutInfo& shortcut_info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon,
const FinishCallback& finish_callback) {
FinishCallback finish_callback) {
install_duration_timer_.reset(new base::ElapsedTimer());
install_shortcut_info_.reset(new ShortcutInfo(shortcut_info));
install_primary_icon_ = primary_icon;
install_badge_icon_ = badge_icon;
short_name_ = shortcut_info.short_name;
finish_callback_ = finish_callback;
finish_callback_ = std::move(finish_callback);
task_type_ = INSTALL;
CheckFreeSpace();
......@@ -498,15 +501,15 @@ void WebApkInstaller::OnGotSpaceStatus(
}
void WebApkInstaller::UpdateAsync(const base::FilePath& update_request_path,
const FinishCallback& finish_callback) {
finish_callback_ = finish_callback;
FinishCallback finish_callback) {
finish_callback_ = std::move(finish_callback);
task_type_ = UPDATE;
base::PostTaskAndReplyWithResult(
GetBackgroundTaskRunner().get(), FROM_HERE,
base::Bind(&ReadFileInBackground, update_request_path),
base::Bind(&WebApkInstaller::OnReadUpdateRequest,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&ReadFileInBackground, update_request_path),
base::BindOnce(&WebApkInstaller::OnReadUpdateRequest,
weak_ptr_factory_.GetWeakPtr()));
}
void WebApkInstaller::OnReadUpdateRequest(
......@@ -629,8 +632,8 @@ void WebApkInstaller::OnGotBadgeIconMurmur2Hash(
BuildProto(*install_shortcut_info_, install_primary_icon_,
install_badge_icon_, "" /* package_name */, "" /* version */,
icon_url_to_murmur2_hash, false /* is_manifest_stale */,
base::Bind(&WebApkInstaller::SendRequest,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&WebApkInstaller::SendRequest,
weak_ptr_factory_.GetWeakPtr()));
}
void WebApkInstaller::SendRequest(
......
......@@ -8,6 +8,7 @@
#include <jni.h>
#include <map>
#include <memory>
#include <string>
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
......@@ -58,7 +59,7 @@ class WebApkInstaller : public net::URLFetcherDelegate {
const ShortcutInfo& shortcut_info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon,
const FinishCallback& finish_callback);
FinishCallback finish_callback);
// Creates a self-owned WebApkInstaller instance and talks to the Chrome
// WebAPK server to update a WebAPK on the server and locally requests the
......@@ -66,7 +67,7 @@ class WebApkInstaller : public net::URLFetcherDelegate {
// |update_request_path| is the path of the file with the update request.
static void UpdateAsync(content::BrowserContext* context,
const base::FilePath& update_request_path,
const FinishCallback& callback);
FinishCallback callback);
// Calls the private function |InstallAsync| for testing.
// Should be used only for testing.
......@@ -74,13 +75,13 @@ class WebApkInstaller : public net::URLFetcherDelegate {
const ShortcutInfo& shortcut_info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon,
const FinishCallback& callback);
FinishCallback callback);
// Calls the private function |UpdateAsync| for testing.
// Should be used only for testing.
static void UpdateAsyncForTesting(WebApkInstaller* installer,
const base::FilePath& update_request_path,
const FinishCallback& callback);
FinishCallback callback);
// Sets the timeout for the server requests.
void SetTimeoutMs(int timeout_ms);
......@@ -108,7 +109,7 @@ class WebApkInstaller : public net::URLFetcherDelegate {
const std::string& version,
const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
bool is_manifest_stale,
const base::Callback<void(std::unique_ptr<std::string>)>& callback);
base::OnceCallback<void(std::unique_ptr<std::string>)> callback);
// Builds the WebAPK proto for an update or an install request and stores it
// to |update_request_path|. Runs |callback| with a boolean indicating
......@@ -123,7 +124,7 @@ class WebApkInstaller : public net::URLFetcherDelegate {
const std::map<std::string, std::string>& icon_url_to_murmur2_hash,
bool is_manifest_stale,
WebApkUpdateReason update_reason,
const base::Callback<void(bool)> callback);
base::OnceCallback<void(bool)> callback);
protected:
explicit WebApkInstaller(content::BrowserContext* browser_context);
......@@ -156,14 +157,14 @@ class WebApkInstaller : public net::URLFetcherDelegate {
void InstallAsync(const ShortcutInfo& shortcut_info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon,
const FinishCallback& finish_callback);
FinishCallback finish_callback);
// Talks to the Chrome WebAPK server to update a WebAPK on the server and to
// the Google Play server to install the downloaded WebAPK.
// |update_request_path| is the path of the file with the update request.
// Calls |finish_callback| once the update completed or failed.
void UpdateAsync(const base::FilePath& update_request_path,
const FinishCallback& finish_callback);
FinishCallback finish_callback);
// Called once there is sufficient space on the user's device to install a
// WebAPK. The user may already have had sufficient space on their device
......
......@@ -4,9 +4,7 @@
#include "chrome/browser/android/webapk/webapk_installer.h"
#include <jni.h>
#include <memory>
#include <string>
#include <utility>
#include "base/android/scoped_java_ref.h"
#include "base/bind.h"
......@@ -116,8 +114,8 @@ class WebApkInstallerRunner {
info.best_badge_icon_url = best_badge_icon_url_;
WebApkInstaller::InstallAsyncForTesting(
CreateWebApkInstaller(), info, SkBitmap(), SkBitmap(),
base::Bind(&WebApkInstallerRunner::OnCompleted,
base::Unretained(this)));
base::BindOnce(&WebApkInstallerRunner::OnCompleted,
base::Unretained(this)));
run_loop.Run();
}
......@@ -128,8 +126,8 @@ class WebApkInstallerRunner {
WebApkInstaller::UpdateAsyncForTesting(
CreateWebApkInstaller(), update_request_path,
base::Bind(&WebApkInstallerRunner::OnCompleted,
base::Unretained(this)));
base::BindOnce(&WebApkInstallerRunner::OnCompleted,
base::Unretained(this)));
run_loop.Run();
}
......@@ -183,7 +181,8 @@ class UpdateRequestStorer {
update_request_path, ShortcutInfo((GURL())), SkBitmap(), SkBitmap(), "",
"", std::map<std::string, std::string>(), false,
WebApkUpdateReason::PRIMARY_ICON_HASH_DIFFERS,
base::Bind(&UpdateRequestStorer::OnComplete, base::Unretained(this)));
base::BindOnce(&UpdateRequestStorer::OnComplete,
base::Unretained(this)));
run_loop.Run();
}
......@@ -233,8 +232,8 @@ class BuildProtoRunner {
WebApkInstaller::BuildProto(
info, primary_icon, badge_icon, "" /* package_name */, "" /* version */,
icon_url_to_murmur2_hash, is_manifest_stale,
base::Bind(&BuildProtoRunner::OnBuiltWebApkProto,
base::Unretained(this)));
base::BindOnce(&BuildProtoRunner::OnBuiltWebApkProto,
base::Unretained(this)));
base::RunLoop run_loop;
on_completed_callback_ = run_loop.QuitClosure();
......@@ -289,7 +288,7 @@ class WebApkInstallerTest : public ::testing::Test {
void SetUp() override {
test_server_.AddDefaultHandlers(base::FilePath(kTestDataDir));
test_server_.RegisterRequestHandler(base::Bind(
test_server_.RegisterRequestHandler(base::BindRepeating(
&WebApkInstallerTest::HandleWebApkRequest, base::Unretained(this)));
ASSERT_TRUE(test_server_.Start());
......@@ -439,7 +438,7 @@ BuildUnparsableWebApkResponse() {
// Test that an HTTP response which cannot be parsed as a webapk::WebApkResponse
// is handled properly.
TEST_F(WebApkInstallerTest, UnparsableCreateWebApkResponse) {
SetWebApkResponseBuilder(base::Bind(&BuildUnparsableWebApkResponse));
SetWebApkResponseBuilder(base::BindRepeating(&BuildUnparsableWebApkResponse));
std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner();
runner->RunInstallWebApk();
......@@ -466,7 +465,7 @@ TEST_F(WebApkInstallerTest, UpdateSuccess) {
// - The most up to date version of the WebAPK on the server is identical to the
// one installed on the client.
TEST_F(WebApkInstallerTest, UpdateSuccessWithEmptyTokenInResponse) {
SetWebApkResponseBuilder(base::Bind(&BuildValidWebApkResponse, ""));
SetWebApkResponseBuilder(base::BindRepeating(&BuildValidWebApkResponse, ""));
ScopedTempFile scoped_file;
base::FilePath update_request_path = scoped_file.GetFilePath();
......
......@@ -128,8 +128,8 @@ static void JNI_WebApkUpdateManager_StoreWebApkUpdateRequestToFile(
base::FilePath(update_request_path), info, primary_icon, badge_icon,
webapk_package, std::to_string(java_webapk_version),
icon_url_to_murmur2_hash, java_is_manifest_stale, update_reason,
base::Bind(&OnStoredUpdateRequest,
ScopedJavaGlobalRef<jobject>(java_callback)));
base::BindOnce(&OnStoredUpdateRequest,
ScopedJavaGlobalRef<jobject>(java_callback)));
}
// static JNI method.
......
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