Chromium Code Reviews| 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" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 if (!parsed_ok) { | 243 if (!parsed_ok) { |
| 244 VLOG(1) << "SafeBrowsing request for: " << source->GetURL() | 244 VLOG(1) << "SafeBrowsing request for: " << source->GetURL() |
| 245 << " failed parse."; | 245 << " failed parse."; |
| 246 must_back_off = true; | 246 must_back_off = true; |
| 247 chunk_request_urls_.clear(); | 247 chunk_request_urls_.clear(); |
| 248 UpdateFinished(false); | 248 UpdateFinished(false); |
| 249 } | 249 } |
| 250 | 250 |
| 251 switch (request_type_) { | 251 switch (request_type_) { |
| 252 case CHUNK_REQUEST: | 252 case CHUNK_REQUEST: |
| 253 if (parsed_ok) | 253 if (parsed_ok) { |
| 254 chunk_request_urls_.pop_front(); | 254 chunk_request_urls_.pop_front(); |
| 255 if (chunk_request_urls_.empty() && !chunk_pending_to_write_) | |
| 256 UpdateFinished(true); | |
| 257 } | |
| 255 break; | 258 break; |
| 256 case UPDATE_REQUEST: | 259 case UPDATE_REQUEST: |
| 257 if (chunk_request_urls_.empty() && parsed_ok) { | 260 if (chunk_request_urls_.empty() && parsed_ok) { |
| 258 // We are up to date since the servers gave us nothing new, so we | 261 // We are up to date since the servers gave us nothing new, so we |
| 259 // are done with this update cycle. | 262 // are done with this update cycle. |
| 260 UpdateFinished(true); | 263 UpdateFinished(true); |
| 261 } | 264 } |
| 262 break; | 265 break; |
| 263 default: | 266 default: |
| 264 NOTREACHED(); | 267 NOTREACHED(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 276 } else { | 279 } else { |
| 277 VLOG(1) << "SafeBrowsing request for: " << source->GetURL() | 280 VLOG(1) << "SafeBrowsing request for: " << source->GetURL() |
| 278 << " failed with error: " << source->GetResponseCode(); | 281 << " failed with error: " << source->GetResponseCode(); |
| 279 } | 282 } |
| 280 } | 283 } |
| 281 } | 284 } |
| 282 | 285 |
| 283 // Schedule a new update request if we've finished retrieving all the chunks | 286 // Schedule a new update request if we've finished retrieving all the chunks |
| 284 // from the previous update. We treat the update request and the chunk URLs it | 287 // from the previous update. We treat the update request and the chunk URLs it |
| 285 // contains as an atomic unit as far as back off is concerned. | 288 // contains as an atomic unit as far as back off is concerned. |
| 286 if (chunk_request_urls_.empty() && | 289 if (chunk_request_urls_.empty() && !chunk_pending_to_write_ && |
|
mattm
2012/11/16 21:48:46
so if we hit this case, does something else schedu
cbentzel
2012/11/16 21:52:35
This is handled in OnAddChunksComplete.
The test
| |
| 287 (request_type_ == CHUNK_REQUEST || request_type_ == UPDATE_REQUEST)) | 290 (request_type_ == CHUNK_REQUEST || request_type_ == UPDATE_REQUEST)) { |
| 288 ScheduleNextUpdate(must_back_off); | 291 ScheduleNextUpdate(must_back_off); |
| 292 } | |
| 289 | 293 |
| 290 // Get the next chunk if available. | 294 // Get the next chunk if available. |
| 291 IssueChunkRequest(); | 295 IssueChunkRequest(); |
| 292 } | 296 } |
| 293 | 297 |
| 294 bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, | 298 bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url, |
| 295 const char* data, | 299 const char* data, |
| 296 int length) { | 300 int length) { |
| 297 DCHECK(CalledOnValidThread()); | 301 DCHECK(CalledOnValidThread()); |
| 298 SafeBrowsingProtocolParser parser; | 302 SafeBrowsingProtocolParser parser; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 VLOG(1) << "ParseChunk error for chunk: " << chunk_url.url | 369 VLOG(1) << "ParseChunk error for chunk: " << chunk_url.url |
| 366 << ", Base64Encode(data): " << encoded_chunk | 370 << ", Base64Encode(data): " << encoded_chunk |
| 367 << ", length: " << length; | 371 << ", length: " << length; |
| 368 #endif | 372 #endif |
| 369 return false; | 373 return false; |
| 370 } | 374 } |
| 371 | 375 |
| 372 // Chunks to add to storage. Pass ownership of |chunks|. | 376 // Chunks to add to storage. Pass ownership of |chunks|. |
| 373 if (!chunks->empty()) { | 377 if (!chunks->empty()) { |
| 374 chunk_pending_to_write_ = true; | 378 chunk_pending_to_write_ = true; |
| 375 delegate_->AddChunks(chunk_url.list_name, chunks.release()); | 379 delegate_->AddChunks( |
| 380 chunk_url.list_name, chunks.release(), | |
| 381 base::Bind(&SafeBrowsingProtocolManager::OnAddChunksComplete, | |
| 382 base::Unretained(this))); | |
| 376 } | 383 } |
| 377 | 384 |
| 378 break; | 385 break; |
| 379 } | 386 } |
| 380 | 387 |
| 381 default: | 388 default: |
| 382 return false; | 389 return false; |
| 383 } | 390 } |
| 384 | 391 |
| 385 return true; | 392 return true; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 // If we haven't heard back from the server with an update response, this method | 545 // If we haven't heard back from the server with an update response, this method |
| 539 // will run. Close the current update session and schedule another update. | 546 // will run. Close the current update session and schedule another update. |
| 540 void SafeBrowsingProtocolManager::UpdateResponseTimeout() { | 547 void SafeBrowsingProtocolManager::UpdateResponseTimeout() { |
| 541 DCHECK(CalledOnValidThread()); | 548 DCHECK(CalledOnValidThread()); |
| 542 DCHECK_EQ(request_type_, UPDATE_REQUEST); | 549 DCHECK_EQ(request_type_, UPDATE_REQUEST); |
| 543 request_.reset(); | 550 request_.reset(); |
| 544 UpdateFinished(false); | 551 UpdateFinished(false); |
| 545 ScheduleNextUpdate(true); | 552 ScheduleNextUpdate(true); |
| 546 } | 553 } |
| 547 | 554 |
| 548 void SafeBrowsingProtocolManager::OnChunkInserted() { | 555 void SafeBrowsingProtocolManager::OnAddChunksComplete() { |
| 549 DCHECK(CalledOnValidThread()); | 556 DCHECK(CalledOnValidThread()); |
| 550 chunk_pending_to_write_ = false; | 557 chunk_pending_to_write_ = false; |
| 551 | 558 |
| 552 if (chunk_request_urls_.empty()) { | 559 if (chunk_request_urls_.empty()) { |
| 553 UMA_HISTOGRAM_LONG_TIMES("SB2.Update", Time::Now() - last_update_); | 560 UMA_HISTOGRAM_LONG_TIMES("SB2.Update", Time::Now() - last_update_); |
| 554 UpdateFinished(true); | 561 UpdateFinished(true); |
| 555 } else { | 562 } else { |
| 556 IssueChunkRequest(); | 563 IssueChunkRequest(); |
| 557 } | 564 } |
| 558 } | 565 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 FullHashCallback callback, bool is_download) | 643 FullHashCallback callback, bool is_download) |
| 637 : callback(callback), | 644 : callback(callback), |
| 638 is_download(is_download) { | 645 is_download(is_download) { |
| 639 } | 646 } |
| 640 | 647 |
| 641 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() { | 648 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() { |
| 642 } | 649 } |
| 643 | 650 |
| 644 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() { | 651 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() { |
| 645 } | 652 } |
| OLD | NEW |