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

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

Issue 348037: Fourth patch in getting rid of caching MessageLoop pointers. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | 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/file_version_info.h" 7 #include "base/file_version_info.h"
8 #include "base/histogram.h" 8 #include "base/histogram.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h"
11 #include "base/rand_util.h" 10 #include "base/rand_util.h"
12 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
13 #include "base/string_util.h" 12 #include "base/string_util.h"
14 #include "base/sys_info.h" 13 #include "base/sys_info.h"
15 #include "base/task.h" 14 #include "base/task.h"
16 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
18 #include "chrome/browser/safe_browsing/protocol_parser.h" 18 #include "chrome/browser/safe_browsing/protocol_parser.h"
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
20 #include "chrome/common/env_vars.h" 20 #include "chrome/common/env_vars.h"
21 #include "net/base/base64.h" 21 #include "net/base/base64.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 24
25 using base::Time; 25 using base::Time;
26 using base::TimeDelta; 26 using base::TimeDelta;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #endif 60 #endif
61 61
62 // Maximum back off multiplier. 62 // Maximum back off multiplier.
63 static const int kSbMaxBackOff = 8; 63 static const int kSbMaxBackOff = 8;
64 64
65 65
66 // SafeBrowsingProtocolManager implementation ---------------------------------- 66 // SafeBrowsingProtocolManager implementation ----------------------------------
67 67
68 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( 68 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager(
69 SafeBrowsingService* sb_service, 69 SafeBrowsingService* sb_service,
70 MessageLoop* notify_loop,
71 const std::string& client_key, 70 const std::string& client_key,
72 const std::string& wrapped_key) 71 const std::string& wrapped_key)
73 : sb_service_(sb_service), 72 : sb_service_(sb_service),
74 request_type_(NO_REQUEST), 73 request_type_(NO_REQUEST),
75 update_error_count_(0), 74 update_error_count_(0),
76 gethash_error_count_(0), 75 gethash_error_count_(0),
77 update_back_off_mult_(1), 76 update_back_off_mult_(1),
78 gethash_back_off_mult_(1), 77 gethash_back_off_mult_(1),
79 next_update_sec_(-1), 78 next_update_sec_(-1),
80 update_state_(FIRST_REQUEST), 79 update_state_(FIRST_REQUEST),
81 initial_request_(true), 80 initial_request_(true),
82 chunk_pending_to_write_(false), 81 chunk_pending_to_write_(false),
83 notify_loop_(notify_loop),
84 client_key_(client_key), 82 client_key_(client_key),
85 wrapped_key_(wrapped_key), 83 wrapped_key_(wrapped_key),
86 update_size_(0) { 84 update_size_(0) {
87 // Set the backoff multiplier fuzz to a random value between 0 and 1. 85 // Set the backoff multiplier fuzz to a random value between 0 and 1.
88 back_off_fuzz_ = static_cast<float>(base::RandDouble()); 86 back_off_fuzz_ = static_cast<float>(base::RandDouble());
89 87
90 // The first update must happen between 0-5 minutes of start up. 88 // The first update must happen between 0-5 minutes of start up.
91 next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec); 89 next_update_sec_ = base::RandInt(60, kSbTimerStartIntervalSec);
92 90
93 scoped_ptr<FileVersionInfo> version_info( 91 scoped_ptr<FileVersionInfo> version_info(
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 414
417 break; 415 break;
418 } 416 }
419 case GETKEY_REQUEST: { 417 case GETKEY_REQUEST: {
420 std::string client_key, wrapped_key; 418 std::string client_key, wrapped_key;
421 if (!parser.ParseNewKey(data, length, &client_key, &wrapped_key)) 419 if (!parser.ParseNewKey(data, length, &client_key, &wrapped_key))
422 return false; 420 return false;
423 421
424 client_key_ = client_key; 422 client_key_ = client_key;
425 wrapped_key_ = wrapped_key; 423 wrapped_key_ = wrapped_key;
426 notify_loop_->PostTask(FROM_HERE, NewRunnableMethod( 424 ChromeThread::PostTask(
427 sb_service_, &SafeBrowsingService::OnNewMacKeys, client_key_, 425 ChromeThread::UI, FROM_HERE,
428 wrapped_key_)); 426 NewRunnableMethod(
427 sb_service_, &SafeBrowsingService::OnNewMacKeys, client_key_,
428 wrapped_key_));
429 break; 429 break;
430 } 430 }
431 431
432 default: 432 default:
433 return false; 433 return false;
434 } 434 }
435 435
436 return true; 436 return true;
437 } 437 }
438 438
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 void SafeBrowsingProtocolManager::HandleGetHashError(const Time& now) { 658 void SafeBrowsingProtocolManager::HandleGetHashError(const Time& now) {
659 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_); 659 int next = GetNextBackOffTime(&gethash_error_count_, &gethash_back_off_mult_);
660 next_gethash_time_ = now + TimeDelta::FromSeconds(next); 660 next_gethash_time_ = now + TimeDelta::FromSeconds(next);
661 } 661 }
662 662
663 void SafeBrowsingProtocolManager::UpdateFinished(bool success) { 663 void SafeBrowsingProtocolManager::UpdateFinished(bool success) {
664 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_); 664 UMA_HISTOGRAM_COUNTS("SB2.UpdateSize", update_size_);
665 update_size_ = 0; 665 update_size_ = 0;
666 sb_service_->UpdateFinished(success); 666 sb_service_->UpdateFinished(success);
667 } 667 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.h ('k') | chrome/browser/safe_browsing/protocol_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698