OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/browser/autocheckout/whitelist_manager.h" | 5 #include "components/autofill/browser/autocheckout/whitelist_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 void WhitelistManager::StartDownloadTimer(size_t interval_seconds) { | 70 void WhitelistManager::StartDownloadTimer(size_t interval_seconds) { |
71 download_timer_.Start(FROM_HERE, | 71 download_timer_.Start(FROM_HERE, |
72 base::TimeDelta::FromSeconds(interval_seconds), | 72 base::TimeDelta::FromSeconds(interval_seconds), |
73 this, | 73 this, |
74 &WhitelistManager::TriggerDownload); | 74 &WhitelistManager::TriggerDownload); |
75 } | 75 } |
76 | 76 |
77 void WhitelistManager::TriggerDownload() { | 77 void WhitelistManager::TriggerDownload() { |
78 callback_is_pending_ = true; | 78 callback_is_pending_ = true; |
79 | 79 |
80 request_started_timestamp_ = base::Time::Now(); | |
81 | |
80 request_.reset(net::URLFetcher::Create( | 82 request_.reset(net::URLFetcher::Create( |
81 0, GURL(kWhitelistUrl), net::URLFetcher::GET, this)); | 83 0, GURL(kWhitelistUrl), net::URLFetcher::GET, this)); |
82 request_->SetRequestContext(context_getter_); | 84 request_->SetRequestContext(context_getter_); |
83 request_->SetAutomaticallyRetryOn5xx(false); | 85 request_->SetAutomaticallyRetryOn5xx(false); |
84 request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 86 request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
85 net::LOAD_DO_NOT_SEND_COOKIES); | 87 net::LOAD_DO_NOT_SEND_COOKIES); |
86 request_->Start(); | 88 request_->Start(); |
87 } | 89 } |
88 | 90 |
89 void WhitelistManager::StopDownloadTimer() { | 91 void WhitelistManager::StopDownloadTimer() { |
90 download_timer_.Stop(); | 92 download_timer_.Stop(); |
91 callback_is_pending_ = false; | 93 callback_is_pending_ = false; |
92 } | 94 } |
93 | 95 |
94 void WhitelistManager::OnURLFetchComplete( | 96 void WhitelistManager::OnURLFetchComplete( |
95 const net::URLFetcher* source) { | 97 const net::URLFetcher* source) { |
96 DCHECK(callback_is_pending_); | 98 DCHECK(callback_is_pending_); |
97 callback_is_pending_ = false; | 99 callback_is_pending_ = false; |
98 scoped_ptr<net::URLFetcher> old_request = request_.Pass(); | 100 scoped_ptr<net::URLFetcher> old_request = request_.Pass(); |
99 DCHECK_EQ(source, old_request.get()); | 101 DCHECK_EQ(source, old_request.get()); |
100 | 102 |
101 if (source->GetResponseCode() == net::HTTP_OK) { | 103 if (source->GetResponseCode() == net::HTTP_OK) { |
104 GetMetricLogger().LogAutocheckoutWhitelistDownloadDuration( | |
105 base::Time::Now() - request_started_timestamp_, | |
106 AutofillMetrics::WHITELIST_DOWNLOAD_SUCCEEDED); | |
102 std::string data; | 107 std::string data; |
103 source->GetResponseAsString(&data); | 108 source->GetResponseAsString(&data); |
104 BuildWhitelist(data); | 109 BuildWhitelist(data); |
110 } else { | |
111 GetMetricLogger().LogAutocheckoutWhitelistDownloadDuration( | |
112 base::Time::Now() - request_started_timestamp_, | |
113 AutofillMetrics::WHITELIST_DOWNLOAD_FAILED); | |
Ilya Sherman
2013/04/17 00:18:01
nit: Would be nice to move most of this code out o
benquan
2013/04/17 01:51:30
In the If block, I want to track UMA before callin
Ilya Sherman
2013/04/17 05:01:48
You can compute the duration outside of the if/els
benquan
2013/04/17 05:48:18
Done.
| |
105 } | 114 } |
106 | 115 |
107 ScheduleDownload(kDownloadIntervalSeconds); | 116 ScheduleDownload(kDownloadIntervalSeconds); |
108 } | 117 } |
109 | 118 |
110 std::string WhitelistManager::GetMatchedURLPrefix(const GURL& url) const { | 119 std::string WhitelistManager::GetMatchedURLPrefix(const GURL& url) const { |
111 if (!experimental_form_filling_enabled_ || url.is_empty()) | 120 if (!experimental_form_filling_enabled_ || url.is_empty()) |
112 return std::string(); | 121 return std::string(); |
113 | 122 |
114 for (std::vector<std::string>::const_iterator it = url_prefixes_.begin(); | 123 for (std::vector<std::string>::const_iterator it = url_prefixes_.begin(); |
(...skipping 25 matching lines...) Expand all Loading... | |
140 // Chrome can ignore them and continue to work. | 149 // Chrome can ignore them and continue to work. |
141 if (!fields[0].empty()) | 150 if (!fields[0].empty()) |
142 new_url_prefixes.push_back(fields[0]); | 151 new_url_prefixes.push_back(fields[0]); |
143 } | 152 } |
144 } | 153 } |
145 url_prefixes_ = new_url_prefixes; | 154 url_prefixes_ = new_url_prefixes; |
146 } | 155 } |
147 | 156 |
148 } // namespace autocheckout | 157 } // namespace autocheckout |
149 } // namespace autofill | 158 } // namespace autofill |
OLD | NEW |