Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 302603008: [Android] Only update safe-browsing database on WiFi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Take reviewer's suggestions. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698