diff options
author | benquan@chromium.org <benquan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 05:14:48 +0000 |
---|---|---|
committer | benquan@chromium.org <benquan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 05:14:48 +0000 |
commit | 4652b5a6d9e385e0903b9c513b58fd0989bbb40f (patch) | |
tree | 9fcdf66e8cfc3eb3cc27c1f6a694b520f1c632d4 /components/autofill | |
parent | 1af93e81d9a336346c9ddd664812f8dc30e53950 (diff) | |
download | chromium_src-4652b5a6d9e385e0903b9c513b58fd0989bbb40f.zip chromium_src-4652b5a6d9e385e0903b9c513b58fd0989bbb40f.tar.gz chromium_src-4652b5a6d9e385e0903b9c513b58fd0989bbb40f.tar.bz2 |
Add UMA stats to track whitelist download latency.
BUG= 232274
Review URL: https://chromiumcodereview.appspot.com/14060013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/autofill')
5 files changed, 83 insertions, 0 deletions
diff --git a/components/autofill/browser/autocheckout/whitelist_manager.cc b/components/autofill/browser/autocheckout/whitelist_manager.cc index ed735b6..53806c7 100644 --- a/components/autofill/browser/autocheckout/whitelist_manager.cc +++ b/components/autofill/browser/autocheckout/whitelist_manager.cc @@ -76,9 +76,15 @@ void WhitelistManager::StartDownloadTimer(size_t interval_seconds) { &WhitelistManager::TriggerDownload); } +const AutofillMetrics& WhitelistManager::GetMetricLogger() const { + return metrics_logger_; +} + void WhitelistManager::TriggerDownload() { callback_is_pending_ = true; + request_started_timestamp_ = base::Time::Now(); + request_.reset(net::URLFetcher::Create( 0, GURL(kWhitelistUrl), net::URLFetcher::GET, this)); request_->SetRequestContext(context_getter_); @@ -100,12 +106,20 @@ void WhitelistManager::OnURLFetchComplete( scoped_ptr<net::URLFetcher> old_request = request_.Pass(); DCHECK_EQ(source, old_request.get()); + AutofillMetrics::AutocheckoutWhitelistDownloadStatus status; + base::TimeDelta duration = base::Time::Now() - request_started_timestamp_; + if (source->GetResponseCode() == net::HTTP_OK) { std::string data; source->GetResponseAsString(&data); BuildWhitelist(data); + status = AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED; + } else { + status = AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED; } + GetMetricLogger().LogAutocheckoutWhitelistDownloadDuration(duration, status); + ScheduleDownload(kDownloadIntervalSeconds); } diff --git a/components/autofill/browser/autocheckout/whitelist_manager.h b/components/autofill/browser/autocheckout/whitelist_manager.h index 5d8634c..bd60721 100644 --- a/components/autofill/browser/autocheckout/whitelist_manager.h +++ b/components/autofill/browser/autocheckout/whitelist_manager.h @@ -9,6 +9,7 @@ #include <vector> #include "base/timer.h" +#include "components/autofill/browser/autofill_metrics.h" #include "net/url_request/url_fetcher_delegate.h" class GURL; @@ -49,6 +50,10 @@ class WhitelistManager : public net::URLFetcherDelegate { // as a separate method for mocking out in tests. virtual void StartDownloadTimer(size_t interval_seconds); + // Returns the |AutofillMetrics| instance that should be used for logging + // Autocheckout whitelist file downloading. + virtual const AutofillMetrics& GetMetricLogger() const; + // Timer callback indicating it's time to download whitelist from server. void TriggerDownload(); @@ -83,6 +88,12 @@ class WhitelistManager : public net::URLFetcherDelegate { // State of the kBypassAutocheckoutWhitelist flag. const bool bypass_autocheckout_whitelist_; + // Logger for UMA metrics. + AutofillMetrics metrics_logger_; + + // When the whitelist download started. Used to track download latency. + base::Time request_started_timestamp_; + // The request object. scoped_ptr<net::URLFetcher> request_; diff --git a/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc b/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc index 6ff02bb..0aaedc8 100644 --- a/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc +++ b/components/autofill/browser/autocheckout/whitelist_manager_unittest.cc @@ -7,6 +7,7 @@ #include "base/message_loop.h" #include "chrome/test/base/testing_profile.h" #include "components/autofill/browser/autocheckout/whitelist_manager.h" +#include "components/autofill/browser/autofill_metrics.h" #include "components/autofill/common/autofill_switches.h" #include "content/public/test/test_browser_thread.h" #include "googleurl/src/gurl.h" @@ -15,6 +16,7 @@ #include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_request_status.h" +#include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -32,6 +34,16 @@ namespace autocheckout { class WhitelistManagerTest; +class MockAutofillMetrics : public AutofillMetrics { + public: + MockAutofillMetrics() {} + MOCK_CONST_METHOD2(LogAutocheckoutWhitelistDownloadDuration, + void(const base::TimeDelta& duration, + AutofillMetrics::AutocheckoutWhitelistDownloadStatus)); + private: + DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); +}; + class TestWhitelistManager : public WhitelistManager { public: TestWhitelistManager() @@ -64,9 +76,15 @@ class TestWhitelistManager : public WhitelistManager { return WhitelistManager::url_prefixes(); } + virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { + return mock_metrics_logger_; + } + private: bool did_start_download_timer_; + MockAutofillMetrics mock_metrics_logger_; + DISALLOW_COPY_AND_ASSIGN(TestWhitelistManager); }; @@ -97,6 +115,16 @@ class WhitelistManagerTest : public testing::Test { CreateWhitelistManager(); + AutofillMetrics::AutocheckoutWhitelistDownloadStatus status; + if (response_code == net::HTTP_OK) + status = AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED; + else + status = AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED; + EXPECT_CALL( + static_cast<const MockAutofillMetrics&>( + whitelist_manager_->GetMetricLogger()), + LogAutocheckoutWhitelistDownloadDuration(testing::_, status)).Times(1); + whitelist_manager_->TriggerDownload(); net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); ASSERT_TRUE(fetcher); diff --git a/components/autofill/browser/autofill_metrics.cc b/components/autofill/browser/autofill_metrics.cc index f36d3b1..82594a8 100644 --- a/components/autofill/browser/autofill_metrics.cc +++ b/components/autofill/browser/autofill_metrics.cc @@ -448,6 +448,25 @@ void AutofillMetrics::LogAutocheckoutDuration( LogUMAHistogramLongTimes("Autocheckout.FlowDuration." + suffix, duration); } +void AutofillMetrics::LogAutocheckoutWhitelistDownloadDuration( + const base::TimeDelta& duration, + AutocheckoutWhitelistDownloadStatus status) const { + std::string suffix; + switch (status) { + case AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED: + suffix = "Failed"; + break; + + case AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED: + suffix = "Succeeded"; + break; + } + + LogUMAHistogramTimes("Autocheckout.WhitelistDownloadDuration", duration); + LogUMAHistogramTimes( + "Autocheckout.WhitelistDownloadDuration." + suffix, duration); +} + void AutofillMetrics::LogDeveloperEngagementMetric( DeveloperEngagementMetric metric) const { DCHECK_LT(metric, NUM_DEVELOPER_ENGAGEMENT_METRICS); diff --git a/components/autofill/browser/autofill_metrics.h b/components/autofill/browser/autofill_metrics.h index 2f9abd0..e479714 100644 --- a/components/autofill/browser/autofill_metrics.h +++ b/components/autofill/browser/autofill_metrics.h @@ -350,6 +350,12 @@ class AutofillMetrics { NUM_WALLET_REQUIRED_ACTIONS }; + // The success or failure of downloading Autocheckout whitelist file. + enum AutocheckoutWhitelistDownloadStatus { + AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED, + AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED, + }; + AutofillMetrics(); virtual ~AutofillMetrics(); @@ -435,6 +441,11 @@ class AutofillMetrics { const base::TimeDelta& duration, AutocheckoutCompletionStatus status) const; + // Logs the time taken to download Autocheckout whitelist file. + virtual void LogAutocheckoutWhitelistDownloadDuration( + const base::TimeDelta& duration, + AutocheckoutWhitelistDownloadStatus status) const; + // This should be called when a form that has been Autofilled is submitted. // |duration| should be the time elapsed between form load and submission. virtual void LogFormFillDurationFromLoadWithAutofill( |