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