OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/protocol_manager.h" | 5 #include "chrome/browser/safe_browsing/protocol_manager.h" |
6 | 6 |
7 #include "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "google_apis/google_api_keys.h" | 22 #include "google_apis/google_api_keys.h" |
23 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
24 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
27 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
28 #include "net/url_request/url_fetcher.h" | 28 #include "net/url_request/url_fetcher.h" |
29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
30 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
31 | 31 |
32 #if defined(OS_ANDROID) | |
33 #include "net/base/network_change_notifier.h" | |
34 #endif | |
35 | |
36 using base::Time; | 32 using base::Time; |
37 using base::TimeDelta; | 33 using base::TimeDelta; |
38 | 34 |
39 namespace { | 35 namespace { |
40 | 36 |
41 // UpdateResult indicates what happened with the primary and/or backup update | 37 // UpdateResult indicates what happened with the primary and/or backup update |
42 // requests. The ordering of the values must stay the same for UMA consistency, | 38 // requests. The ordering of the values must stay the same for UMA consistency, |
43 // and is also ordered in this way to match ProtocolManager::BackupUpdateReason. | 39 // and is also ordered in this way to match ProtocolManager::BackupUpdateReason. |
44 enum UpdateResult { | 40 enum UpdateResult { |
45 UPDATE_RESULT_FAIL, | 41 UPDATE_RESULT_FAIL, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 base::RandInt(kSbTimerStartIntervalSecMin, | 137 base::RandInt(kSbTimerStartIntervalSecMin, |
142 kSbTimerStartIntervalSecMax))), | 138 kSbTimerStartIntervalSecMax))), |
143 chunk_pending_to_write_(false), | 139 chunk_pending_to_write_(false), |
144 version_(config.version), | 140 version_(config.version), |
145 update_size_(0), | 141 update_size_(0), |
146 client_name_(config.client_name), | 142 client_name_(config.client_name), |
147 request_context_getter_(request_context_getter), | 143 request_context_getter_(request_context_getter), |
148 url_prefix_(config.url_prefix), | 144 url_prefix_(config.url_prefix), |
149 backup_update_reason_(BACKUP_UPDATE_REASON_MAX), | 145 backup_update_reason_(BACKUP_UPDATE_REASON_MAX), |
150 disable_auto_update_(config.disable_auto_update), | 146 disable_auto_update_(config.disable_auto_update), |
151 #if defined(OS_ANDROID) | |
152 disable_connection_check_(config.disable_connection_check), | |
153 #endif | |
154 url_fetcher_id_(0), | 147 url_fetcher_id_(0), |
155 app_in_foreground_(true) { | 148 app_in_foreground_(true) { |
156 DCHECK(!url_prefix_.empty()); | 149 DCHECK(!url_prefix_.empty()); |
157 | 150 |
158 backup_url_prefixes_[BACKUP_UPDATE_REASON_CONNECT] = | 151 backup_url_prefixes_[BACKUP_UPDATE_REASON_CONNECT] = |
159 config.backup_connect_error_url_prefix; | 152 config.backup_connect_error_url_prefix; |
160 backup_url_prefixes_[BACKUP_UPDATE_REASON_HTTP] = | 153 backup_url_prefixes_[BACKUP_UPDATE_REASON_HTTP] = |
161 config.backup_http_error_url_prefix; | 154 config.backup_http_error_url_prefix; |
162 backup_url_prefixes_[BACKUP_UPDATE_REASON_NETWORK] = | 155 backup_url_prefixes_[BACKUP_UPDATE_REASON_NETWORK] = |
163 config.backup_network_error_url_prefix; | 156 config.backup_network_error_url_prefix; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 fetcher->SetRequestContext(request_context_getter_.get()); | 221 fetcher->SetRequestContext(request_context_getter_.get()); |
229 fetcher->SetUploadData("text/plain", get_hash); | 222 fetcher->SetUploadData("text/plain", get_hash); |
230 fetcher->Start(); | 223 fetcher->Start(); |
231 } | 224 } |
232 | 225 |
233 void SafeBrowsingProtocolManager::GetNextUpdate() { | 226 void SafeBrowsingProtocolManager::GetNextUpdate() { |
234 DCHECK(CalledOnValidThread()); | 227 DCHECK(CalledOnValidThread()); |
235 if (request_.get() || request_type_ != NO_REQUEST) | 228 if (request_.get() || request_type_ != NO_REQUEST) |
236 return; | 229 return; |
237 | 230 |
238 #if defined(OS_ANDROID) | |
239 if (!disable_connection_check_) { | |
240 net::NetworkChangeNotifier::ConnectionType type = | |
241 net::NetworkChangeNotifier::GetConnectionType(); | |
242 if (type != net::NetworkChangeNotifier::CONNECTION_WIFI) { | |
243 ScheduleNextUpdate(false /* no back off */); | |
244 return; | |
245 } | |
246 } | |
247 #endif | |
248 | |
249 IssueUpdateRequest(); | 231 IssueUpdateRequest(); |
250 } | 232 } |
251 | 233 |
252 // net::URLFetcherDelegate implementation ---------------------------------- | 234 // net::URLFetcherDelegate implementation ---------------------------------- |
253 | 235 |
254 // All SafeBrowsing request responses are handled here. | 236 // All SafeBrowsing request responses are handled here. |
255 // TODO(paulg): Clarify with the SafeBrowsing team whether a failed parse of a | 237 // TODO(paulg): Clarify with the SafeBrowsing team whether a failed parse of a |
256 // chunk should retry the download and parse of that chunk (and | 238 // chunk should retry the download and parse of that chunk (and |
257 // what back off / how many times to try), and if that effects the | 239 // what back off / how many times to try), and if that effects the |
258 // update back off. For now, a failed parse of the chunk means we | 240 // update back off. For now, a failed parse of the chunk means we |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 &gethash_error_count_, &gethash_back_off_mult_); | 703 &gethash_error_count_, &gethash_back_off_mult_); |
722 next_gethash_time_ = now + next; | 704 next_gethash_time_ = now + next; |
723 } | 705 } |
724 | 706 |
725 void SafeBrowsingProtocolManager::UpdateFinished(bool success) { | 707 void SafeBrowsingProtocolManager::UpdateFinished(bool success) { |
726 UpdateFinished(success, !success); | 708 UpdateFinished(success, !success); |
727 } | 709 } |
728 | 710 |
729 void SafeBrowsingProtocolManager::UpdateFinished(bool success, bool back_off) { | 711 void SafeBrowsingProtocolManager::UpdateFinished(bool success, bool back_off) { |
730 DCHECK(CalledOnValidThread()); | 712 DCHECK(CalledOnValidThread()); |
731 #if defined(OS_ANDROID) | |
732 if (app_in_foreground_) | |
733 UMA_HISTOGRAM_COUNTS("SB2.UpdateSizeForeground", update_size_); | |
734 else | |
735 UMA_HISTOGRAM_COUNTS("SB2.UpdateSizeBackground", update_size_); | |
736 #endif | |
737 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_); | 713 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_); |
738 update_size_ = 0; | 714 update_size_ = 0; |
739 bool update_success = success || request_type_ == CHUNK_REQUEST; | 715 bool update_success = success || request_type_ == CHUNK_REQUEST; |
740 if (backup_update_reason_ == BACKUP_UPDATE_REASON_MAX) { | 716 if (backup_update_reason_ == BACKUP_UPDATE_REASON_MAX) { |
741 RecordUpdateResult( | 717 RecordUpdateResult( |
742 update_success ? UPDATE_RESULT_SUCCESS : UPDATE_RESULT_FAIL); | 718 update_success ? UPDATE_RESULT_SUCCESS : UPDATE_RESULT_FAIL); |
743 } else { | 719 } else { |
744 UpdateResult update_result = static_cast<UpdateResult>( | 720 UpdateResult update_result = static_cast<UpdateResult>( |
745 UPDATE_RESULT_BACKUP_START + | 721 UPDATE_RESULT_BACKUP_START + |
746 (static_cast<int>(backup_update_reason_) * 2) + | 722 (static_cast<int>(backup_update_reason_) * 2) + |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 FullHashCallback callback, bool is_download) | 792 FullHashCallback callback, bool is_download) |
817 : callback(callback), | 793 : callback(callback), |
818 is_download(is_download) { | 794 is_download(is_download) { |
819 } | 795 } |
820 | 796 |
821 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() { | 797 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() { |
822 } | 798 } |
823 | 799 |
824 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() { | 800 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() { |
825 } | 801 } |
OLD | NEW |