diff options
author | gab <gab@chromium.org> | 2014-12-08 13:54:09 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-08 21:54:30 +0000 |
commit | ce7cfee334855215412460f91fd4d0f29b5e4afb (patch) | |
tree | 622bd71263d1f5e7e9081d180147d3a1938bb437 | |
parent | 6b150518257d898af57991939f9481bc3e95b5e7 (diff) | |
download | chromium_src-ce7cfee334855215412460f91fd4d0f29b5e4afb.zip chromium_src-ce7cfee334855215412460f91fd4d0f29b5e4afb.tar.gz chromium_src-ce7cfee334855215412460f91fd4d0f29b5e4afb.tar.bz2 |
Revert of Revert of Don't deref stale AutofillMetrics pointer in AutofillCCInfoBarDelegate (patchset #1 id:1 of https://codereview.chromium.org/790543002/)
Reason for revert:
Re-landing, revert didn't fix Win7 bots..
Original issue's description:
> Revert of Don't deref stale AutofillMetrics pointer in AutofillCCInfoBarDelegate (patchset #2 id:20001 of https://codereview.chromium.org/780423002/)
>
> Reason for revert:
> Suspected cause of flakines on Win7-bots, see http://crbug.com/440060 for details.
>
> Original issue's description:
> > Don't deref stale AutofillMetrics pointer in AutofillCCInfoBarDelegate
> >
> > It was only by luck that this used to work. After a recent refactoring, the destruction order changed and the AutofillMetrics object no longer outlasts the infobar. AutofillMetrics doesn't need to be an instance object; make the relevant function a static instead.
> >
> > TBR=sgurun@chromium.org
> > BUG=439551, 439620
> >
> > Committed: https://crrev.com/19ece1e4af5207b92c2152395dfccca1683504e1
> > Cr-Commit-Position: refs/heads/master@{#307128}
>
> TBR=isherman@chromium.org,pkasting@chromium.org,estade@chromium.org
> NOTREECHECKS=true
> NOTRY=true
> BUG=439551, 439620
>
> Committed: https://crrev.com/051aca46ed1dec4f040c9a3d7dac2af60df2db6c
> Cr-Commit-Position: refs/heads/master@{#307303}
TBR=isherman@chromium.org,pkasting@chromium.org,estade@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=439551, 439620, 440060
Review URL: https://codereview.chromium.org/782353002
Cr-Commit-Position: refs/heads/master@{#307345}
13 files changed, 43 insertions, 82 deletions
diff --git a/android_webview/native/aw_autofill_client.cc b/android_webview/native/aw_autofill_client.cc index 95f3fd5..de1d1ef 100644 --- a/android_webview/native/aw_autofill_client.cc +++ b/android_webview/native/aw_autofill_client.cc @@ -188,7 +188,6 @@ void AwAutofillClient::ShowAutofillSettings() { } void AwAutofillClient::ConfirmSaveCreditCard( - const autofill::AutofillMetrics& metric_logger, const base::Closure& save_card_callback) { NOTIMPLEMENTED(); } diff --git a/android_webview/native/aw_autofill_client.h b/android_webview/native/aw_autofill_client.h index c328d56..96a86e1 100644 --- a/android_webview/native/aw_autofill_client.h +++ b/android_webview/native/aw_autofill_client.h @@ -62,7 +62,6 @@ class AwAutofillClient : public autofill::AutofillClient, virtual void HideRequestAutocompleteDialog() override; virtual void ShowAutofillSettings() override; virtual void ConfirmSaveCreditCard( - const autofill::AutofillMetrics& metric_logger, const base::Closure& save_card_callback) override; virtual bool HasCreditCardScanFeature() override; virtual void ScanCreditCard(const CreditCardScanCallback& callback) override; diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc index f2fd9ea..a44a1b3 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc @@ -24,21 +24,18 @@ namespace autofill { // static void AutofillCCInfoBarDelegate::Create( InfoBarService* infobar_service, - const AutofillMetrics* metric_logger, const base::Closure& save_card_callback) { - infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( - scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate( - metric_logger, save_card_callback)))); + infobar_service->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new AutofillCCInfoBarDelegate(save_card_callback)))); } AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( - const AutofillMetrics* metric_logger, const base::Closure& save_card_callback) : ConfirmInfoBarDelegate(), - metric_logger_(metric_logger), save_card_callback_(save_card_callback), had_user_interaction_(false) { - metric_logger->LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); + AutofillMetrics::LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN); } AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() { @@ -50,7 +47,7 @@ void AutofillCCInfoBarDelegate::LogUserAction( AutofillMetrics::InfoBarMetric user_action) { DCHECK(!had_user_interaction_); - metric_logger_->LogCreditCardInfoBarMetric(user_action); + AutofillMetrics::LogCreditCardInfoBarMetric(user_action); had_user_interaction_ = true; } diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.h b/chrome/browser/autofill/autofill_cc_infobar_delegate.h index 2fd4e79..717cd90 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate.h +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.h @@ -27,21 +27,18 @@ class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { // Creates an autofill credit card infobar and delegate and adds the infobar // to |infobar_service|. static void Create(InfoBarService* infobar_service, - const AutofillMetrics* metric_logger, const base::Closure& save_card_callback); #if defined(UNIT_TEST) static scoped_ptr<ConfirmInfoBarDelegate> Create( - const AutofillMetrics* metric_logger, const base::Closure& save_card_callback) { return scoped_ptr<ConfirmInfoBarDelegate>( - new AutofillCCInfoBarDelegate(metric_logger, save_card_callback)); + new AutofillCCInfoBarDelegate(save_card_callback)); } #endif private: - AutofillCCInfoBarDelegate(const AutofillMetrics* metric_logger, - const base::Closure& save_card_callback); + explicit AutofillCCInfoBarDelegate(const base::Closure& save_card_callback); ~AutofillCCInfoBarDelegate() override; void LogUserAction(AutofillMetrics::InfoBarMetric user_action); @@ -58,10 +55,6 @@ class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { base::string16 GetLinkText() const override; bool LinkClicked(WindowOpenDisposition disposition) override; - // For logging UMA metrics. - // Weak reference. Owned by the AutofillManager that initiated this infobar. - const AutofillMetrics* metric_logger_; - // The callback to save credit card if the user accepts the infobar. base::Closure save_card_callback_; diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc index 2b5e9a4..3aa5b17 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate_unittest.cc @@ -5,11 +5,11 @@ #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" #include "base/memory/scoped_ptr.h" +#include "base/test/histogram_tester.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/ui/autofill/chrome_autofill_client.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" -#include "components/autofill/core/browser/autofill_metrics.h" #include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/personal_data_manager.h" #include "testing/gmock/include/gmock/gmock.h" @@ -21,15 +21,6 @@ namespace autofill { namespace { -class MockAutofillMetrics : public AutofillMetrics { - public: - MockAutofillMetrics() {} - MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); -}; - class TestPersonalDataManager : public PersonalDataManager { public: TestPersonalDataManager() : PersonalDataManager("en-US") {} @@ -58,8 +49,7 @@ class AutofillCCInfobarDelegateTest : public ChromeRenderViewHostTestHarness { void TearDown() override; protected: - scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( - MockAutofillMetrics* metric_logger); + scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(); scoped_ptr<TestPersonalDataManager> personal_data_; }; @@ -89,72 +79,61 @@ void AutofillCCInfobarDelegateTest::TearDown() { } scoped_ptr<ConfirmInfoBarDelegate> -AutofillCCInfobarDelegateTest::CreateDelegate( - MockAutofillMetrics* metric_logger) { - EXPECT_CALL(*metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); - +AutofillCCInfobarDelegateTest::CreateDelegate() { + base::HistogramTester histogram_tester; CreditCard credit_card; - return AutofillCCInfoBarDelegate::Create( - metric_logger, - base::Bind( + scoped_ptr<ConfirmInfoBarDelegate> delegate( + AutofillCCInfoBarDelegate::Create(base::Bind( base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), - base::Unretained(personal_data_.get()), - credit_card)); + base::Unretained(personal_data_.get()), credit_card))); + histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", + AutofillMetrics::INFOBAR_SHOWN, 1); + return delegate.Pass(); } // Test that credit card infobar metrics are logged correctly. TEST_F(AutofillCCInfobarDelegateTest, Metrics) { - MockAutofillMetrics metric_logger; ::testing::InSequence dummy; // Accept the infobar. { - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); - ASSERT_TRUE(infobar); + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) - .Times(0); + base::HistogramTester histogram_tester; EXPECT_TRUE(infobar->Accept()); + histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", + AutofillMetrics::INFOBAR_ACCEPTED, 1); } // Cancel the infobar. { - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); - ASSERT_TRUE(infobar); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)) - .Times(1); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) - .Times(0); + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); + + base::HistogramTester histogram_tester; EXPECT_TRUE(infobar->Cancel()); + histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", + AutofillMetrics::INFOBAR_DENIED, 1); } // Dismiss the infobar. { - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); - ASSERT_TRUE(infobar); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)) - .Times(1); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) - .Times(0); + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); + + base::HistogramTester histogram_tester; infobar->InfoBarDismissed(); + histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", + AutofillMetrics::INFOBAR_DENIED, 1); } // Ignore the infobar. { - scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); - ASSERT_TRUE(infobar); - EXPECT_CALL(metric_logger, - LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) - .Times(1); + scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate()); + + base::HistogramTester histogram_tester; + infobar.reset(); + histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar", + AutofillMetrics::INFOBAR_IGNORED, 1); } } diff --git a/chrome/browser/ui/autofill/chrome_autofill_client.cc b/chrome/browser/ui/autofill/chrome_autofill_client.cc index 5aa836c..7fad809 100644 --- a/chrome/browser/ui/autofill/chrome_autofill_client.cc +++ b/chrome/browser/ui/autofill/chrome_autofill_client.cc @@ -107,12 +107,10 @@ void ChromeAutofillClient::ShowAutofillSettings() { } void ChromeAutofillClient::ConfirmSaveCreditCard( - const AutofillMetrics& metric_logger, const base::Closure& save_card_callback) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents_); - AutofillCCInfoBarDelegate::Create( - infobar_service, &metric_logger, save_card_callback); + AutofillCCInfoBarDelegate::Create(infobar_service, save_card_callback); } bool ChromeAutofillClient::HasCreditCardScanFeature() { diff --git a/chrome/browser/ui/autofill/chrome_autofill_client.h b/chrome/browser/ui/autofill/chrome_autofill_client.h index 772119c..9c43f42 100644 --- a/chrome/browser/ui/autofill/chrome_autofill_client.h +++ b/chrome/browser/ui/autofill/chrome_autofill_client.h @@ -46,8 +46,7 @@ class ChromeAutofillClient PrefService* GetPrefs() override; void HideRequestAutocompleteDialog() override; void ShowAutofillSettings() override; - void ConfirmSaveCreditCard(const AutofillMetrics& metric_logger, - const base::Closure& save_card_callback) override; + void ConfirmSaveCreditCard(const base::Closure& save_card_callback) override; bool HasCreditCardScanFeature() override; void ScanCreditCard(const CreditCardScanCallback& callback) override; void ShowRequestAutocompleteDialog(const FormData& form, diff --git a/components/autofill/core/browser/autofill_client.h b/components/autofill/core/browser/autofill_client.h index e99a28e..8cba62c 100644 --- a/components/autofill/core/browser/autofill_client.h +++ b/components/autofill/core/browser/autofill_client.h @@ -79,7 +79,6 @@ class AutofillClient { // Run |save_card_callback| if the credit card should be imported as personal // data. |metric_logger| can be used to log user actions. virtual void ConfirmSaveCreditCard( - const AutofillMetrics& metric_logger, const base::Closure& save_card_callback) = 0; // Returns true if both the platform and the device support scanning credit diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc index be7ce13..3a23c99 100644 --- a/components/autofill/core/browser/autofill_manager.cc +++ b/components/autofill/core/browser/autofill_manager.cc @@ -707,7 +707,6 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) { // save it. if (imported_credit_card) { client_->ConfirmSaveCreditCard( - *metric_logger_, base::Bind( base::IgnoreResult(&PersonalDataManager::SaveImportedCreditCard), base::Unretained(personal_data_), diff --git a/components/autofill/core/browser/autofill_metrics.cc b/components/autofill/core/browser/autofill_metrics.cc index c3a271a..b1ea0d9 100644 --- a/components/autofill/core/browser/autofill_metrics.cc +++ b/components/autofill/core/browser/autofill_metrics.cc @@ -265,7 +265,8 @@ AutofillMetrics::AutofillMetrics() { AutofillMetrics::~AutofillMetrics() { } -void AutofillMetrics::LogCreditCardInfoBarMetric(InfoBarMetric metric) const { +// static +void AutofillMetrics::LogCreditCardInfoBarMetric(InfoBarMetric metric) { DCHECK_LT(metric, NUM_INFO_BAR_METRICS); UMA_HISTOGRAM_ENUMERATION("Autofill.CreditCardInfoBar", metric, NUM_INFO_BAR_METRICS); diff --git a/components/autofill/core/browser/autofill_metrics.h b/components/autofill/core/browser/autofill_metrics.h index 68fb824..b02d339 100644 --- a/components/autofill/core/browser/autofill_metrics.h +++ b/components/autofill/core/browser/autofill_metrics.h @@ -310,7 +310,7 @@ class AutofillMetrics { AutofillMetrics(); virtual ~AutofillMetrics(); - virtual void LogCreditCardInfoBarMetric(InfoBarMetric metric) const; + static void LogCreditCardInfoBarMetric(InfoBarMetric metric); virtual void LogDeveloperEngagementMetric( DeveloperEngagementMetric metric) const; diff --git a/components/autofill/core/browser/test_autofill_client.cc b/components/autofill/core/browser/test_autofill_client.cc index 53adfd8..dec427b 100644 --- a/components/autofill/core/browser/test_autofill_client.cc +++ b/components/autofill/core/browser/test_autofill_client.cc @@ -32,7 +32,6 @@ void TestAutofillClient::ShowAutofillSettings() { } void TestAutofillClient::ConfirmSaveCreditCard( - const AutofillMetrics& metric_logger, const base::Closure& save_card_callback) { } diff --git a/components/autofill/core/browser/test_autofill_client.h b/components/autofill/core/browser/test_autofill_client.h index 5266d8b..ed0290a 100644 --- a/components/autofill/core/browser/test_autofill_client.h +++ b/components/autofill/core/browser/test_autofill_client.h @@ -25,8 +25,7 @@ class TestAutofillClient : public AutofillClient { PrefService* GetPrefs() override; void HideRequestAutocompleteDialog() override; void ShowAutofillSettings() override; - void ConfirmSaveCreditCard(const AutofillMetrics& metric_logger, - const base::Closure& save_card_callback) override; + void ConfirmSaveCreditCard(const base::Closure& save_card_callback) override; bool HasCreditCardScanFeature() override; void ScanCreditCard(const CreditCardScanCallback& callback) override; void ShowRequestAutocompleteDialog(const FormData& form, |