| 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 #ifndef NDEBUG | 7 #ifndef NDEBUG |
| 8 #include "base/base64.h" | 8 #include "base/base64.h" |
| 9 #endif | 9 #endif |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 18 #include "chrome/browser/safe_browsing/protocol_parser.h" | 18 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 19 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 20 #include "chrome/common/env_vars.h" | 20 #include "chrome/common/env_vars.h" |
| 21 #include "google_apis/google_api_keys.h" | 21 #include "google_apis/google_api_keys.h" |
| 22 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 27 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 28 | 28 |
| 29 #if defined(OS_ANDROID) |
| 30 #include "net/base/network_change_notifier.h" |
| 31 #endif |
| 32 |
| 29 using base::Time; | 33 using base::Time; |
| 30 using base::TimeDelta; | 34 using base::TimeDelta; |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 // UpdateResult indicates what happened with the primary and/or backup update | 38 // UpdateResult indicates what happened with the primary and/or backup update |
| 35 // requests. The ordering of the values must stay the same for UMA consistency, | 39 // requests. The ordering of the values must stay the same for UMA consistency, |
| 36 // and is also ordered in this way to match ProtocolManager::BackupUpdateReason. | 40 // and is also ordered in this way to match ProtocolManager::BackupUpdateReason. |
| 37 enum UpdateResult { | 41 enum UpdateResult { |
| 38 UPDATE_RESULT_FAIL, | 42 UPDATE_RESULT_FAIL, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 parser.FormatGetHash(prefixes, &get_hash); | 194 parser.FormatGetHash(prefixes, &get_hash); |
| 191 | 195 |
| 192 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 196 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 193 fetcher->SetRequestContext(request_context_getter_.get()); | 197 fetcher->SetRequestContext(request_context_getter_.get()); |
| 194 fetcher->SetUploadData("text/plain", get_hash); | 198 fetcher->SetUploadData("text/plain", get_hash); |
| 195 fetcher->Start(); | 199 fetcher->Start(); |
| 196 } | 200 } |
| 197 | 201 |
| 198 void SafeBrowsingProtocolManager::GetNextUpdate() { | 202 void SafeBrowsingProtocolManager::GetNextUpdate() { |
| 199 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
| 200 if (!request_.get() && request_type_ == NO_REQUEST) | 204 if (request_.get() || request_type_ != NO_REQUEST) |
| 201 IssueUpdateRequest(); | 205 return; |
| 206 |
| 207 #if defined(OS_ANDROID) |
| 208 net::NetworkChangeNotifier::ConnectionType type = |
| 209 net::NetworkChangeNotifier::GetConnectionType(); |
| 210 if (type != net::NetworkChangeNotifier::CONNECTION_WIFI) { |
| 211 ScheduleNextUpdate(false /* no back off */); |
| 212 return; |
| 213 } |
| 214 #endif |
| 215 |
| 216 IssueUpdateRequest(); |
| 202 } | 217 } |
| 203 | 218 |
| 204 // net::URLFetcherDelegate implementation ---------------------------------- | 219 // net::URLFetcherDelegate implementation ---------------------------------- |
| 205 | 220 |
| 206 // All SafeBrowsing request responses are handled here. | 221 // All SafeBrowsing request responses are handled here. |
| 207 // TODO(paulg): Clarify with the SafeBrowsing team whether a failed parse of a | 222 // TODO(paulg): Clarify with the SafeBrowsing team whether a failed parse of a |
| 208 // chunk should retry the download and parse of that chunk (and | 223 // chunk should retry the download and parse of that chunk (and |
| 209 // what back off / how many times to try), and if that effects the | 224 // what back off / how many times to try), and if that effects the |
| 210 // update back off. For now, a failed parse of the chunk means we | 225 // update back off. For now, a failed parse of the chunk means we |
| 211 // drop it. This isn't so bad because the next UPDATE_REQUEST we | 226 // drop it. This isn't so bad because the next UPDATE_REQUEST we |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 FullHashCallback callback, bool is_download) | 798 FullHashCallback callback, bool is_download) |
| 784 : callback(callback), | 799 : callback(callback), |
| 785 is_download(is_download) { | 800 is_download(is_download) { |
| 786 } | 801 } |
| 787 | 802 |
| 788 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() { | 803 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() { |
| 789 } | 804 } |
| 790 | 805 |
| 791 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() { | 806 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() { |
| 792 } | 807 } |
| OLD | NEW |