OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MALWARE_DETAILS_CACHE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // A class that gets malware details from the HTTP Cache. | 9 // A class that gets malware details from the HTTP Cache. |
10 // An instance of this class is generated by MalwareDetails. | 10 // An instance of this class is generated by MalwareDetails. |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "chrome/browser/safe_browsing/report.pb.h" | 19 #include "chrome/browser/safe_browsing/report.pb.h" |
20 #include "content/public/common/url_fetcher_delegate.h" | |
21 #include "net/base/completion_callback.h" | 20 #include "net/base/completion_callback.h" |
| 21 #include "net/url_request/url_fetcher_delegate.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
| 24 class URLFetcher; |
24 class URLRequestContext; | 25 class URLRequestContext; |
25 } | 26 } |
26 | 27 |
27 namespace safe_browsing { | 28 namespace safe_browsing { |
28 | 29 |
29 // Maps a URL to its Resource. | 30 // Maps a URL to its Resource. |
30 typedef base::hash_map< | 31 typedef base::hash_map< |
31 std::string, | 32 std::string, |
32 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; | 33 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; |
33 } | 34 } |
34 | 35 |
35 class MalwareDetailsCacheCollector | 36 class MalwareDetailsCacheCollector |
36 : public base::RefCountedThreadSafe<MalwareDetailsCacheCollector>, | 37 : public base::RefCountedThreadSafe<MalwareDetailsCacheCollector>, |
37 public content::URLFetcherDelegate { | 38 public net::URLFetcherDelegate { |
38 | 39 |
39 public: | 40 public: |
40 MalwareDetailsCacheCollector(); | 41 MalwareDetailsCacheCollector(); |
41 | 42 |
42 // We use |request_context_getter|, we modify |resources| and | 43 // We use |request_context_getter|, we modify |resources| and |
43 // |result|, and we call |callback|, so they must all remain alive | 44 // |result|, and we call |callback|, so they must all remain alive |
44 // for the lifetime of this object. | 45 // for the lifetime of this object. |
45 void StartCacheCollection( | 46 void StartCacheCollection( |
46 net::URLRequestContextGetter* request_context_getter, | 47 net::URLRequestContextGetter* request_context_getter, |
47 safe_browsing::ResourceMap* resources, | 48 safe_browsing::ResourceMap* resources, |
(...skipping 27 matching lines...) Expand all Loading... |
75 // whole time, we are modifying its state (see above). | 76 // whole time, we are modifying its state (see above). |
76 base::Closure callback_; | 77 base::Closure callback_; |
77 | 78 |
78 // Set to true as soon as StartCacheCollection is called. | 79 // Set to true as soon as StartCacheCollection is called. |
79 bool has_started_; | 80 bool has_started_; |
80 | 81 |
81 // Used to get a pointer to the current request context. | 82 // Used to get a pointer to the current request context. |
82 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 83 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
83 | 84 |
84 // The current URLFetcher. | 85 // The current URLFetcher. |
85 scoped_ptr<content::URLFetcher> current_fetch_; | 86 scoped_ptr<net::URLFetcher> current_fetch_; |
86 | 87 |
87 // Returns the resource from resources_ that corresponds to |url| | 88 // Returns the resource from resources_ that corresponds to |url| |
88 safe_browsing::ClientMalwareReportRequest::Resource* GetResource( | 89 safe_browsing::ClientMalwareReportRequest::Resource* GetResource( |
89 const GURL& url); | 90 const GURL& url); |
90 | 91 |
91 // Creates a new URLFetcher and starts it. | 92 // Creates a new URLFetcher and starts it. |
92 void OpenEntry(); | 93 void OpenEntry(); |
93 | 94 |
94 // Read the HTTP response from |source| and add it to |pb_resource|. | 95 // Read the HTTP response from |source| and add it to |pb_resource|. |
95 void ReadResponse( | 96 void ReadResponse( |
96 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource, | 97 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource, |
97 const net::URLFetcher* source); | 98 const net::URLFetcher* source); |
98 | 99 |
99 // Read the body |data| and add it to |pb_resource|. | 100 // Read the body |data| and add it to |pb_resource|. |
100 void ReadData( | 101 void ReadData( |
101 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource, | 102 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource, |
102 const std::string& data); | 103 const std::string& data); |
103 | 104 |
104 // Called when we are done. | 105 // Called when we are done. |
105 void AllDone(bool success); | 106 void AllDone(bool success); |
106 | 107 |
107 // Advances to the next entry in resources_it_. | 108 // Advances to the next entry in resources_it_. |
108 void AdvanceEntry(); | 109 void AdvanceEntry(); |
109 }; | 110 }; |
110 | 111 |
111 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ | 112 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
OLD | NEW |