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