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

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

Issue 4079: Porting refactoring changes:... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/rand_util.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/sys_info.h"
11 #include "base/task.h" 13 #include "base/task.h"
12 #include "base/timer.h" 14 #include "base/timer.h"
13 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
14 #include "chrome/browser/safe_browsing/protocol_parser.h" 16 #include "chrome/browser/safe_browsing/protocol_parser.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/common/env_util.h"
17 #include "chrome/common/env_vars.h" 18 #include "chrome/common/env_vars.h"
18 #include "chrome/common/rand_util.h"
19 #include "chrome/common/stl_util-inl.h" 19 #include "chrome/common/stl_util-inl.h"
20 #include "net/base/base64.h" 20 #include "net/base/base64.h"
21 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
22 22
23 23
24 // Maximum time, in seconds, from start up before we must issue an update query. 24 // Maximum time, in seconds, from start up before we must issue an update query.
25 static const int kSbTimerStartIntervalSec = 300; 25 static const int kSbTimerStartIntervalSec = 300;
Mark Mentovai 2008/09/29 22:20:05 Changed this to 5 * 60 for improved awesomeness.
26 26
27 // Update URL for querying about the latest set of chunk updates. 27 // Update URL for querying about the latest set of chunk updates.
28 static const char* const kSbUpdateUrl = 28 static const char* const kSbUpdateUrl =
29 "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=%s&app ver=%d.%d&pver=2.1"; 29 "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=%s&app ver=%d.%d&pver=2.1";
30 30
31 // GetHash request URL for retrieving full hashes. 31 // GetHash request URL for retrieving full hashes.
32 static const char* const kSbGetHashUrl = 32 static const char* const kSbGetHashUrl =
33 "http://safebrowsing.clients.google.com/safebrowsing/gethash?client=%s&appve r=%d.%d&pver=2.1"; 33 "http://safebrowsing.clients.google.com/safebrowsing/gethash?client=%s&appve r=%d.%d&pver=2.1";
34 34
35 // New MAC client key requests URL. 35 // New MAC client key requests URL.
(...skipping 26 matching lines...) Expand all
62 update_back_off_mult_(1), 62 update_back_off_mult_(1),
63 gethash_back_off_mult_(1), 63 gethash_back_off_mult_(1),
64 next_update_sec_(-1), 64 next_update_sec_(-1),
65 update_state_(FIRST_REQUEST), 65 update_state_(FIRST_REQUEST),
66 initial_request_(true), 66 initial_request_(true),
67 chunk_pending_to_write_(false), 67 chunk_pending_to_write_(false),
68 notify_loop_(notify_loop), 68 notify_loop_(notify_loop),
69 client_key_(client_key), 69 client_key_(client_key),
70 wrapped_key_(wrapped_key) { 70 wrapped_key_(wrapped_key) {
71 // Set the backoff multiplier fuzz to a random value between 0 and 1. 71 // Set the backoff multiplier fuzz to a random value between 0 and 1.
72 back_off_fuzz_ = static_cast<float>(rand_util::RandInt(1, INT_MAX)) / INT_MAX; 72 back_off_fuzz_ = base::RandDouble();
Mark Mentovai 2008/09/29 22:20:05 MSVC still requires static_cast<float> here, "poss
73 73
74 // The first update must happen between 0-5 minutes of start up. 74 // The first update must happen between 0-5 minutes of start up.
75 next_update_sec_ = rand_util::RandInt(60, kSbTimerStartIntervalSec); 75 next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec);
76 } 76 }
77 77
78 SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() { 78 SafeBrowsingProtocolManager::~SafeBrowsingProtocolManager() {
79 // Delete in-progress SafeBrowsing requests. 79 // Delete in-progress SafeBrowsing requests.
80 STLDeleteContainerPairFirstPointers(hash_requests_.begin(), 80 STLDeleteContainerPairFirstPointers(hash_requests_.begin(),
81 hash_requests_.end()); 81 hash_requests_.end());
82 hash_requests_.clear(); 82 hash_requests_.clear();
83 } 83 }
84 84
85 // Public API used by the SafeBrowsingService ---------------------------------- 85 // Public API used by the SafeBrowsingService ----------------------------------
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 if (update_state_ == FIRST_REQUEST) 270 if (update_state_ == FIRST_REQUEST)
271 update_state_ = SECOND_REQUEST; 271 update_state_ = SECOND_REQUEST;
272 else if (update_state_ == SECOND_REQUEST) 272 else if (update_state_ == SECOND_REQUEST)
273 update_state_ = NORMAL_REQUEST; 273 update_state_ = NORMAL_REQUEST;
274 274
275 // New time for the next update. 275 // New time for the next update.
276 if (next_update_sec > 0) { 276 if (next_update_sec > 0) {
277 next_update_sec_ = next_update_sec; 277 next_update_sec_ = next_update_sec;
278 } else if (update_state_ == SECOND_REQUEST) { 278 } else if (update_state_ == SECOND_REQUEST) {
279 next_update_sec_ = rand_util::RandInt(15, 45) * 60; 279 next_update_sec_ = base::RandInt(15 * 60, 45 * 60);
280 } 280 }
281 281
282 // We need to request a new set of keys for MAC. 282 // We need to request a new set of keys for MAC.
283 if (re_key) 283 if (re_key)
284 HandleReKey(); 284 HandleReKey();
285 285
286 // New chunks to download. 286 // New chunks to download.
287 if (!chunk_urls.empty()) { 287 if (!chunk_urls.empty()) {
288 for (size_t i = 0; i < chunk_urls.size(); ++i) 288 for (size_t i = 0; i < chunk_urls.size(); ++i)
289 chunk_request_urls_.push_back(chunk_urls[i]); 289 chunk_request_urls_.push_back(chunk_urls[i]);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 365
366 default: 366 default:
367 return false; 367 return false;
368 } 368 }
369 369
370 return true; 370 return true;
371 } 371 }
372 372
373 void SafeBrowsingProtocolManager::Initialize() { 373 void SafeBrowsingProtocolManager::Initialize() {
374 // Don't want to hit the safe browsing servers on build/chrome bots. 374 // Don't want to hit the safe browsing servers on build/chrome bots.
375 if (env_util::HasEnvironmentVariable(env_vars::kHeadless)) 375 if (base::SysInfo::HasEnvironmentVariable(env_vars::kHeadless))
Mark Mentovai 2008/09/29 22:20:05 env_vars::kHeadless is a const wchar_t*, but HasEn
376 return; 376 return;
377 377
378 ScheduleNextUpdate(false /* no back off */); 378 ScheduleNextUpdate(false /* no back off */);
379 } 379 }
380 380
381 void SafeBrowsingProtocolManager::ScheduleNextUpdate(bool back_off) { 381 void SafeBrowsingProtocolManager::ScheduleNextUpdate(bool back_off) {
382 DCHECK(next_update_sec_ > 0); 382 DCHECK(next_update_sec_ > 0);
383 383
384 // Unschedule any current timer. 384 // Unschedule any current timer.
385 update_timer_.Stop(); 385 update_timer_.Stop();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 void SafeBrowsingProtocolManager::HandleReKey() { 554 void SafeBrowsingProtocolManager::HandleReKey() {
555 client_key_.clear(); 555 client_key_.clear();
556 wrapped_key_.clear(); 556 wrapped_key_.clear();
557 IssueKeyRequest(); 557 IssueKeyRequest();
558 } 558 }
559 559
560 void SafeBrowsingProtocolManager::HandleGetHashError() { 560 void SafeBrowsingProtocolManager::HandleGetHashError() {
561 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_); 561 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_);
562 next_gethash_time_ = Time::Now() + TimeDelta::FromSeconds(next); 562 next_gethash_time_ = Time::Now() + TimeDelta::FromSeconds(next);
563 } 563 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698