Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 } | 48 } |
| 49 | 49 |
| 50 WhitelistManager::~WhitelistManager() {} | 50 WhitelistManager::~WhitelistManager() {} |
| 51 | 51 |
| 52 void WhitelistManager::Init(net::URLRequestContextGetter* context_getter) { | 52 void WhitelistManager::Init(net::URLRequestContextGetter* context_getter) { |
| 53 DCHECK(context_getter); | 53 DCHECK(context_getter); |
| 54 context_getter_ = context_getter; | 54 context_getter_ = context_getter; |
| 55 ScheduleDownload(kInitialDownloadDelaySeconds); | 55 ScheduleDownload(kInitialDownloadDelaySeconds); |
| 56 } | 56 } |
| 57 | 57 |
| 58 const AutofillMetrics& WhitelistManager::GetMetricLogger() const { | |
| 59 return metrics_logger_; | |
| 60 } | |
|
Ilya Sherman
2013/04/17 05:01:48
nit: Please order this so that its sorted the same
benquan
2013/04/17 05:48:18
Done.
| |
| 61 | |
| 58 void WhitelistManager::ScheduleDownload(size_t interval_seconds) { | 62 void WhitelistManager::ScheduleDownload(size_t interval_seconds) { |
| 59 if (!experimental_form_filling_enabled_) { | 63 if (!experimental_form_filling_enabled_) { |
| 60 // The feature is not enabled: do not do the request. | 64 // The feature is not enabled: do not do the request. |
| 61 return; | 65 return; |
| 62 } | 66 } |
| 63 if (download_timer_.IsRunning() || callback_is_pending_) { | 67 if (download_timer_.IsRunning() || callback_is_pending_) { |
| 64 // A download activity is already scheduled or happening. | 68 // A download activity is already scheduled or happening. |
| 65 return; | 69 return; |
| 66 } | 70 } |
| 67 StartDownloadTimer(interval_seconds); | 71 StartDownloadTimer(interval_seconds); |
| 68 } | 72 } |
| 69 | 73 |
| 70 void WhitelistManager::StartDownloadTimer(size_t interval_seconds) { | 74 void WhitelistManager::StartDownloadTimer(size_t interval_seconds) { |
| 71 download_timer_.Start(FROM_HERE, | 75 download_timer_.Start(FROM_HERE, |
| 72 base::TimeDelta::FromSeconds(interval_seconds), | 76 base::TimeDelta::FromSeconds(interval_seconds), |
| 73 this, | 77 this, |
| 74 &WhitelistManager::TriggerDownload); | 78 &WhitelistManager::TriggerDownload); |
| 75 } | 79 } |
| 76 | 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 |
| 101 if (source->GetResponseCode() == net::HTTP_OK) { | 107 if (source->GetResponseCode() == net::HTTP_OK) { |
| 108 GetMetricLogger().LogAutocheckoutWhitelistDownloadDuration( | |
| 109 base::Time::Now() - request_started_timestamp_, | |
| 110 AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_SUCCEEDED); | |
| 102 std::string data; | 111 std::string data; |
| 103 source->GetResponseAsString(&data); | 112 source->GetResponseAsString(&data); |
| 104 BuildWhitelist(data); | 113 BuildWhitelist(data); |
| 114 } else { | |
| 115 GetMetricLogger().LogAutocheckoutWhitelistDownloadDuration( | |
| 116 base::Time::Now() - request_started_timestamp_, | |
| 117 AutofillMetrics::AUTOCHECKOUT_WHITELIST_DOWNLOAD_FAILED); | |
| 105 } | 118 } |
| 106 | 119 |
| 107 ScheduleDownload(kDownloadIntervalSeconds); | 120 ScheduleDownload(kDownloadIntervalSeconds); |
| 108 } | 121 } |
| 109 | 122 |
| 110 std::string WhitelistManager::GetMatchedURLPrefix(const GURL& url) const { | 123 std::string WhitelistManager::GetMatchedURLPrefix(const GURL& url) const { |
| 111 if (!experimental_form_filling_enabled_ || url.is_empty()) | 124 if (!experimental_form_filling_enabled_ || url.is_empty()) |
| 112 return std::string(); | 125 return std::string(); |
| 113 | 126 |
| 114 for (std::vector<std::string>::const_iterator it = url_prefixes_.begin(); | 127 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. | 153 // Chrome can ignore them and continue to work. |
| 141 if (!fields[0].empty()) | 154 if (!fields[0].empty()) |
| 142 new_url_prefixes.push_back(fields[0]); | 155 new_url_prefixes.push_back(fields[0]); |
| 143 } | 156 } |
| 144 } | 157 } |
| 145 url_prefixes_ = new_url_prefixes; | 158 url_prefixes_ = new_url_prefixes; |
| 146 } | 159 } |
| 147 | 160 |
| 148 } // namespace autocheckout | 161 } // namespace autocheckout |
| 149 } // namespace autofill | 162 } // namespace autofill |
| OLD | NEW |