Commit ae24ce9f authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

🚫Bind: offline_pages, net_log, navigation_interception

Migrates some directories off of deprecated base::Bind, base::Callback,
etc, and onto the newer APIs.

Specifically this covers:

- components/navigation_interception/
- components/net_log/
- components/offline_pages/

Fixed: 1007710, 1007705, 1007704
Change-Id: Ifdab534c0dce4d1b484540b6c770a0f3d8e6e7c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1976493Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarJian Li <jianli@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#726480}
parent 4bce4c14
...@@ -71,7 +71,8 @@ InterceptNavigationDelegate::CreateThrottleFor( ...@@ -71,7 +71,8 @@ InterceptNavigationDelegate::CreateThrottleFor(
content::NavigationHandle* handle, content::NavigationHandle* handle,
navigation_interception::SynchronyMode mode) { navigation_interception::SynchronyMode mode) {
return std::make_unique<InterceptNavigationThrottle>( return std::make_unique<InterceptNavigationThrottle>(
handle, base::Bind(&CheckIfShouldIgnoreNavigationOnUIThread), mode); handle, base::BindRepeating(&CheckIfShouldIgnoreNavigationOnUIThread),
mode);
} }
InterceptNavigationDelegate::InterceptNavigationDelegate( InterceptNavigationDelegate::InterceptNavigationDelegate(
......
...@@ -77,7 +77,7 @@ NetExportFileWriter::NetExportFileWriter() ...@@ -77,7 +77,7 @@ NetExportFileWriter::NetExportFileWriter()
log_exists_(false), log_exists_(false),
log_capture_mode_known_(false), log_capture_mode_known_(false),
log_capture_mode_(net::NetLogCaptureMode::kDefault), log_capture_mode_(net::NetLogCaptureMode::kDefault),
default_log_base_dir_getter_(base::Bind(&base::GetTempDir)) {} default_log_base_dir_getter_(base::BindRepeating(&base::GetTempDir)) {}
NetExportFileWriter::~NetExportFileWriter() { NetExportFileWriter::~NetExportFileWriter() {
if (net_log_exporter_) { if (net_log_exporter_) {
...@@ -110,8 +110,8 @@ void NetExportFileWriter::Initialize() { ...@@ -110,8 +110,8 @@ void NetExportFileWriter::Initialize() {
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
file_task_runner_.get(), FROM_HERE, file_task_runner_.get(), FROM_HERE,
base::Bind(&SetUpDefaultLogPath, default_log_base_dir_getter_), base::BindOnce(&SetUpDefaultLogPath, default_log_base_dir_getter_),
base::Bind(&NetExportFileWriter::SetStateAfterSetUpDefaultLogPath, base::BindOnce(&NetExportFileWriter::SetStateAfterSetUpDefaultLogPath,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
...@@ -266,11 +266,11 @@ std::unique_ptr<base::DictionaryValue> NetExportFileWriter::GetState() const { ...@@ -266,11 +266,11 @@ std::unique_ptr<base::DictionaryValue> NetExportFileWriter::GetState() const {
} }
void NetExportFileWriter::GetFilePathToCompletedLog( void NetExportFileWriter::GetFilePathToCompletedLog(
const FilePathCallback& path_callback) const { FilePathCallback path_callback) const {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!(log_exists_ && state_ == STATE_NOT_LOGGING)) { if (!(log_exists_ && state_ == STATE_NOT_LOGGING)) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(path_callback, base::FilePath())); FROM_HERE, base::BindOnce(std::move(path_callback), base::FilePath()));
return; return;
} }
...@@ -278,8 +278,8 @@ void NetExportFileWriter::GetFilePathToCompletedLog( ...@@ -278,8 +278,8 @@ void NetExportFileWriter::GetFilePathToCompletedLog(
DCHECK(!log_path_.empty()); DCHECK(!log_path_.empty());
base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE, base::PostTaskAndReplyWithResult(file_task_runner_.get(), FROM_HERE,
base::Bind(&GetPathIfExists, log_path_), base::BindOnce(&GetPathIfExists, log_path_),
path_callback); std::move(path_callback));
} }
std::string NetExportFileWriter::CaptureModeToString( std::string NetExportFileWriter::CaptureModeToString(
......
...@@ -78,8 +78,8 @@ class NetExportFileWriter { ...@@ -78,8 +78,8 @@ class NetExportFileWriter {
bool log_exists; bool log_exists;
}; };
using FilePathCallback = base::Callback<void(const base::FilePath&)>; using FilePathCallback = base::OnceCallback<void(const base::FilePath&)>;
using DirectoryGetter = base::Callback<bool(base::FilePath*)>; using DirectoryGetter = base::RepeatingCallback<bool(base::FilePath*)>;
// Constructs a NetExportFileWriter. Only one instance is created in browser // Constructs a NetExportFileWriter. Only one instance is created in browser
// process. // process.
...@@ -136,7 +136,7 @@ class NetExportFileWriter { ...@@ -136,7 +136,7 @@ class NetExportFileWriter {
// //
// |path_callback| will be executed at the end of GetFilePathToCompletedLog() // |path_callback| will be executed at the end of GetFilePathToCompletedLog()
// asynchronously. // asynchronously.
void GetFilePathToCompletedLog(const FilePathCallback& path_callback) const; void GetFilePathToCompletedLog(FilePathCallback path_callback) const;
// Converts to/from the string representation of a capture mode used by // Converts to/from the string representation of a capture mode used by
// net_export.js. // net_export.js.
......
...@@ -259,12 +259,11 @@ class TestStateObserver : public NetExportFileWriter::StateObserver { ...@@ -259,12 +259,11 @@ class TestStateObserver : public NetExportFileWriter::StateObserver {
// file path callback and retrieve the result. // file path callback and retrieve the result.
class TestFilePathCallback { class TestFilePathCallback {
public: public:
TestFilePathCallback() TestFilePathCallback() = default;
: callback_(base::Bind(&TestFilePathCallback::SetResultThenNotify,
base::Unretained(this))) {}
const base::Callback<void(const base::FilePath&)>& callback() const { base::OnceCallback<void(const base::FilePath&)> GetCallback() {
return callback_; return base::BindOnce(&TestFilePathCallback::SetResultThenNotify,
base::Unretained(this));
} }
const base::FilePath& WaitForResult() { const base::FilePath& WaitForResult() {
...@@ -280,7 +279,6 @@ class TestFilePathCallback { ...@@ -280,7 +279,6 @@ class TestFilePathCallback {
net::TestClosure test_closure_; net::TestClosure test_closure_;
base::FilePath result_; base::FilePath result_;
base::Callback<void(const base::FilePath&)> callback_;
}; };
class NetExportFileWriterTest : public ::testing::Test { class NetExportFileWriterTest : public ::testing::Test {
...@@ -307,8 +305,8 @@ class NetExportFileWriterTest : public ::testing::Test { ...@@ -307,8 +305,8 @@ class NetExportFileWriterTest : public ::testing::Test {
// Override |file_writer_|'s default-log-base-directory-getter to // Override |file_writer_|'s default-log-base-directory-getter to
// a getter that returns the temp dir created for the test. // a getter that returns the temp dir created for the test.
file_writer_.SetDefaultLogBaseDirectoryGetterForTest( file_writer_.SetDefaultLogBaseDirectoryGetterForTest(base::BindRepeating(
base::Bind(&SetPathToGivenAndReturnTrue, log_temp_dir_.GetPath())); &SetPathToGivenAndReturnTrue, log_temp_dir_.GetPath()));
default_log_path_ = log_temp_dir_.GetPath().Append(kLogRelativePath); default_log_path_ = log_temp_dir_.GetPath().Append(kLogRelativePath);
...@@ -326,7 +324,7 @@ class NetExportFileWriterTest : public ::testing::Test { ...@@ -326,7 +324,7 @@ class NetExportFileWriterTest : public ::testing::Test {
base::FilePath FileWriterGetFilePathToCompletedLog() { base::FilePath FileWriterGetFilePathToCompletedLog() {
TestFilePathCallback test_callback; TestFilePathCallback test_callback;
file_writer_.GetFilePathToCompletedLog(test_callback.callback()); file_writer_.GetFilePathToCompletedLog(test_callback.GetCallback());
return test_callback.WaitForResult(); return test_callback.WaitForResult();
} }
...@@ -498,7 +496,7 @@ TEST_F(NetExportFileWriterTest, InitFail) { ...@@ -498,7 +496,7 @@ TEST_F(NetExportFileWriterTest, InitFail) {
// Override file_writer_'s default log base directory getter to always // Override file_writer_'s default log base directory getter to always
// fail. // fail.
file_writer()->SetDefaultLogBaseDirectoryGetterForTest( file_writer()->SetDefaultLogBaseDirectoryGetterForTest(
base::Bind([](base::FilePath* path) -> bool { return false; })); base::BindRepeating([](base::FilePath* path) -> bool { return false; }));
// Initialization should fail due to the override. // Initialization should fail due to the override.
ASSERT_TRUE(InitializeThenVerifyNewState(false, false)); ASSERT_TRUE(InitializeThenVerifyNewState(false, false));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/values.h" #include "base/values.h"
#include "components/offline_pages/core/renovations/script_injector.h" #include "components/offline_pages/core/renovations/script_injector.h"
...@@ -74,12 +75,12 @@ PageRenovatorTest::~PageRenovatorTest() {} ...@@ -74,12 +75,12 @@ PageRenovatorTest::~PageRenovatorTest() {}
TEST_F(PageRenovatorTest, InjectsScript) { TEST_F(PageRenovatorTest, InjectsScript) {
EXPECT_FALSE(script_injector_inject_called_); EXPECT_FALSE(script_injector_inject_called_);
page_renovator_->RunRenovations(base::Closure()); page_renovator_->RunRenovations(base::NullCallback());
EXPECT_TRUE(script_injector_inject_called_); EXPECT_TRUE(script_injector_inject_called_);
} }
TEST_F(PageRenovatorTest, CallsCallback) { TEST_F(PageRenovatorTest, CallsCallback) {
base::MockCallback<base::Closure> mock_callback; base::MockCallback<base::OnceClosure> mock_callback;
EXPECT_CALL(mock_callback, Run()).Times(1); EXPECT_CALL(mock_callback, Run()).Times(1);
page_renovator_->RunRenovations(mock_callback.Get()); page_renovator_->RunRenovations(mock_callback.Get());
......
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