OLD | NEW |
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 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
7 | 7 |
8 // A class that implements Chrome's interface with the SafeBrowsing protocol. | 8 // A class that implements Chrome's interface with the SafeBrowsing protocol. |
9 // The SafeBrowsingProtocolManager handles formatting and making requests of, | 9 // The SafeBrowsingProtocolManager handles formatting and making requests of, |
10 // and handling responses from, Google's SafeBrowsing servers. This class uses | 10 // and handling responses from, Google's SafeBrowsing servers. This class uses |
11 // The SafeBrowsingProtocolParser class to do the actual parsing. | 11 // The SafeBrowsingProtocolParser class to do the actual parsing. |
12 | 12 |
13 #include <deque> | 13 #include <deque> |
14 #include <set> | 14 #include <set> |
15 | 15 |
16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/timer.h" | 19 #include "base/timer.h" |
20 #include "chrome/browser/net/url_fetcher.h" | 20 #include "chrome/browser/net/url_fetcher.h" |
21 #include "chrome/browser/safe_browsing/chunk_range.h" | 21 #include "chrome/browser/safe_browsing/chunk_range.h" |
22 #include "chrome/browser/safe_browsing/protocol_parser.h" | 22 #include "chrome/browser/safe_browsing/protocol_parser.h" |
23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
24 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
25 #include "testing/gtest/include/gtest/gtest_prod.h" | 25 #include "testing/gtest/include/gtest/gtest_prod.h" |
26 | 26 |
27 class MessageLoop; | |
28 class Task; | 27 class Task; |
29 class Timer; | 28 class Timer; |
30 class URLRequestStatus; | 29 class URLRequestStatus; |
31 | 30 |
32 #if defined(COMPILER_GCC) | 31 #if defined(COMPILER_GCC) |
33 // Allows us to use URLFetchers in a hash_map with gcc (MSVC is okay without | 32 // Allows us to use URLFetchers in a hash_map with gcc (MSVC is okay without |
34 // specifying this). | 33 // specifying this). |
35 namespace __gnu_cxx { | 34 namespace __gnu_cxx { |
36 template<> | 35 template<> |
37 struct hash<const URLFetcher*> { | 36 struct hash<const URLFetcher*> { |
38 size_t operator()(const URLFetcher* fetcher) const { | 37 size_t operator()(const URLFetcher* fetcher) const { |
39 return reinterpret_cast<size_t>(fetcher); | 38 return reinterpret_cast<size_t>(fetcher); |
40 } | 39 } |
41 }; | 40 }; |
42 } | 41 } |
43 #endif | 42 #endif |
44 | 43 |
45 class SafeBrowsingProtocolManager : public URLFetcher::Delegate { | 44 class SafeBrowsingProtocolManager : public URLFetcher::Delegate { |
46 // Testing friends: | 45 // Testing friends: |
47 FRIEND_TEST(SafeBrowsingProtocolManagerTest, TestBackOffTimes); | 46 FRIEND_TEST(SafeBrowsingProtocolManagerTest, TestBackOffTimes); |
48 FRIEND_TEST(SafeBrowsingProtocolManagerTest, TestChunkStrings); | 47 FRIEND_TEST(SafeBrowsingProtocolManagerTest, TestChunkStrings); |
49 FRIEND_TEST(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes); | 48 FRIEND_TEST(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes); |
50 | 49 |
51 public: | 50 public: |
52 SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, | 51 SafeBrowsingProtocolManager(SafeBrowsingService* sb_service, |
53 MessageLoop* notify_loop, | |
54 const std::string& client_key, | 52 const std::string& client_key, |
55 const std::string& wrapped_key); | 53 const std::string& wrapped_key); |
56 ~SafeBrowsingProtocolManager(); | 54 ~SafeBrowsingProtocolManager(); |
57 | 55 |
58 // Set up the update schedule and internal state for making periodic requests | 56 // Set up the update schedule and internal state for making periodic requests |
59 // of the SafeBrowsing service. | 57 // of the SafeBrowsing service. |
60 void Initialize(); | 58 void Initialize(); |
61 | 59 |
62 // URLFetcher::Delegate interface. | 60 // URLFetcher::Delegate interface. |
63 virtual void OnURLFetchComplete(const URLFetcher* source, | 61 virtual void OnURLFetchComplete(const URLFetcher* source, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 203 |
206 // We'll attempt to get keys once per browser session if we don't already have | 204 // We'll attempt to get keys once per browser session if we don't already have |
207 // them. They are not essential to operation, but provide a layer of | 205 // them. They are not essential to operation, but provide a layer of |
208 // verification. | 206 // verification. |
209 bool initial_request_; | 207 bool initial_request_; |
210 | 208 |
211 // True if the service has been given an add/sub chunk but it hasn't been | 209 // True if the service has been given an add/sub chunk but it hasn't been |
212 // added to the database yet. | 210 // added to the database yet. |
213 bool chunk_pending_to_write_; | 211 bool chunk_pending_to_write_; |
214 | 212 |
215 // Message loop for forwarding MAC keys to the SafeBrowsingService for | |
216 // storage. | |
217 MessageLoop* notify_loop_; | |
218 | |
219 // The keys used for MAC. Empty keys mean we aren't using MAC. | 213 // The keys used for MAC. Empty keys mean we aren't using MAC. |
220 std::string client_key_; | 214 std::string client_key_; |
221 std::string wrapped_key_; | 215 std::string wrapped_key_; |
222 | 216 |
223 // The last time we successfully received an update. | 217 // The last time we successfully received an update. |
224 base::Time last_update_; | 218 base::Time last_update_; |
225 | 219 |
226 // While in GetHash backoff, we can't make another GetHash until this time. | 220 // While in GetHash backoff, we can't make another GetHash until this time. |
227 base::Time next_gethash_time_; | 221 base::Time next_gethash_time_; |
228 | 222 |
229 // Current product version sent in each request. | 223 // Current product version sent in each request. |
230 std::string version_; | 224 std::string version_; |
231 | 225 |
232 // Used for measuring chunk request latency. | 226 // Used for measuring chunk request latency. |
233 base::Time chunk_request_start_; | 227 base::Time chunk_request_start_; |
234 | 228 |
235 // Track the size of each update (in bytes). | 229 // Track the size of each update (in bytes). |
236 int update_size_; | 230 int update_size_; |
237 | 231 |
238 // Track outstanding malware report fetchers for clean up. | 232 // Track outstanding malware report fetchers for clean up. |
239 std::set<const URLFetcher*> malware_reports_; | 233 std::set<const URLFetcher*> malware_reports_; |
240 | 234 |
241 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); | 235 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); |
242 }; | 236 }; |
243 | 237 |
244 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 238 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
OLD | NEW |