Commit 8c66c243 authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

Extensions: Store and use RunLoop::QuitClosure as OnceClosure.

It won't be necessary to call base::ResetAndReturn. Use std::move
to Run() those closures instead.

Bug: 812717
Change-Id: Ie8956bfcb23e3411025352d4714a9c928c0869fe
Reviewed-on: https://chromium-review.googlesource.com/920742
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537349}
parent 859bc0e6
......@@ -82,7 +82,7 @@ class ExtensionInfoGeneratorUnitTest : public ExtensionServiceTestBase {
EXPECT_EQ(1u, list.size());
if (!list.empty())
info_out->reset(new developer::ExtensionInfo(std::move(list[0])));
base::ResetAndReturn(&quit_closure_).Run();
std::move(quit_closure_).Run();
}
std::unique_ptr<developer::ExtensionInfo> GenerateExtensionInfo(
......@@ -103,7 +103,7 @@ class ExtensionInfoGeneratorUnitTest : public ExtensionServiceTestBase {
void OnInfosGenerated(ExtensionInfoGenerator::ExtensionInfoList* out,
ExtensionInfoGenerator::ExtensionInfoList list) {
*out = std::move(list);
base::ResetAndReturn(&quit_closure_).Run();
std::move(quit_closure_).Run();
}
ExtensionInfoGenerator::ExtensionInfoList GenerateExtensionsInfo() {
......@@ -204,7 +204,7 @@ class ExtensionInfoGeneratorUnitTest : public ExtensionServiceTestBase {
}
private:
base::Closure quit_closure_;
base::OnceClosure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(ExtensionInfoGeneratorUnitTest);
};
......
......@@ -293,7 +293,6 @@ class TestExternalProvider : public ExternalProviderInterface {
private:
VisitorInterface* visitor_;
ExtensionId extension_id_;
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(TestExternalProvider);
};
......
......@@ -4,13 +4,16 @@
#include "chrome/browser/extensions/extension_install_prompt_test_helper.h"
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
ExtensionInstallPromptTestHelper::ExtensionInstallPromptTestHelper() {}
ExtensionInstallPromptTestHelper::ExtensionInstallPromptTestHelper(
const base::Closure& quit_closure) : quit_closure_(quit_closure) {}
base::OnceClosure quit_closure)
: quit_closure_(std::move(quit_closure)) {}
ExtensionInstallPromptTestHelper::~ExtensionInstallPromptTestHelper() {}
ExtensionInstallPrompt::DoneCallback
......@@ -32,7 +35,7 @@ void ExtensionInstallPromptTestHelper::HandleResult(
ExtensionInstallPrompt::Result result) {
if (result_.get())
ADD_FAILURE() << "HandleResult() called twice!";
if (!quit_closure_.is_null())
base::ResetAndReturn(&quit_closure_).Run();
if (quit_closure_)
std::move(quit_closure_).Run();
result_.reset(new ExtensionInstallPrompt::Result(result));
}
......@@ -13,7 +13,7 @@
class ExtensionInstallPromptTestHelper {
public:
ExtensionInstallPromptTestHelper();
explicit ExtensionInstallPromptTestHelper(const base::Closure& quit_closure);
explicit ExtensionInstallPromptTestHelper(base::OnceClosure quit_closure);
~ExtensionInstallPromptTestHelper();
// Returns a callback to be used with the ExtensionInstallPrompt.
......@@ -31,7 +31,7 @@ class ExtensionInstallPromptTestHelper {
// A closure to run once HandleResult() has been called; used for exiting
// run loops in tests.
base::Closure quit_closure_;
base::OnceClosure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(ExtensionInstallPromptTestHelper);
};
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/macros.h"
#include "base/run_loop.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
......@@ -67,8 +69,8 @@ class CallbackHelper {
// causes unit tests to crash), but rather runs the given |quit_closure| (with
// the prompt still active|.
ExtensionInstallPrompt::ShowDialogCallback CreateShowCallback(
const base::Closure& quit_closure) {
quit_closure_ = quit_closure;
base::OnceClosure quit_closure) {
quit_closure_ = std::move(quit_closure);
return base::Bind(&CallbackHelper::OnShow, base::Unretained(this));
}
......@@ -82,14 +84,13 @@ class CallbackHelper {
void OnShow(ExtensionInstallPromptShowParams* show_params,
const ExtensionInstallPrompt::DoneCallback& done_callback,
std::unique_ptr<ExtensionInstallPrompt::Prompt> prompt) {
DCHECK(!quit_closure_.is_null());
quit_closure_.Run();
quit_closure_ = base::Closure();
DCHECK(quit_closure_);
std::move(quit_closure_).Run();
}
// The closure to quit the currently-running loop; used with test
// ExtensionInstallPrompts.
base::Closure quit_closure_;
base::OnceClosure quit_closure_;
// The result of the reenable process, or null if the process hasn't finished.
std::unique_ptr<ExtensionReenabler::ReenableResult> result_;
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
......@@ -26,8 +28,8 @@ class DelayedRestartTestApiDelegate : public TestRuntimeAPIDelegate {
// TestRuntimeAPIDelegate:
bool RestartDevice(std::string* error_message) override {
if (!quit_closure_.is_null())
base::ResetAndReturn(&quit_closure_).Run();
if (quit_closure_)
std::move(quit_closure_).Run();
*error_message = "Success.";
restart_done_ = true;
......@@ -46,7 +48,7 @@ class DelayedRestartTestApiDelegate : public TestRuntimeAPIDelegate {
}
private:
base::Closure quit_closure_;
base::OnceClosure quit_closure_;
bool restart_done_ = false;
......
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