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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 StartDownloadTimer(interval_seconds); | 67 StartDownloadTimer(interval_seconds); |
68 } | 68 } |
69 | 69 |
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 const AutofillMetrics& WhitelistManager::GetMetricLogger() const { |
| 78 return metrics_logger_; |
| 79 } |
| 80 |
77 void WhitelistManager::TriggerDownload() { | 81 void WhitelistManager::TriggerDownload() { |
78 callback_is_pending_ = true; | 82 callback_is_pending_ = true; |
79 | 83 |
| 84 request_started_timestamp_ = base::Time::Now(); |
| 85 |
80 request_.reset(net::URLFetcher::Create( | 86 request_.reset(net::URLFetcher::Create( |
81 0, GURL(kWhitelistUrl), net::URLFetcher::GET, this)); | 87 0, GURL(kWhitelistUrl), net::URLFetcher::GET, this)); |
82 request_->SetRequestContext(context_getter_); | 88 request_->SetRequestContext(context_getter_); |
83 request_->SetAutomaticallyRetryOn5xx(false); | 89 request_->SetAutomaticallyRetryOn5xx(false); |
84 request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 90 request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
85 net::LOAD_DO_NOT_SEND_COOKIES); | 91 net::LOAD_DO_NOT_SEND_COOKIES); |
86 request_->Start(); | 92 request_->Start(); |
87 } | 93 } |
88 | 94 |
89 void WhitelistManager::StopDownloadTimer() { | 95 void WhitelistManager::StopDownloadTimer() { |
90 download_timer_.Stop(); | 96 download_timer_.Stop(); |
91 callback_is_pending_ = false; | 97 callback_is_pending_ = false; |
92 } | 98 } |
93 | 99 |
94 void WhitelistManager::OnURLFetchComplete( | 100 void WhitelistManager::OnURLFetchComplete( |
95 const net::URLFetcher* source) { | 101 const net::URLFetcher* source) { |
96 DCHECK(callback_is_pending_); | 102 DCHECK(callback_is_pending_); |
97 callback_is_pending_ = false; | 103 callback_is_pending_ = false; |
98 scoped_ptr<net::URLFetcher> old_request = request_.Pass(); | 104 scoped_ptr<net::URLFetcher> old_request = request_.Pass(); |
99 DCHECK_EQ(source, old_request.get()); | 105 DCHECK_EQ(source, old_request.get()); |
100 | 106 |
| 107 AutofillMetrics::AutocheckoutWhitelistDownloadStatus status; |
| 108 base::TimeDelta duration = base::Time::Now() - request_started_timestamp_; |
| 109 |
101 if (source->GetResponseCode() == net::HTTP_OK) { | 110 if (source->GetResponseCode() == net::HTTP_OK) { |
102 std::string data; | 111 std::string data; |
103 source->GetResponseAsString(&data); | 112 source->GetResponseAsString(&data); |
104 BuildWhitelist(data); | 113 BuildWhitelist(data); |
| 114 status = AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED; |
| 115 } else { |
| 116 status = AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED; |
105 } | 117 } |
106 | 118 |
| 119 GetMetricLogger().LogAutocheckoutWhitelistDownloadDuration(duration, status); |
| 120 |
107 ScheduleDownload(kDownloadIntervalSeconds); | 121 ScheduleDownload(kDownloadIntervalSeconds); |
108 } | 122 } |
109 | 123 |
110 std::string WhitelistManager::GetMatchedURLPrefix(const GURL& url) const { | 124 std::string WhitelistManager::GetMatchedURLPrefix(const GURL& url) const { |
111 if (!experimental_form_filling_enabled_ || url.is_empty()) | 125 if (!experimental_form_filling_enabled_ || url.is_empty()) |
112 return std::string(); | 126 return std::string(); |
113 | 127 |
114 for (std::vector<std::string>::const_iterator it = url_prefixes_.begin(); | 128 for (std::vector<std::string>::const_iterator it = url_prefixes_.begin(); |
115 it != url_prefixes_.end(); ++it) { | 129 it != url_prefixes_.end(); ++it) { |
116 // This is only for ~20 sites initially, liner search is sufficient. | 130 // This is only for ~20 sites initially, liner search is sufficient. |
(...skipping 23 matching lines...) Expand all Loading... |
140 // Chrome can ignore them and continue to work. | 154 // Chrome can ignore them and continue to work. |
141 if (!fields[0].empty()) | 155 if (!fields[0].empty()) |
142 new_url_prefixes.push_back(fields[0]); | 156 new_url_prefixes.push_back(fields[0]); |
143 } | 157 } |
144 } | 158 } |
145 url_prefixes_ = new_url_prefixes; | 159 url_prefixes_ = new_url_prefixes; |
146 } | 160 } |
147 | 161 |
148 } // namespace autocheckout | 162 } // namespace autocheckout |
149 } // namespace autofill | 163 } // namespace autofill |
OLD | NEW |