diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-01 03:56:01 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-01 03:56:01 +0000 |
commit | e2c66c328e40b7d84b104c12074e5d84c15e308d (patch) | |
tree | 3527ba18749322a8f4eb481bc5a94745c00198fe /chrome | |
parent | caf167dc928373bc9e7316088a383ddea9ecded1 (diff) | |
download | chromium_src-e2c66c328e40b7d84b104c12074e5d84c15e308d.zip chromium_src-e2c66c328e40b7d84b104c12074e5d84c15e308d.tar.gz chromium_src-e2c66c328e40b7d84b104c12074e5d84c15e308d.tar.bz2 |
Add UMA metric for number of autofill profiles
BUG=73933
TEST=unit_tests --gtest_filter=AutoFillMetricsTest.ProfileCount
Review URL: http://codereview.chromium.org/6574022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76352 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autofill/autofill_metrics.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_metrics.h | 3 | ||||
-rw-r--r-- | chrome/browser/autofill/autofill_metrics_unittest.cc | 65 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.cc | 32 | ||||
-rw-r--r-- | chrome/browser/autofill/personal_data_manager.h | 16 |
5 files changed, 108 insertions, 12 deletions
diff --git a/chrome/browser/autofill/autofill_metrics.cc b/chrome/browser/autofill/autofill_metrics.cc index 713d8a3..bf6adfd 100644 --- a/chrome/browser/autofill/autofill_metrics.cc +++ b/chrome/browser/autofill/autofill_metrics.cc @@ -29,3 +29,7 @@ void AutofillMetrics::Log(QualityMetric metric, UMA_HISTOGRAM_ENUMERATION(histogram_name, metric, NUM_QUALITY_METRICS); } + +void AutofillMetrics::LogProfileCount(size_t num_profiles) const { + UMA_HISTOGRAM_COUNTS("AutoFill.ProfileCount", num_profiles); +} diff --git a/chrome/browser/autofill/autofill_metrics.h b/chrome/browser/autofill/autofill_metrics.h index 8616f79..8251e75 100644 --- a/chrome/browser/autofill/autofill_metrics.h +++ b/chrome/browser/autofill/autofill_metrics.h @@ -64,6 +64,9 @@ class AutofillMetrics { virtual void Log(QualityMetric metric, const std::string& experiment_id) const; + // This should be called at most once per run. + virtual void LogProfileCount(size_t num_profiles) const; + private: DISALLOW_COPY_AND_ASSIGN(AutofillMetrics); }; diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc index ca51a20..f3d9d99 100644 --- a/chrome/browser/autofill/autofill_metrics_unittest.cc +++ b/chrome/browser/autofill/autofill_metrics_unittest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/autofill/autofill_manager.h" #include "chrome/browser/autofill/autofill_metrics.h" #include "chrome/browser/autofill/personal_data_manager.h" +#include "chrome/browser/webdata/web_data_service.h" #include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/tab_contents/test_tab_contents.h" #include "testing/gmock/include/gmock/gmock.h" @@ -24,10 +25,23 @@ using webkit_glue::FormField; namespace { +class MockAutofillMetrics : public AutofillMetrics { + public: + MockAutofillMetrics() {} + MOCK_CONST_METHOD1(Log, void(ServerQueryMetric metric)); + MOCK_CONST_METHOD2(Log, void(QualityMetric metric, + const std::string& experiment_id)); + MOCK_CONST_METHOD1(LogProfileCount, void(size_t num_profiles)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); +}; + // TODO(isherman): Move this into autofill_common_test.h? class TestPersonalDataManager : public PersonalDataManager { public: TestPersonalDataManager() { + set_metric_logger(new MockAutofillMetrics); CreateTestAutoFillProfiles(&web_profiles_); CreateTestCreditCards(&credit_cards_); } @@ -36,6 +50,31 @@ class TestPersonalDataManager : public PersonalDataManager { virtual void SaveImportedFormData() {} virtual bool IsDataLoaded() const { return true; } + // Overridden to avoid a trip to the database. This should be a no-op except + // for the side-effect of logging the profile count. + virtual void LoadProfiles() { + std::vector<AutoFillProfile*> profiles; + web_profiles_.release(&profiles); + WDResult<std::vector<AutoFillProfile*> > result(AUTOFILL_PROFILES_RESULT, + profiles); + ReceiveLoadedProfiles(0, &result); + } + + // Adds |profile| to |web_profiles_| and takes ownership of the profile's + // memory. + virtual void AddProfile(AutoFillProfile* profile) { + web_profiles_.push_back(profile); + } + + const MockAutofillMetrics* metric_logger() const { + return static_cast<const MockAutofillMetrics*>( + PersonalDataManager::metric_logger()); + } + + static void ResetHasLoggedProfileCount() { + PersonalDataManager::set_has_logged_profile_count(false); + } + private: void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) { AutoFillProfile* profile = new AutoFillProfile; @@ -83,17 +122,6 @@ class TestPersonalDataManager : public PersonalDataManager { DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); }; -class MockAutofillMetrics : public AutofillMetrics { - public: - MockAutofillMetrics() {} - MOCK_CONST_METHOD1(Log, void(ServerQueryMetric metric)); - MOCK_CONST_METHOD2(Log, void(QualityMetric metric, - const std::string& experiment_id)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); -}; - class TestAutofillManager : public AutoFillManager { public: TestAutofillManager(TabContents* tab_contents, @@ -538,3 +566,18 @@ TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) { // Simulate form submission. EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); } + +// Test that the profile count is logged correctly. +TEST_F(AutofillMetricsTest, ProfileCount) { + TestPersonalDataManager::ResetHasLoggedProfileCount(); + + // The metric should be logged when the profiles are first loaded. + EXPECT_CALL(*test_personal_data_->metric_logger(), + LogProfileCount(3)).Times(1); + test_personal_data_->LoadProfiles(); + + // The metric should only be logged once. + EXPECT_CALL(*test_personal_data_->metric_logger(), + LogProfileCount(::testing::_)).Times(0); + test_personal_data_->LoadProfiles(); +} diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc index 78c656a..ed3b86b 100644 --- a/chrome/browser/autofill/personal_data_manager.cc +++ b/chrome/browser/autofill/personal_data_manager.cc @@ -12,6 +12,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/autofill/autofill_field.h" #include "chrome/browser/autofill/autofill-inl.h" +#include "chrome/browser/autofill/autofill_metrics.h" #include "chrome/browser/autofill/form_structure.h" #include "chrome/browser/autofill/phone_number.h" #include "chrome/browser/browser_thread.h" @@ -92,6 +93,9 @@ bool IsMinimumAddress(const AutoFillProfile& profile) { !profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)).empty(); } +// Whether we have already logged the number of profiles this session. +bool g_has_logged_profile_count = false; + } // namespace PersonalDataManager::~PersonalDataManager() { @@ -605,11 +609,18 @@ void PersonalDataManager::Refresh() { LoadCreditCards(); } +// static +void PersonalDataManager::set_has_logged_profile_count( + bool has_logged_profile_count) { + g_has_logged_profile_count = has_logged_profile_count; +} + PersonalDataManager::PersonalDataManager() : profile_(NULL), is_data_loaded_(false), pending_profiles_query_(0), - pending_creditcards_query_(0) { + pending_creditcards_query_(0), + metric_logger_(new AutofillMetrics) { } void PersonalDataManager::Init(Profile* profile) { @@ -666,6 +677,8 @@ void PersonalDataManager::ReceiveLoadedProfiles(WebDataService::Handle h, iter != profiles.end(); ++iter) { web_profiles_.push_back(*iter); } + + LogProfileCount(); } void PersonalDataManager::ReceiveLoadedCreditCards( @@ -800,3 +813,20 @@ void PersonalDataManager::SaveImportedCreditCard( SetCreditCards(&creditcards); } + + +void PersonalDataManager::LogProfileCount() const { + if (!g_has_logged_profile_count) { + g_has_logged_profile_count = true; + metric_logger_->LogProfileCount(web_profiles_.size()); + } +} + +const AutofillMetrics* PersonalDataManager::metric_logger() const { + return metric_logger_.get(); +} + +void PersonalDataManager::set_metric_logger( + const AutofillMetrics* metric_logger) { + metric_logger_.reset(metric_logger); +} diff --git a/chrome/browser/autofill/personal_data_manager.h b/chrome/browser/autofill/personal_data_manager.h index a876bf9..c7c5c30 100644 --- a/chrome/browser/autofill/personal_data_manager.h +++ b/chrome/browser/autofill/personal_data_manager.h @@ -21,6 +21,7 @@ #include "chrome/browser/webdata/web_data_service.h" class AutoFillManager; +class AutofillMetrics; class FormStructure; class Profile; @@ -158,6 +159,9 @@ class PersonalDataManager friend class ProfileImpl; friend class ProfileSyncServiceAutofillTest; + // For tests. + static void set_has_logged_profile_count(bool has_logged_profile_count); + PersonalDataManager(); virtual ~PersonalDataManager(); @@ -197,6 +201,14 @@ class PersonalDataManager const std::vector<AutoFillProfile*>& existing_profiles, std::vector<AutoFillProfile>* merged_profiles); + // The first time this is called, logs an UMA metrics for the number of + // profiles the user has. On subsequent calls, does nothing. + void LogProfileCount() const; + + // For tests. + const AutofillMetrics* metric_logger() const; + void set_metric_logger(const AutofillMetrics* metric_logger); + // The profile hosting this PersonalDataManager. Profile* profile_; @@ -230,6 +242,10 @@ class PersonalDataManager // The observers. ObserverList<Observer> observers_; + private: + // For logging UMA metrics. Overridden by metrics tests. + scoped_ptr<const AutofillMetrics> metric_logger_; + DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); }; |