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

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

Issue 2470923003: Handle timeout for update requests. (Closed)
Patch Set: 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 response.minimum_wait_duration().seconds(); 246 response.minimum_wait_duration().seconds();
244 247
245 // Do not let the next_update_interval_ to be too low. 248 // Do not let the next_update_interval_ to be too low.
246 if (minimum_wait_duration_seconds < kV4TimerStartIntervalSecMin) { 249 if (minimum_wait_duration_seconds < kV4TimerStartIntervalSecMin) {
247 minimum_wait_duration_seconds = kV4TimerStartIntervalSecMin; 250 minimum_wait_duration_seconds = kV4TimerStartIntervalSecMin;
248 } 251 }
249 next_update_interval_ = 252 next_update_interval_ =
250 base::TimeDelta::FromSeconds(minimum_wait_duration_seconds); 253 base::TimeDelta::FromSeconds(minimum_wait_duration_seconds);
251 } 254 }
252 255
253 // TODO(vakh): Do something useful with this response.
254 for (ListUpdateResponse& list_update_response : 256 for (ListUpdateResponse& list_update_response :
255 *response.mutable_list_update_responses()) { 257 *response.mutable_list_update_responses()) {
256 if (!list_update_response.has_platform_type()) { 258 if (!list_update_response.has_platform_type()) {
257 RecordParseUpdateResult(NO_PLATFORM_TYPE_ERROR); 259 RecordParseUpdateResult(NO_PLATFORM_TYPE_ERROR);
258 } else if (!list_update_response.has_threat_entry_type()) { 260 } else if (!list_update_response.has_threat_entry_type()) {
259 RecordParseUpdateResult(NO_THREAT_ENTRY_TYPE_ERROR); 261 RecordParseUpdateResult(NO_THREAT_ENTRY_TYPE_ERROR);
260 } else if (!list_update_response.has_threat_type()) { 262 } else if (!list_update_response.has_threat_type()) {
261 RecordParseUpdateResult(NO_THREAT_TYPE_ERROR); 263 RecordParseUpdateResult(NO_THREAT_TYPE_ERROR);
262 } else if (!list_update_response.has_new_client_state()) { 264 } else if (!list_update_response.has_new_client_state()) {
263 RecordParseUpdateResult(NO_STATE_ERROR); 265 RecordParseUpdateResult(NO_STATE_ERROR);
(...skipping 24 matching lines...) Expand all
288 url_fetcher_id_++, update_url, net::URLFetcher::GET, this); 290 url_fetcher_id_++, update_url, net::URLFetcher::GET, this);
289 fetcher->SetExtraRequestHeaders(headers.ToString()); 291 fetcher->SetExtraRequestHeaders(headers.ToString());
290 data_use_measurement::DataUseUserData::AttachToFetcher( 292 data_use_measurement::DataUseUserData::AttachToFetcher(
291 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING); 293 fetcher.get(), data_use_measurement::DataUseUserData::SAFE_BROWSING);
292 294
293 request_.reset(fetcher.release()); 295 request_.reset(fetcher.release());
294 296
295 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); 297 request_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
296 request_->SetRequestContext(request_context_getter_.get()); 298 request_->SetRequestContext(request_context_getter_.get());
297 request_->Start(); 299 request_->Start();
298 // TODO(vakh): Handle request timeout. 300
301 // Begin the update request timeout.
302 timeout_timer_.Start(FROM_HERE,
303 TimeDelta::FromSeconds(kV4TimerUpdateWaitSecMax), this,
304 &V4UpdateProtocolManager::HandleTimeout);
305 }
306
307 void V4UpdateProtocolManager::HandleTimeout() {
308 request_.reset();
Nathan Parker 2016/11/02 21:56:57 This should log some UMA value to indicate the req
vakh (use Gerrit instead) 2016/11/02 22:37:22 I thought about it but I couldn't find a good way
Nathan Parker 2016/11/05 00:32:21 Yes, you can use a UMA_HISTOGRAM just as a counter
309 IssueUpdateRequest();
Nathan Parker 2016/11/02 21:56:57 This will keep trying every 30 seconds. Is that wh
Scott Hess - ex-Googler 2016/11/02 22:05:08 Does the spec address this? I see language about
vakh (use Gerrit instead) 2016/11/02 22:37:22 Sure, that's possible. But what happens after that
vakh (use Gerrit instead) 2016/11/02 22:37:22 No, I don't see it: https://developers.google.com/
vakh (use Gerrit instead) 2016/11/08 17:51:40 Changed the code to schedule a normal update after
299 } 310 }
300 311
301 // net::URLFetcherDelegate implementation ---------------------------------- 312 // net::URLFetcherDelegate implementation ----------------------------------
302 313
303 // SafeBrowsing request responses are handled here. 314 // SafeBrowsing request responses are handled here.
304 void V4UpdateProtocolManager::OnURLFetchComplete( 315 void V4UpdateProtocolManager::OnURLFetchComplete(
305 const net::URLFetcher* source) { 316 const net::URLFetcher* source) {
306 DCHECK(CalledOnValidThread()); 317 DCHECK(CalledOnValidThread());
307 318
319 timeout_timer_.Stop();
320
308 int response_code = source->GetResponseCode(); 321 int response_code = source->GetResponseCode();
309 net::URLRequestStatus status = source->GetStatus(); 322 net::URLRequestStatus status = source->GetStatus();
310 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode( 323 V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode(
311 "SafeBrowsing.V4UpdateHttpResponseOrErrorCode", status, response_code); 324 "SafeBrowsing.V4UpdateHttpResponseOrErrorCode", status, response_code);
312 325
313 last_response_time_ = Time::Now(); 326 last_response_time_ = Time::Now();
314 327
315 std::unique_ptr<ParsedServerResponse> parsed_server_response( 328 std::unique_ptr<ParsedServerResponse> parsed_server_response(
316 new ParsedServerResponse); 329 new ParsedServerResponse);
317 if (status.is_success() && response_code == net::HTTP_OK) { 330 if (status.is_success() && response_code == net::HTTP_OK) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 365
353 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders( 366 void V4UpdateProtocolManager::GetUpdateUrlAndHeaders(
354 const std::string& req_base64, 367 const std::string& req_base64,
355 GURL* gurl, 368 GURL* gurl,
356 net::HttpRequestHeaders* headers) const { 369 net::HttpRequestHeaders* headers) const {
357 V4ProtocolManagerUtil::GetRequestUrlAndHeaders( 370 V4ProtocolManagerUtil::GetRequestUrlAndHeaders(
358 req_base64, "threatListUpdates:fetch", config_, gurl, headers); 371 req_base64, "threatListUpdates:fetch", config_, gurl, headers);
359 } 372 }
360 373
361 } // namespace safe_browsing 374 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698