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

Side by Side Diff: components/safe_browsing_db/v4_update_protocol_manager.cc

Issue 2470923003: Handle timeout for update requests. (Closed)
Patch Set: Added a histogram for counting update timeouts Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/safe_browsing_db/v4_update_protocol_manager.h" 5 #include "components/safe_browsing_db/v4_update_protocol_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64url.h" 9 #include "base/base64url.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } // namespace 63 } // namespace
64 64
65 namespace safe_browsing { 65 namespace safe_browsing {
66 66
67 // Minimum time, in seconds, from start up before we must issue an update query. 67 // Minimum time, in seconds, from start up before we must issue an update query.
68 static const int kV4TimerStartIntervalSecMin = 60; 68 static const int kV4TimerStartIntervalSecMin = 60;
69 69
70 // Maximum time, in seconds, from start up before we must issue an update query. 70 // Maximum time, in seconds, from start up before we must issue an update query.
71 static const int kV4TimerStartIntervalSecMax = 300; 71 static const int kV4TimerStartIntervalSecMax = 300;
72 72
73 // Maximum time, in seconds, to wait for a response to an update request.
74 static const int kV4TimerUpdateWaitSecMax = 30;
75
73 // The default V4UpdateProtocolManagerFactory. 76 // The default V4UpdateProtocolManagerFactory.
74 class V4UpdateProtocolManagerFactoryImpl 77 class V4UpdateProtocolManagerFactoryImpl
75 : public V4UpdateProtocolManagerFactory { 78 : public V4UpdateProtocolManagerFactory {
76 public: 79 public:
77 V4UpdateProtocolManagerFactoryImpl() {} 80 V4UpdateProtocolManagerFactoryImpl() {}
78 ~V4UpdateProtocolManagerFactoryImpl() override {} 81 ~V4UpdateProtocolManagerFactoryImpl() override {}
79 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( 82 std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager(
80 net::URLRequestContextGetter* request_context_getter, 83 net::URLRequestContextGetter* request_context_getter,
81 const V4ProtocolConfig& config, 84 const V4ProtocolConfig& config,
82 V4UpdateCallback callback) override { 85 V4UpdateCallback callback) override {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 response.minimum_wait_duration().seconds(); 244 response.minimum_wait_duration().seconds();
242 245
243 // Do not let the next_update_interval_ to be too low. 246 // Do not let the next_update_interval_ to be too low.
244 if (minimum_wait_duration_seconds < kV4TimerStartIntervalSecMin) { 247 if (minimum_wait_duration_seconds < kV4TimerStartIntervalSecMin) {
245 minimum_wait_duration_seconds = kV4TimerStartIntervalSecMin; 248 minimum_wait_duration_seconds = kV4TimerStartIntervalSecMin;
246 } 249 }
247 next_update_interval_ = 250 next_update_interval_ =
248 base::TimeDelta::FromSeconds(minimum_wait_duration_seconds); 251 base::TimeDelta::FromSeconds(minimum_wait_duration_seconds);
249 } 252 }
250 253
251 // TODO(vakh): Do something useful with this response.
252 for (ListUpdateResponse& list_update_response : 254 for (ListUpdateResponse& list_update_response :
253 *response.mutable_list_update_responses()) { 255 *response.mutable_list_update_responses()) {
254 if (!list_update_response.has_platform_type()) { 256 if (!list_update_response.has_platform_type()) {
255 RecordParseUpdateResult(NO_PLATFORM_TYPE_ERROR); 257 RecordParseUpdateResult(NO_PLATFORM_TYPE_ERROR);
256 } else if (!list_update_response.has_threat_entry_type()) { 258 } else if (!list_update_response.has_threat_entry_type()) {
257 RecordParseUpdateResult(NO_THREAT_ENTRY_TYPE_ERROR); 259 RecordParseUpdateResult(NO_THREAT_ENTRY_TYPE_ERROR);
258 } else if (!list_update_response.has_threat_type()) { 260 } else if (!list_update_response.has_threat_type()) {
259 RecordParseUpdateResult(NO_THREAT_TYPE_ERROR); 261 RecordParseUpdateResult(NO_THREAT_TYPE_ERROR);
260 } else if (!list_update_response.has_new_client_state()) { 262 } else if (!list_update_response.has_new_client_state()) {
261 RecordParseUpdateResult(NO_STATE_ERROR); 263 RecordParseUpdateResult(NO_STATE_ERROR);
(...skipping 24 matching lines...) Expand all
286 url_fetcher_id_++, update_url, net::URLFetcher::GET, this); 288 url_fetcher_id_++, update_url, net::URLFetcher::GET, this);
287 fetcher->SetExtraRequestHeaders(headers.ToString()); 289 fetcher->SetExtraRequestHeaders(headers.ToString());
288 data_use_measurement::DataUseUserData::AttachToFetcher( 290 data_use_measurement::DataUseUserData::AttachToFetcher(
289 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); 291 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
290 292
291 request_.reset(fetcher.release()); 293 request_.reset(fetcher.release());
292 294
293 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); 295 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
294 request_->SetRequestContext(request_context_getter_.get()); 296 request_->SetRequestContext(request_context_getter_.get());
295 request_->Start(); 297 request_->Start();
296 // TODO(vakh): Handle request timeout. 298
299 // Begin the update request timeout.
300 timeout_timer_.Start(FROM_HERE,
301 TimeDelta::FromSeconds(kV4TimerUpdateWaitSecMax), this,
302 &V4UpdateProtocolManager::HandleTimeout);
303 }
304
305 void V4UpdateProtocolManager::HandleTimeout() {
306 UMA_HISTOGRAM_COUNTS_100("SafeBrowsing.V4Update.Timeout.Count", 1);
Nathan Parker 2016/11/08 23:39:29 Or UMA_HISTOGRAM_BOOLEAN("..", true) either way
vakh (use Gerrit instead) 2016/11/09 00:08:51 Done.
307 request_.reset();
308 ScheduleNextUpdateWithBackoff(false);
297 } 309 }
298 310
299 // net::URLFetcherDelegate implementation ---------------------------------- 311 // net::URLFetcherDelegate implementation ----------------------------------
300 312
301 // SafeBrowsing request responses are handled here. 313 // SafeBrowsing request responses are handled here.
302 void V4UpdateProtocolManager::OnURLFetchComplete( 314 void V4UpdateProtocolManager::OnURLFetchComplete(
303 const net::URLFetcher* source) { 315 const net::URLFetcher* source) {
304 DCHECK(CalledOnValidThread()); 316 DCHECK(CalledOnValidThread());
305 317
318 timeout_timer_.Stop();
319
306 int response_code = source->GetResponseCode(); 320 int response_code = source->GetResponseCode();
307 net::URLRequestStatus status = source->GetStatus(); 321 net::URLRequestStatus status = source->GetStatus();
308 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( 322 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode(
309 "SafeBrowsing.V4Update.Network.Result", status, response_code); 323 "SafeBrowsing.V4Update.Network.Result", status, response_code);
310 324
311 last_response_time_ = Time::Now(); 325 last_response_time_ = Time::Now();
312 326
313 std::unique_ptr<ParsedServerResponse> parsed_server_response( 327 std::unique_ptr<ParsedServerResponse> parsed_server_response(
314 new ParsedServerResponse); 328 new ParsedServerResponse);
315 if (status.is_success() && response_code == net::HTTP_OK) { 329 if (status.is_success() && response_code == net::HTTP_OK) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 364
351 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( 365 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders(
352 const std::string& req_base64, 366 const std::string& req_base64,
353 GURL* gurl, 367 GURL* gurl,
354 net::HttpRequestHeaders* headers) const { 368 net::HttpRequestHeaders* headers) const {
355 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( 369 V4ProtocolManagerUtil::GetRequestUrlAndHeaders(
356 req_base64, "threatListUpdates:fetch", config_, gurl, headers); 370 req_base64, "threatListUpdates:fetch", config_, gurl, headers);
357 } 371 }
358 372
359 } // namespace safe_browsing 373 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698