OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // A class that encapsulates the detailed malware reports sent when | 9 // A class that encapsulates the detailed malware reports sent when |
10 // users opt-in to do so from the malware warning page. | 10 // users opt-in to do so from the malware warning page. |
11 | 11 |
12 // An instance of this class is generated when a malware warning page | 12 // An instance of this class is generated when a malware warning page |
13 // is shown (SafeBrowsingBlockingPage). | 13 // is shown (SafeBrowsingBlockingPage). |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/hash_tables.h" | 18 #include "base/hash_tables.h" |
19 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "chrome/browser/safe_browsing/report.pb.h" | 22 #include "chrome/browser/safe_browsing/report.pb.h" |
23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
24 #include "content/browser/browser_thread.h" | |
24 #include "content/browser/tab_contents/tab_contents_observer.h" | 25 #include "content/browser/tab_contents/tab_contents_observer.h" |
25 #include "net/base/completion_callback.h" | 26 #include "net/base/completion_callback.h" |
26 | 27 |
27 class TabContents; | 28 class TabContents; |
28 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node; | 29 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node; |
29 | 30 |
30 class MalwareDetailsCacheCollector; | 31 class MalwareDetailsCacheCollector; |
32 class MalwareDetailsRedirectsCollector; | |
31 class MalwareDetailsFactory; | 33 class MalwareDetailsFactory; |
32 | 34 |
33 namespace safe_browsing { | 35 namespace safe_browsing { |
34 // Maps a URL to its Resource. | 36 // Maps a URL to its Resource. |
35 typedef base::hash_map< | 37 typedef base::hash_map< |
36 std::string, | 38 std::string, |
37 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; | 39 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; |
38 } | 40 } |
39 | 41 |
40 class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>, | 42 class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>, |
41 public TabContentsObserver { | 43 public TabContentsObserver { |
42 public: | 44 public: |
43 // Constructs a new MalwareDetails instance, using the factory. | 45 // Constructs a new MalwareDetails instance, using the factory. |
44 static MalwareDetails* NewMalwareDetails( | 46 static MalwareDetails* NewMalwareDetails( |
45 SafeBrowsingService* sb_service, | 47 SafeBrowsingService* sb_service, |
46 TabContents* tab_contents, | 48 TabContents* tab_contents, |
47 const SafeBrowsingService::UnsafeResource& resource); | 49 const SafeBrowsingService::UnsafeResource& resource); |
48 | 50 |
49 // Makes the passed |factory| the factory used to instanciate | 51 // Makes the passed |factory| the factory used to instanciate |
50 // SafeBrowsingBlockingPage objects. Useful for tests. | 52 // SafeBrowsingBlockingPage objects. Useful for tests. |
51 static void RegisterFactory(MalwareDetailsFactory* factory) { | 53 static void RegisterFactory(MalwareDetailsFactory* factory) { |
52 factory_ = factory; | 54 factory_ = factory; |
53 } | 55 } |
54 | 56 |
55 // The SafeBrowsingBlockingPage calls this from the IO thread when | 57 // The SafeBrowsingBlockingPage calls this from the IO thread when |
56 // the user is leaving the blocking page and has opted-in to sending | 58 // the user is leaving the blocking page and has opted-in to sending |
57 // the report. We start the cache collection, and when we are done, | 59 // the report. We start the cache collection, and when we are done, |
58 // we send the report. | 60 // we send the report. |
mattm
2011/05/17 03:17:01
update this comment
kewang
2011/05/18 05:47:40
Done.
| |
59 void FinishCollection(); | 61 void FinishCollection(); |
60 | 62 |
61 void OnCacheCollectionReady(); | 63 void OnCacheCollectionReady(); |
62 | 64 |
65 void OnRedirectionCollectionReady(); | |
66 | |
63 // TabContentsObserver implementation. | 67 // TabContentsObserver implementation. |
64 virtual bool OnMessageReceived(const IPC::Message& message); | 68 virtual bool OnMessageReceived(const IPC::Message& message); |
65 | 69 |
66 protected: | 70 protected: |
67 friend class MalwareDetailsFactoryImpl; | 71 friend class MalwareDetailsFactoryImpl; |
68 | 72 |
69 MalwareDetails(SafeBrowsingService* sb_service, | 73 MalwareDetails(SafeBrowsingService* sb_service, |
70 TabContents* tab_contents, | 74 TabContents* tab_contents, |
71 const SafeBrowsingService::UnsafeResource& resource); | 75 const SafeBrowsingService::UnsafeResource& resource); |
72 | 76 |
(...skipping 28 matching lines...) Expand all Loading... | |
101 // relationship. |parent| and |tagname| can be empty, |children| can be NULL. | 105 // relationship. |parent| and |tagname| can be empty, |children| can be NULL. |
102 void AddUrl(const GURL& url, | 106 void AddUrl(const GURL& url, |
103 const GURL& parent, | 107 const GURL& parent, |
104 const std::string& tagname, | 108 const std::string& tagname, |
105 const std::vector<GURL>* children); | 109 const std::vector<GURL>* children); |
106 | 110 |
107 // Message handler. | 111 // Message handler. |
108 void OnReceivedMalwareDOMDetails( | 112 void OnReceivedMalwareDOMDetails( |
109 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); | 113 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); |
110 | 114 |
115 void AddRedirectUrlList(const std::vector<GURL>& urls); | |
116 | |
111 scoped_refptr<SafeBrowsingService> sb_service_; | 117 scoped_refptr<SafeBrowsingService> sb_service_; |
112 | 118 |
113 const SafeBrowsingService::UnsafeResource resource_; | 119 const SafeBrowsingService::UnsafeResource resource_; |
114 | 120 |
115 // For every Url we collect we create a Resource message. We keep | 121 // For every Url we collect we create a Resource message. We keep |
116 // them in a map so we can avoid duplicates. | 122 // them in a map so we can avoid duplicates. |
117 safe_browsing::ResourceMap resources_; | 123 safe_browsing::ResourceMap resources_; |
118 | 124 |
119 // Result from the cache extractor. | 125 // Result from the cache extractor. |
120 bool cache_result_; | 126 bool cache_result_; |
121 | 127 |
122 // The factory used to instanciate SafeBrowsingBlockingPage objects. | 128 // The factory used to instanciate SafeBrowsingBlockingPage objects. |
123 // Usefull for tests, so they can provide their own implementation of | 129 // Usefull for tests, so they can provide their own implementation of |
124 // SafeBrowsingBlockingPage. | 130 // SafeBrowsingBlockingPage. |
125 static MalwareDetailsFactory* factory_; | 131 static MalwareDetailsFactory* factory_; |
126 | 132 |
127 // Used to collect details from the HTTP Cache. | 133 // Used to collect details from the HTTP Cache. |
128 scoped_refptr<MalwareDetailsCacheCollector> cache_collector_; | 134 scoped_refptr<MalwareDetailsCacheCollector> cache_collector_; |
129 | 135 |
136 // Used to collect redirect urls from the history service | |
137 scoped_refptr<MalwareDetailsRedirectsCollector> redirects_collector_; | |
138 | |
130 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails); | 139 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails); |
131 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache); | 140 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache); |
132 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries); | 141 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries); |
142 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HistoryServiceUrls); | |
133 | 143 |
134 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); | 144 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); |
135 }; | 145 }; |
136 | 146 |
137 // Factory for creating MalwareDetails. Useful for tests. | 147 // Factory for creating MalwareDetails. Useful for tests. |
138 class MalwareDetailsFactory { | 148 class MalwareDetailsFactory { |
139 public: | 149 public: |
140 virtual ~MalwareDetailsFactory() { } | 150 virtual ~MalwareDetailsFactory() { } |
141 | 151 |
142 virtual MalwareDetails* CreateMalwareDetails( | 152 virtual MalwareDetails* CreateMalwareDetails( |
143 SafeBrowsingService* sb_service, | 153 SafeBrowsingService* sb_service, |
144 TabContents* tab_contents, | 154 TabContents* tab_contents, |
145 const SafeBrowsingService::UnsafeResource& unsafe_resource) = 0; | 155 const SafeBrowsingService::UnsafeResource& unsafe_resource) = 0; |
146 }; | 156 }; |
147 | 157 |
148 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ | 158 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
OLD | NEW |