| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // Maximum time, in seconds, from start up before we must issue an update query. | 32 // Maximum time, in seconds, from start up before we must issue an update query. |
| 33 static const int kSbTimerStartIntervalSec = 5 * 60; | 33 static const int kSbTimerStartIntervalSec = 5 * 60; |
| 34 | 34 |
| 35 // The maximum time, in seconds, to wait for a response to an update request. | 35 // The maximum time, in seconds, to wait for a response to an update request. |
| 36 static const int kSbMaxUpdateWaitSec = 10; | 36 static const int kSbMaxUpdateWaitSec = 10; |
| 37 | 37 |
| 38 // Maximum back off multiplier. | 38 // Maximum back off multiplier. |
| 39 static const int kSbMaxBackOff = 8; | 39 static const int kSbMaxBackOff = 8; |
| 40 | 40 |
| 41 // The default SBProtocolManagerFactory. |
| 42 class SBProtocolManagerFactoryImpl : public SBProtocolManagerFactory { |
| 43 public: |
| 44 SBProtocolManagerFactoryImpl() { } |
| 45 virtual ~SBProtocolManagerFactoryImpl() { } |
| 46 virtual SafeBrowsingProtocolManager* CreateProtocolManager( |
| 47 SafeBrowsingService* sb_service, |
| 48 const std::string& client_name, |
| 49 const std::string& client_key, |
| 50 const std::string& wrapped_key, |
| 51 URLRequestContextGetter* request_context_getter, |
| 52 const std::string& info_url_prefix, |
| 53 const std::string& mackey_url_prefix, |
| 54 bool disable_auto_update) { |
| 55 return new SafeBrowsingProtocolManager( |
| 56 sb_service, client_name, client_key, wrapped_key, |
| 57 request_context_getter, info_url_prefix, mackey_url_prefix, |
| 58 disable_auto_update); |
| 59 } |
| 60 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactoryImpl); |
| 62 }; |
| 41 | 63 |
| 42 // SafeBrowsingProtocolManager implementation ---------------------------------- | 64 // SafeBrowsingProtocolManager implementation ---------------------------------- |
| 43 | 65 |
| 66 // static |
| 67 SBProtocolManagerFactory* SafeBrowsingProtocolManager::factory_ = NULL; |
| 68 |
| 69 // static |
| 70 SafeBrowsingProtocolManager* SafeBrowsingProtocolManager::Create( |
| 71 SafeBrowsingService* sb_service, |
| 72 const std::string& client_name, |
| 73 const std::string& client_key, |
| 74 const std::string& wrapped_key, |
| 75 URLRequestContextGetter* request_context_getter, |
| 76 const std::string& info_url_prefix, |
| 77 const std::string& mackey_url_prefix, |
| 78 bool disable_auto_update) { |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 80 if (!factory_) |
| 81 factory_ = new SBProtocolManagerFactoryImpl(); |
| 82 return factory_->CreateProtocolManager(sb_service, client_name, client_key, |
| 83 wrapped_key, request_context_getter, |
| 84 info_url_prefix, mackey_url_prefix, |
| 85 disable_auto_update); |
| 86 } |
| 87 |
| 44 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( | 88 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( |
| 45 SafeBrowsingService* sb_service, | 89 SafeBrowsingService* sb_service, |
| 46 const std::string& client_name, | 90 const std::string& client_name, |
| 47 const std::string& client_key, | 91 const std::string& client_key, |
| 48 const std::string& wrapped_key, | 92 const std::string& wrapped_key, |
| 49 URLRequestContextGetter* request_context_getter, | 93 URLRequestContextGetter* request_context_getter, |
| 50 const std::string& info_url_prefix, | 94 const std::string& info_url_prefix, |
| 51 const std::string& mackey_url_prefix, | 95 const std::string& mackey_url_prefix, |
| 52 bool disable_auto_update) | 96 bool disable_auto_update) |
| 53 : sb_service_(sb_service), | 97 : sb_service_(sb_service), |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // so that it doesn't hold up the user's request indefinitely. Not sure | 244 // so that it doesn't hold up the user's request indefinitely. Not sure |
| 201 // what to do at that point though! | 245 // what to do at that point though! |
| 202 full_hashes.clear(); | 246 full_hashes.clear(); |
| 203 } else { | 247 } else { |
| 204 if (re_key) | 248 if (re_key) |
| 205 HandleReKey(); | 249 HandleReKey(); |
| 206 } | 250 } |
| 207 } else { | 251 } else { |
| 208 HandleGetHashError(Time::Now()); | 252 HandleGetHashError(Time::Now()); |
| 209 if (status.status() == URLRequestStatus::FAILED) { | 253 if (status.status() == URLRequestStatus::FAILED) { |
| 210 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() | 254 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() |
| 211 << " failed with os error: " << status.os_error(); | 255 << " failed with os error: " << status.os_error(); |
| 212 } else { | 256 } else { |
| 213 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() | 257 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() |
| 214 << " failed with error: " << response_code; | 258 << " failed with error: " << response_code; |
| 215 } | 259 } |
| 216 } | 260 } |
| 217 | 261 |
| 218 // Call back the SafeBrowsingService with full_hashes, even if there was a | 262 // Call back the SafeBrowsingService with full_hashes, even if there was a |
| 219 // parse error or an error response code (in which case full_hashes will be | 263 // parse error or an error response code (in which case full_hashes will be |
| 220 // empty). We can't block the user regardless of the error status. | 264 // empty). We can't block the user regardless of the error status. |
| 221 sb_service_->HandleGetHashResults(check, full_hashes, can_cache); | 265 sb_service_->HandleGetHashResults(check, full_hashes, can_cache); |
| 222 | 266 |
| 223 hash_requests_.erase(it); | 267 hash_requests_.erase(it); |
| 224 } else { | 268 } else { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 if (!additional_query_.empty()) { | 760 if (!additional_query_.empty()) { |
| 717 if (next_url.find("?") != std::string::npos) { | 761 if (next_url.find("?") != std::string::npos) { |
| 718 next_url.append("&"); | 762 next_url.append("&"); |
| 719 } else { | 763 } else { |
| 720 next_url.append("?"); | 764 next_url.append("?"); |
| 721 } | 765 } |
| 722 next_url.append(additional_query_); | 766 next_url.append(additional_query_); |
| 723 } | 767 } |
| 724 return GURL(next_url); | 768 return GURL(next_url); |
| 725 } | 769 } |
| OLD | NEW |