Refactor update_client to use base::OnceCallback.
For correctness, change the type of callbacks which are invoked one time
only from base::Callback to base::OnceCallback. Same for closures.
This is a mechanical change.
BUG=780524
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I29c9b2bab9e83695f0ac041a95a23545ef852a81
Reviewed-on: https://chromium-review.googlesource.com/741037
Reviewed-by: Devlin <[email protected]>
Reviewed-by: Julian Pastarmov <[email protected]>
Reviewed-by: Joshua Pawlicki <[email protected]>
Commit-Queue: Sorin Jianu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#513520}
diff --git a/components/update_client/crx_downloader_unittest.cc b/components/update_client/crx_downloader_unittest.cc
index ae83dc18..b87257d5 100644
--- a/components/update_client/crx_downloader_unittest.cc
+++ b/components/update_client/crx_downloader_unittest.cc
@@ -5,6 +5,7 @@
#include "components/update_client/crx_downloader.h"
#include <memory>
+#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -87,15 +88,15 @@
private:
base::test::ScopedTaskEnvironment scoped_task_environment_;
scoped_refptr<net::TestURLRequestContextGetter> context_;
- base::Closure quit_closure_;
+ base::OnceClosure quit_closure_;
};
const int CrxDownloaderTest::kExpectedContext;
CrxDownloaderTest::CrxDownloaderTest()
- : callback_(base::Bind(&CrxDownloaderTest::DownloadComplete,
- base::Unretained(this),
- kExpectedContext)),
+ : callback_(base::BindOnce(&CrxDownloaderTest::DownloadComplete,
+ base::Unretained(this),
+ kExpectedContext)),
progress_callback_(base::Bind(&CrxDownloaderTest::DownloadProgress,
base::Unretained(this),
kExpectedContext)),
@@ -104,7 +105,7 @@
num_progress_calls_(0),
scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::IO),
- context_(new net::TestURLRequestContextGetter(
+ context_(base::MakeRefCounted<net::TestURLRequestContextGetter>(
base::ThreadTaskRunnerHandle::Get())) {}
CrxDownloaderTest::~CrxDownloaderTest() {
@@ -122,12 +123,11 @@
download_progress_result_ = CrxDownloader::Result();
// Do not use the background downloader in these tests.
- crx_downloader_.reset(CrxDownloader::Create(false, context_.get()).release());
+ crx_downloader_ = CrxDownloader::Create(false, context_.get());
crx_downloader_->set_progress_callback(progress_callback_);
- get_interceptor_.reset(
- new GetInterceptor(base::ThreadTaskRunnerHandle::Get(),
- base::ThreadTaskRunnerHandle::Get()));
+ get_interceptor_ = std::make_unique<GetInterceptor>(
+ base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get());
}
void CrxDownloaderTest::TearDown() {
@@ -136,7 +136,7 @@
void CrxDownloaderTest::Quit() {
if (!quit_closure_.is_null())
- quit_closure_.Run();
+ std::move(quit_closure_).Run();
}
void CrxDownloaderTest::DownloadComplete(int crx_context,
@@ -173,7 +173,8 @@
// Tests that starting a download without a url results in an error.
TEST_F(CrxDownloaderTest, NoUrl) {
std::vector<GURL> urls;
- crx_downloader_->StartDownload(urls, std::string("abcd"), callback_);
+ crx_downloader_->StartDownload(urls, std::string("abcd"),
+ std::move(callback_));
RunThreadsUntilIdle();
EXPECT_EQ(1, num_download_complete_calls_);
@@ -190,7 +191,7 @@
TEST_F(CrxDownloaderTest, NoHash) {
std::vector<GURL> urls(1, GURL("http://somehost/somefile"));
- crx_downloader_->StartDownload(urls, std::string(), callback_);
+ crx_downloader_->StartDownload(urls, std::string(), std::move(callback_));
RunThreadsUntilIdle();
EXPECT_EQ(1, num_download_complete_calls_);
@@ -211,8 +212,8 @@
const base::FilePath test_file(MakeTestFilePath(kTestFileName));
get_interceptor_->SetResponse(expected_crx_url, test_file);
- crx_downloader_->StartDownloadFromUrl(expected_crx_url,
- std::string(hash_jebg), callback_);
+ crx_downloader_->StartDownloadFromUrl(
+ expected_crx_url, std::string(hash_jebg), std::move(callback_));
RunThreads();
EXPECT_EQ(1, get_interceptor_->GetHitCount());
@@ -245,7 +246,7 @@
expected_crx_url,
std::string(
"813c59747e139a608b3b5fc49633affc6db574373f309f156ea6d27229c0b3f9"),
- callback_);
+ std::move(callback_));
RunThreads();
EXPECT_EQ(1, get_interceptor_->GetHitCount());
@@ -282,7 +283,8 @@
urls.push_back(expected_crx_url);
urls.push_back(expected_crx_url);
- crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
+ crx_downloader_->StartDownload(urls, std::string(hash_jebg),
+ std::move(callback_));
RunThreads();
EXPECT_EQ(1, get_interceptor_->GetHitCount());
@@ -313,7 +315,7 @@
crx_downloader_->StartDownloadFromUrl(
GURL("http://no.such.host"
"/download/jebgalgnebhfojomionfpkfelancnnkf.crx"),
- std::string(hash_jebg), callback_);
+ std::string(hash_jebg), std::move(callback_));
RunThreads();
EXPECT_EQ(0, get_interceptor_->GetHitCount());
@@ -333,7 +335,8 @@
get_interceptor_->SetResponse(expected_crx_url, test_file);
crx_downloader_->StartDownloadFromUrl(GURL("http://localhost/no/such/file"),
- std::string(hash_jebg), callback_);
+ std::string(hash_jebg),
+ std::move(callback_));
RunThreads();
EXPECT_EQ(0, get_interceptor_->GetHitCount());
@@ -362,7 +365,8 @@
urls.push_back(GURL("http://localhost/no/such/file"));
urls.push_back(expected_crx_url);
- crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
+ crx_downloader_->StartDownload(urls, std::string(hash_jebg),
+ std::move(callback_));
RunThreads();
EXPECT_EQ(1, get_interceptor_->GetHitCount());
@@ -395,7 +399,8 @@
urls.push_back(expected_crx_url);
urls.push_back(GURL("http://localhost/no/such/file"));
- crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
+ crx_downloader_->StartDownload(urls, std::string(hash_jebg),
+ std::move(callback_));
RunThreads();
EXPECT_EQ(1, get_interceptor_->GetHitCount());
@@ -429,7 +434,8 @@
"http://no.such.host/"
"/download/jebgalgnebhfojomionfpkfelancnnkf.crx"));
- crx_downloader_->StartDownload(urls, std::string(hash_jebg), callback_);
+ crx_downloader_->StartDownload(urls, std::string(hash_jebg),
+ std::move(callback_));
RunThreads();
EXPECT_EQ(0, get_interceptor_->GetHitCount());