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 ProtocolManagerFactory. | |
42 class ProtocolManagerFactoryImpl : public ProtocolManagerFactory { | |
43 public: | |
44 ProtocolManagerFactoryImpl() { } | |
45 virtual ~ProtocolManagerFactoryImpl() { } | |
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(ProtocolManagerFactoryImpl); | |
62 }; | |
41 | 63 |
42 // SafeBrowsingProtocolManager implementation ---------------------------------- | 64 // SafeBrowsingProtocolManager implementation ---------------------------------- |
43 | 65 |
66 // static | |
67 ProtocolManagerFactory* 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 if (!factory_) | |
Scott Hess - ex-Googler
2010/12/07 21:22:57
If this is thread-safe, tell me why, and maybe CHE
lzheng
2010/12/08 01:57:32
There should only be one protocol manager globally
| |
80 factory_ = new ProtocolManagerFactoryImpl(); | |
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 | |
44 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( | 87 SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( |
45 SafeBrowsingService* sb_service, | 88 SafeBrowsingService* sb_service, |
46 const std::string& client_name, | 89 const std::string& client_name, |
47 const std::string& client_key, | 90 const std::string& client_key, |
48 const std::string& wrapped_key, | 91 const std::string& wrapped_key, |
49 URLRequestContextGetter* request_context_getter, | 92 URLRequestContextGetter* request_context_getter, |
50 const std::string& info_url_prefix, | 93 const std::string& info_url_prefix, |
51 const std::string& mackey_url_prefix, | 94 const std::string& mackey_url_prefix, |
52 bool disable_auto_update) | 95 bool disable_auto_update) |
53 : sb_service_(sb_service), | 96 : 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 | 243 // so that it doesn't hold up the user's request indefinitely. Not sure |
201 // what to do at that point though! | 244 // what to do at that point though! |
202 full_hashes.clear(); | 245 full_hashes.clear(); |
203 } else { | 246 } else { |
204 if (re_key) | 247 if (re_key) |
205 HandleReKey(); | 248 HandleReKey(); |
206 } | 249 } |
207 } else { | 250 } else { |
208 HandleGetHashError(Time::Now()); | 251 HandleGetHashError(Time::Now()); |
209 if (status.status() == URLRequestStatus::FAILED) { | 252 if (status.status() == URLRequestStatus::FAILED) { |
210 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() | 253 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() |
211 << " failed with os error: " << status.os_error(); | 254 << " failed with os error: " << status.os_error(); |
212 } else { | 255 } else { |
213 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() | 256 VLOG(1) << "SafeBrowsing GetHash request for: " << source->url() |
214 << " failed with error: " << response_code; | 257 << " failed with error: " << response_code; |
215 } | 258 } |
216 } | 259 } |
217 | 260 |
218 // 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 |
219 // 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 |
220 // 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. |
221 sb_service_->HandleGetHashResults(check, full_hashes, can_cache); | 264 sb_service_->HandleGetHashResults(check, full_hashes, can_cache); |
222 | 265 |
223 hash_requests_.erase(it); | 266 hash_requests_.erase(it); |
224 } else { | 267 } else { |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
716 if (!additional_query_.empty()) { | 759 if (!additional_query_.empty()) { |
717 if (next_url.find("?") != std::string::npos) { | 760 if (next_url.find("?") != std::string::npos) { |
718 next_url.append("&"); | 761 next_url.append("&"); |
719 } else { | 762 } else { |
720 next_url.append("?"); | 763 next_url.append("?"); |
721 } | 764 } |
722 next_url.append(additional_query_); | 765 next_url.append(additional_query_); |
723 } | 766 } |
724 return GURL(next_url); | 767 return GURL(next_url); |
725 } | 768 } |
OLD | NEW |