| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
| 7 #pragma once |
| 8 |
| 9 // A class that gets malware details from the HTTP Cache. |
| 10 // An instance of this class is generated by MalwareDetails. |
| 11 |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
| 15 #include "base/hash_tables.h" |
| 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/ref_counted.h" |
| 18 #include "chrome/browser/safe_browsing/report.pb.h" |
| 19 #include "chrome/common/net/url_fetcher.h" |
| 20 #include "net/base/completion_callback.h" |
| 21 |
| 22 namespace net { |
| 23 class URLRequestContext; |
| 24 } |
| 25 |
| 26 class MalwareDetailsFactory; |
| 27 |
| 28 namespace safe_browsing { |
| 29 |
| 30 // Maps a URL to its Resource. |
| 31 typedef base::hash_map< |
| 32 std::string, |
| 33 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; |
| 34 } |
| 35 |
| 36 class MalwareDetailsCacheCollector |
| 37 : public base::RefCountedThreadSafe<MalwareDetailsCacheCollector>, |
| 38 public URLFetcher::Delegate { |
| 39 |
| 40 public: |
| 41 MalwareDetailsCacheCollector(); |
| 42 |
| 43 // friend class base::RefCountedThreadSafe<MalwareDetailsCacheCollector>; |
| 44 virtual ~MalwareDetailsCacheCollector(); |
| 45 |
| 46 // We use |request_context_getter|, we modify |resources| and |
| 47 // |result|, and we call |callback|, so they must all remain alive |
| 48 // for the lifetime of this object. |
| 49 void StartCacheCollection( |
| 50 net::URLRequestContextGetter* request_context_getter, |
| 51 safe_browsing::ResourceMap* resources, |
| 52 bool* result, |
| 53 Task* callback); |
| 54 |
| 55 // Returns whether or not StartCacheCollection has been called. |
| 56 bool HasStarted(); |
| 57 |
| 58 // Creates a new URLFetcher and starts it. Public because we create |
| 59 // a task to it, but not to be used by other classes. |
| 60 // tODO: needs to be public? |
| 61 void OpenEntry(); |
| 62 |
| 63 protected: |
| 64 // Implementation of URLFetcher::Delegate. Called after the request |
| 65 // completes (either successfully or with failure). |
| 66 virtual void OnURLFetchComplete(const URLFetcher* source, |
| 67 const GURL& url, |
| 68 const net::URLRequestStatus& status, |
| 69 int response_code, |
| 70 const ResponseCookies& cookies, |
| 71 const std::string& data); |
| 72 |
| 73 private: |
| 74 // Points to the url for which we are fetching the HTTP cache entry or |
| 75 // redirect chain. |
| 76 safe_browsing::ResourceMap::iterator resources_it_; |
| 77 |
| 78 // Points to the resources_ map in the MalwareDetails. |
| 79 safe_browsing::ResourceMap* resources_; |
| 80 |
| 81 // Points to the cache_result_ in the MalwareDetails. |
| 82 bool* result_; |
| 83 |
| 84 // Method we call when we are done. The caller must be alive for the |
| 85 // whole time, we are modifying its state (see above). |
| 86 Task* callback_; |
| 87 |
| 88 // Set to true as soon as StartCacheCollection is called. |
| 89 bool has_started_; |
| 90 |
| 91 // Used to get a pointer to the HTTP cache. |
| 92 net::URLRequestContextGetter* request_context_getter_; |
| 93 |
| 94 // The current URLFetcher. |
| 95 scoped_ptr<URLFetcher> current_fetch_; |
| 96 |
| 97 // Returns the resource from resources_ that corresponds to |url| |
| 98 safe_browsing::ClientMalwareReportRequest::Resource* GetResource( |
| 99 const GURL& url); |
| 100 |
| 101 // Read the HTTP response from |source| and add it to |pb_resource|. |
| 102 void ReadResponse( |
| 103 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource, |
| 104 const URLFetcher* source); |
| 105 |
| 106 // Read the body |data| and add it to |pb_resource|. |
| 107 void ReadData( |
| 108 safe_browsing::ClientMalwareReportRequest::Resource* pb_resource, |
| 109 const std::string& data); |
| 110 |
| 111 // Called when we are done. |
| 112 void AllDone(bool success); |
| 113 |
| 114 // Advances to the next entry in resources_it_. |
| 115 void AdvanceEntry(); |
| 116 }; |
| 117 |
| 118 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
| OLD | NEW |