Commit b5830c31 authored by Renjie Tang's avatar Renjie Tang Committed by Commit Bot

In ios/chrome, migrate CallBack and Closure to Once/Repeating.

Bug:1007792

Change-Id: I5d8f3167fcb4db996258f4e2ce91b29f45eb6737
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518117
Commit-Queue: Renjie Tang <renjietang@chromium.org>
Auto-Submit: Renjie Tang <renjietang@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824506}
parent a284c2cf
......@@ -103,7 +103,7 @@ class ChromeBrowserState : public web::BrowserState {
// Be aware that theoretically it is possible that |completion| will be
// invoked after the Profile instance has been destroyed.
virtual void ClearNetworkingHistorySince(base::Time time,
const base::Closure& completion) = 0;
base::OnceClosure completion) = 0;
// Returns an identifier of the browser state for debugging.
std::string GetDebugName();
......
......@@ -219,8 +219,8 @@ net::URLRequestContextGetter* ChromeBrowserStateImpl::CreateRequestContext(
void ChromeBrowserStateImpl::ClearNetworkingHistorySince(
base::Time time,
const base::Closure& completion) {
io_data_->ClearNetworkingHistorySince(time, completion);
base::OnceClosure completion) {
io_data_->ClearNetworkingHistorySince(time, std::move(completion));
}
PrefProxyConfigTracker* ChromeBrowserStateImpl::GetProxyConfigTracker() {
......
......@@ -42,7 +42,7 @@ class ChromeBrowserStateImpl : public ChromeBrowserState {
PrefService* GetOffTheRecordPrefs() override;
ChromeBrowserStateIOData* GetIOData() override;
void ClearNetworkingHistorySince(base::Time time,
const base::Closure& completion) override;
base::OnceClosure completion) override;
net::URLRequestContextGetter* CreateRequestContext(
ProtocolHandlerMap* protocol_handlers) override;
......
......@@ -53,7 +53,7 @@ class ChromeBrowserStateImplIOData : public ChromeBrowserStateIOData {
// Works asynchronously, however if the |completion| callback is non-null,
// it will be posted on the UI thread once the removal process completes.
void ClearNetworkingHistorySince(base::Time time,
const base::Closure& completion);
base::OnceClosure completion);
private:
typedef std::map<base::FilePath,
......@@ -113,7 +113,7 @@ class ChromeBrowserStateImplIOData : public ChromeBrowserStateIOData {
// Works asynchronously, however if the |completion| callback is non-null,
// it will be posted on the UI thread once the removal process completes.
void ClearNetworkingHistorySinceOnIOThread(base::Time time,
const base::Closure& completion);
base::OnceClosure completion);
mutable std::unique_ptr<IOSChromeNetworkDelegate> network_delegate_;
......
......@@ -104,7 +104,7 @@ ChromeBrowserStateIOData* ChromeBrowserStateImplIOData::Handle::io_data()
void ChromeBrowserStateImplIOData::Handle::ClearNetworkingHistorySince(
base::Time time,
const base::Closure& completion) {
base::OnceClosure completion) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
LazyInitialize();
......@@ -112,7 +112,7 @@ void ChromeBrowserStateImplIOData::Handle::ClearNetworkingHistorySince(
FROM_HERE, {web::WebThread::IO},
base::BindOnce(
&ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread,
base::Unretained(io_data_), time, completion));
base::Unretained(io_data_), time, std::move(completion)));
}
void ChromeBrowserStateImplIOData::Handle::LazyInitialize() const {
......@@ -234,15 +234,15 @@ void ChromeBrowserStateImplIOData::InitializeInternal(
void ChromeBrowserStateImplIOData::ClearNetworkingHistorySinceOnIOThread(
base::Time time,
const base::Closure& completion) {
base::OnceClosure completion) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
DCHECK(initialized());
DCHECK(transport_security_state());
auto barrier = base::BarrierClosure(
2, base::BindOnce(
[](base::Closure completion) {
[](base::OnceClosure callback) {
base::PostTask(FROM_HERE, base::TaskTraits(web::WebThread::UI),
std::move(completion));
std::move(callback));
},
std::move(completion)));
......
......@@ -116,12 +116,12 @@ OffTheRecordChromeBrowserStateImpl::CreateRequestContext(
void OffTheRecordChromeBrowserStateImpl::ClearNetworkingHistorySince(
base::Time time,
const base::Closure& completion) {
base::OnceClosure completion) {
// Nothing to do here, our transport security state is read-only.
// Still, fire the callback to indicate we have finished, otherwise the
// BrowsingDataRemover will never be destroyed and the dialog will never be
// closed. We must do this asynchronously in order to avoid reentrancy issues.
if (!completion.is_null()) {
base::PostTask(FROM_HERE, {web::WebThread::UI}, completion);
base::PostTask(FROM_HERE, {web::WebThread::UI}, std::move(completion));
}
}
......@@ -31,7 +31,7 @@ class OffTheRecordChromeBrowserStateImpl : public ChromeBrowserState {
PrefService* GetOffTheRecordPrefs() override;
ChromeBrowserStateIOData* GetIOData() override;
void ClearNetworkingHistorySince(base::Time time,
const base::Closure& completion) override;
base::OnceClosure completion) override;
net::URLRequestContextGetter* CreateRequestContext(
ProtocolHandlerMap* protocol_handlers) override;
......
......@@ -53,7 +53,7 @@ class TestChromeBrowserState : public ChromeBrowserState {
PrefService* GetOffTheRecordPrefs() override;
ChromeBrowserStateIOData* GetIOData() override;
void ClearNetworkingHistorySince(base::Time time,
const base::Closure& completion) override;
base::OnceClosure completion) override;
net::URLRequestContextGetter* CreateRequestContext(
ProtocolHandlerMap* protocol_handlers) override;
......
......@@ -255,9 +255,9 @@ ChromeBrowserStateIOData* TestChromeBrowserState::GetIOData() {
void TestChromeBrowserState::ClearNetworkingHistorySince(
base::Time time,
const base::Closure& completion) {
base::OnceClosure completion) {
if (!completion.is_null())
completion.Run();
std::move(completion).Run();
}
net::URLRequestContextGetter* TestChromeBrowserState::CreateRequestContext(
......
......@@ -23,8 +23,10 @@ DistillerViewer::DistillerViewer(
dom_distiller::DomDistillerService* distillerService,
PrefService* prefs,
const GURL& url,
const DistillationFinishedCallback& callback)
: DistillerViewerInterface(prefs), url_(url), callback_(callback) {
DistillationFinishedCallback callback)
: DistillerViewerInterface(prefs),
url_(url),
callback_(std::move(callback)) {
DCHECK(distillerService);
DCHECK(url.is_valid());
std::unique_ptr<dom_distiller::DistillerPage> page =
......@@ -40,8 +42,10 @@ DistillerViewer::DistillerViewer(
std::unique_ptr<dom_distiller::DistillerPage> page,
PrefService* prefs,
const GURL& url,
const DistillationFinishedCallback& callback)
: DistillerViewerInterface(prefs), url_(url), callback_(callback) {
DistillationFinishedCallback callback)
: DistillerViewerInterface(prefs),
url_(url),
callback_(std::move(callback)) {
DCHECK(url.is_valid());
SendCommonJavaScript();
distiller_ = distiller_factory->CreateDistillerForUrl(url);
......@@ -65,6 +69,7 @@ void DistillerViewer::OnDistillerFinished(
void DistillerViewer::OnArticleReady(
const dom_distiller::DistilledArticleProto* article_proto) {
DCHECK(!callback_.is_null());
DomDistillerRequestViewBase::OnArticleReady(article_proto);
bool is_empty = article_proto->pages_size() == 0 ||
article_proto->pages(0).html().empty();
......@@ -83,9 +88,10 @@ void DistillerViewer::OnArticleReady(
std::string html_and_script(html);
html_and_script +=
"<script> distillerOnIos = true; " + js_buffer_ + "</script>";
callback_.Run(url_, html_and_script, images, article_proto->title());
std::move(callback_).Run(url_, html_and_script, images,
article_proto->title());
} else {
callback_.Run(url_, std::string(), {}, std::string());
std::move(callback_).Run(url_, std::string(), {}, std::string());
}
}
......
......@@ -30,11 +30,11 @@ class DistillerViewerInterface : public DomDistillerRequestViewBase {
// The image data as a string.
std::string data;
};
typedef base::Callback<void(const GURL& url,
using DistillationFinishedCallback =
base::OnceCallback<void(const GURL& url,
const std::string& html,
const std::vector<ImageInfo>& images,
const std::string& title)>
DistillationFinishedCallback;
const std::string& title)>;
DistillerViewerInterface(PrefService* prefs)
: DomDistillerRequestViewBase(new DistilledPagePrefs(prefs)) {}
......@@ -57,7 +57,7 @@ class DistillerViewer : public DistillerViewerInterface {
DistillerViewer(dom_distiller::DomDistillerService* distillerService,
PrefService* prefs,
const GURL& url,
const DistillationFinishedCallback& callback);
DistillationFinishedCallback callback);
// Creates a |DistillerView| without depending on the DomDistillerService.
// Caller must provide |distiller_factory| and |page| which cannot be null.
......@@ -67,7 +67,7 @@ class DistillerViewer : public DistillerViewerInterface {
std::unique_ptr<dom_distiller::DistillerPage> page,
PrefService* prefs,
const GURL& url,
const DistillationFinishedCallback& callback);
DistillationFinishedCallback callback);
~DistillerViewer() override;
// DistillerViewerInterface implementation
......@@ -91,7 +91,7 @@ class DistillerViewer : public DistillerViewerInterface {
// JavaScript buffer.
std::string js_buffer_;
// Callback to run once distillation is complete.
const DistillationFinishedCallback callback_;
DistillationFinishedCallback callback_;
// Keep reference of the distiller_ during distillation.
std::unique_ptr<Distiller> distiller_;
......
......@@ -17,7 +17,7 @@ TEST(InProcessJsonParserTest, TestSuccess) {
InProcessJsonParser::Parse(
R"json({"key": 1})json",
base::BindOnce(
[](base::Closure quit_closure, base::Value value) {
[](base::OnceClosure quit_closure, base::Value value) {
ASSERT_TRUE(value.is_dict());
ASSERT_TRUE(value.FindIntKey("key"));
EXPECT_EQ(1, *value.FindIntKey("key"));
......@@ -25,7 +25,7 @@ TEST(InProcessJsonParserTest, TestSuccess) {
},
run_loop.QuitClosure()),
base::BindOnce(
[](base::Closure quit_closure, const std::string& error) {
[](base::OnceClosure quit_closure, const std::string& error) {
EXPECT_FALSE(true) << "unexpected json parse error: " << error;
std::move(quit_closure).Run();
},
......@@ -40,13 +40,13 @@ TEST(InProcessJsonParserTest, TestFailure) {
InProcessJsonParser::Parse(
R"json(invalid)json",
base::BindOnce(
[](base::Closure quit_closure, base::Value value) {
[](base::OnceClosure quit_closure, base::Value value) {
EXPECT_FALSE(true) << "unexpected json parse success: " << value;
std::move(quit_closure).Run();
},
run_loop.QuitClosure()),
base::BindOnce(
[](base::Closure quit_closure, const std::string& error) {
[](base::OnceClosure quit_closure, const std::string& error) {
EXPECT_TRUE(!error.empty());
std::move(quit_closure).Run();
},
......
......@@ -154,9 +154,6 @@ class IOSChromeMetricsServiceClient : public IncognitoWebStateObserver,
// Saved callback received from CollectFinalMetricsForLog().
base::OnceClosure collect_final_metrics_done_callback_;
// Callback that is called when initial metrics gathering is complete.
base::Closure finished_init_task_callback_;
// Subscription for receiving callbacks that a tab was parented.
std::unique_ptr<base::CallbackList<void(web::WebState*)>::Subscription>
tab_parented_subscription_;
......
......@@ -74,7 +74,7 @@ IOSChromePasswordManagerClient::IOSChromePasswordManagerClient(
log_manager_ = autofill::LogManager::Create(
ios::PasswordManagerLogRouterFactory::GetForBrowserState(
bridge_.browserState),
base::Closure());
base::RepeatingClosure());
}
IOSChromePasswordManagerClient::~IOSChromePasswordManagerClient() = default;
......
......@@ -55,7 +55,7 @@
.get();
// Remove credentials stored during executing the test.
passwordStore->RemoveLoginsCreatedBetween(base::Time(), base::Time::Now(),
base::Closure());
base::OnceClosure());
}
+ (void)getCredentialsInTabAtIndex:(int)index {
......
......@@ -43,8 +43,6 @@ class ReadingListDistillerPageDelegate {
// and add a 2 seconds delay between loading and distillation.
class ReadingListDistillerPage : public dom_distiller::DistillerPageIOS {
public:
typedef base::Callback<void(const GURL&, const GURL&)> RedirectionCallback;
// Creates a ReadingListDistillerPage to distill |url|. WebStates to download
// the pages will be provided by web_state_dispatcher.
// |browser_state|, |web_state_dispatcher| and |delegate| must not be null.
......
......@@ -32,7 +32,7 @@ namespace {
class DistillerViewerTest : public dom_distiller::DistillerViewerInterface {
public:
DistillerViewerTest(const GURL& url,
const DistillationFinishedCallback& callback,
DistillationFinishedCallback callback,
reading_list::ReadingListDistillerPageDelegate* delegate,
const std::string& html,
const GURL& redirect_url,
......@@ -50,7 +50,7 @@ class DistillerViewerTest : public dom_distiller::DistillerViewerInterface {
if (!mime_type.empty()) {
delegate->DistilledPageHasMimeType(url, mime_type);
}
callback.Run(url, html, images, "title");
std::move(callback).Run(url, html, images, "title");
}
void OnArticleReady(
......
......@@ -33,7 +33,7 @@ base::RepeatingClosure GetDefaultSearchProviderChangedCallback() {
base::IgnoreResult(&rlz::RLZTracker::RecordProductEvent), rlz_lib::CHROME,
rlz::RLZTracker::ChromeOmnibox(), rlz_lib::SET_TO_GOOGLE);
#else
return base::Closure();
return base::RepeatingClosure();
#endif
}
......
......@@ -20,7 +20,7 @@ class WebState;
// the TAB_PARENTED notification from all sources.
class TabParentingGlobalObserver {
public:
typedef base::Callback<void(web::WebState*)> OnTabParentedCallback;
using OnTabParentedCallback = base::RepeatingCallback<void(web::WebState*)>;
// Returns the instance of TabParentingGlobalObserver.
static TabParentingGlobalObserver* GetInstance();
......
......@@ -139,7 +139,7 @@ void SaveLocalPasswordForm(const GURL& url) {
// Removes all credentials stored.
void ClearPasswordStore() {
GetPasswordStore()->RemoveLoginsCreatedBetween(base::Time(), base::Time(),
base::Closure());
base::OnceClosure());
TestStoreConsumer consumer;
}
......
......@@ -122,7 +122,7 @@ ChromeAutofillClientIOS::ChromeAutofillClientIOS(
// renderer.
log_manager_(LogManager::Create(
AutofillLogRouterFactory::GetForBrowserState(browser_state),
base::Closure())) {}
base::RepeatingClosure())) {}
ChromeAutofillClientIOS::~ChromeAutofillClientIOS() {
HideAutofillPopup(PopupHidingReason::kTabGone);
......
......@@ -45,11 +45,9 @@ class ChromeOmniboxClientIOS : public OmniboxClient {
OmniboxNavigationObserver* observer) override;
void OnFocusChanged(OmniboxFocusState state,
OmniboxFocusChangeReason reason) override;
void OnResultChanged(
const AutocompleteResult& result,
bool default_match_changed,
const base::Callback<void(int result_index, const SkBitmap& bitmap)>&
on_bitmap_fetched) override;
void OnResultChanged(const AutocompleteResult& result,
bool default_match_changed,
const BitmapFetchedCallback& on_bitmap_fetched) override;
void DiscardNonCommittedNavigations() override;
const base::string16& GetTitle() const override;
gfx::Image GetFavicon() const override;
......
......@@ -133,8 +133,7 @@ void ChromeOmniboxClientIOS::OnFocusChanged(OmniboxFocusState state,
void ChromeOmniboxClientIOS::OnResultChanged(
const AutocompleteResult& result,
bool default_match_changed,
const base::Callback<void(int result_index, const SkBitmap& bitmap)>&
on_bitmap_fetched) {
const BitmapFetchedCallback& on_bitmap_fetched) {
if (result.empty()) {
return;
}
......
......@@ -130,7 +130,7 @@ PasswordForm CreateSampleFormWithIndex(int index) {
bool ClearPasswordStore() {
GetPasswordStore()->RemoveLoginsCreatedBetween(base::Time(), base::Time(),
base::Closure());
base::OnceClosure());
FakeStoreConsumer consumer;
if (!consumer.FetchStoreResults()) {
return false;
......
......@@ -61,9 +61,9 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Sets up the EmbeddedTestServer as needed for tests.
- (void)setUpTestServer {
self.testServer->RegisterDefaultHandler(
base::Bind(net::test_server::HandlePrefixedRequest, "/querytitle",
base::Bind(&HandleQueryTitle)));
self.testServer->RegisterDefaultHandler(base::BindRepeating(
net::test_server::HandlePrefixedRequest, "/querytitle",
base::BindRepeating(&HandleQueryTitle)));
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start");
}
......
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