Skip to content

Commit

Permalink
Use OnceCallback on Mojo interfaces in //components/autofill
Browse files Browse the repository at this point in the history
This CL flips `use_once_calback` flag on the Mojo code generator, and
fixes all compile errors after it. After this CL, Mojo interfaces in
//components/autofill starts using base::OnceCallback instead of
base::Callback on its return value handling.

The migration recipe was:
 - Convert pass-by-ref callback objects to pass-by-value.
 - Use std::move() to forward it to other consumer, or to invoke it
   with Callback::Run().
 - Handle wherever copies are required manually.
 - Check if the conversion doesn't change the semantics. As the transfer
   and invocation clobber the callback object, care about use-after-move.
   It's considered safe to consume almost scoped-out callback.

BUG=714018

Review-Url: https://codereview.chromium.org/2869673002
Cr-Commit-Position: refs/heads/master@{#471170}
  • Loading branch information
tzik authored and Commit bot committed May 12, 2017
1 parent 068131a commit 4772a01
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class FakePasswordAutofillAgent
const autofill::FormsPredictionsMap& predictions) override {}

void FindFocusedPasswordForm(
const FindFocusedPasswordFormCallback& callback) override {}
FindFocusedPasswordFormCallback callback) override {}

// Records whether SetLoggingState() gets called.
bool called_set_logging_state_;
Expand Down
6 changes: 0 additions & 6 deletions components/autofill/content/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ mojom("mojo_interfaces") {
"//ui/gfx/geometry/mojo",
"//url/mojo:url_mojom_gurl",
]

# TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
use_once_callback = false
}

mojom("mojo_types") {
Expand All @@ -55,9 +52,6 @@ mojom("mojo_test_types") {
public_deps = [
":mojo_types",
]

# TODO(crbug.com/714018): Convert the implementation to use OnceCallback.
use_once_callback = false
}

source_set("unit_tests") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -208,49 +210,48 @@ class AutofillTypeTraitsTestImpl : public testing::Test,
}

// mojom::TypeTraitsTest:
void PassFormData(const FormData& s,
const PassFormDataCallback& callback) override {
callback.Run(s);
void PassFormData(const FormData& s, PassFormDataCallback callback) override {
std::move(callback).Run(s);
}

void PassFormFieldData(const FormFieldData& s,
const PassFormFieldDataCallback& callback) override {
callback.Run(s);
PassFormFieldDataCallback callback) override {
std::move(callback).Run(s);
}

void PassFormDataPredictions(
const FormDataPredictions& s,
const PassFormDataPredictionsCallback& callback) override {
callback.Run(s);
PassFormDataPredictionsCallback callback) override {
std::move(callback).Run(s);
}

void PassFormFieldDataPredictions(
const FormFieldDataPredictions& s,
const PassFormFieldDataPredictionsCallback& callback) override {
callback.Run(s);
PassFormFieldDataPredictionsCallback callback) override {
std::move(callback).Run(s);
}

void PassPasswordFormFillData(
const PasswordFormFillData& s,
const PassPasswordFormFillDataCallback& callback) override {
callback.Run(s);
PassPasswordFormFillDataCallback callback) override {
std::move(callback).Run(s);
}

void PassPasswordFormGenerationData(
const PasswordFormGenerationData& s,
const PassPasswordFormGenerationDataCallback& callback) override {
callback.Run(s);
PassPasswordFormGenerationDataCallback callback) override {
std::move(callback).Run(s);
}

void PassPasswordForm(const PasswordForm& s,
const PassPasswordFormCallback& callback) override {
callback.Run(s);
PassPasswordFormCallback callback) override {
std::move(callback).Run(s);
}

void PassFormsPredictionsMap(
const FormsPredictionsMap& s,
const PassFormsPredictionsMapCallback& callback) override {
callback.Run(s);
PassFormsPredictionsMapCallback callback) override {
std::move(callback).Run(s);
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ void PasswordAutofillAgent::AutofillUsernameAndPasswordDataReceived(
}

void PasswordAutofillAgent::FindFocusedPasswordForm(
const FindFocusedPasswordFormCallback& callback) {
FindFocusedPasswordFormCallback callback) {
std::unique_ptr<PasswordForm> password_form;

blink::WebElement element =
Expand Down Expand Up @@ -1577,7 +1577,7 @@ void PasswordAutofillAgent::FindFocusedPasswordForm(

password_form->submission_event =
PasswordForm::SubmissionIndicatorEvent::MANUAL_SAVE;
callback.Run(*password_form);
std::move(callback).Run(*password_form);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
void AutofillUsernameAndPasswordDataReceived(
const FormsPredictionsMap& predictions) override;
void FindFocusedPasswordForm(
const FindFocusedPasswordFormCallback& callback) override;
FindFocusedPasswordFormCallback callback) override;

// WebFrameClient editor related calls forwarded by AutofillAgent.
// If they return true, it indicates the event was consumed and should not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class FakePasswordAutofillAgent
const autofill::FormsPredictionsMap& predictions) override {}

void FindFocusedPasswordForm(
const FindFocusedPasswordFormCallback& callback) override {}
FindFocusedPasswordFormCallback callback) override {}

// Records whether SetLoggingState() gets called.
bool called_set_logging_state_;
Expand Down

0 comments on commit 4772a01

Please sign in to comment.