Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: chrome/browser/safe_browsing/malware_details.h

Issue 6611023: The optional Malware Details also collects HTTP cache information. See design... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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). It is passed on to the 13 // is shown (SafeBrowsingBlockingPage).
14 // SafeBrowsing service when the warning goes away.
15 14
16 #include <string> 15 #include <string>
17 #include <vector> 16 #include <vector>
18 17
19 #include "base/hash_tables.h" 18 #include "base/hash_tables.h"
20 #include "base/memory/linked_ptr.h" 19 #include "base/memory/linked_ptr.h"
21 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
22 #include "chrome/browser/safe_browsing/report.pb.h" 21 #include "chrome/browser/safe_browsing/report.pb.h"
23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
24 #include "content/browser/tab_contents/tab_contents_observer.h" 23 #include "content/browser/tab_contents/tab_contents_observer.h"
24 #include "net/base/completion_callback.h"
25 25
26 class TabContents; 26 class TabContents;
27 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node; 27 struct SafeBrowsingHostMsg_MalwareDOMDetails_Node;
28 28
29 class MalwareDetailsCacheCollector;
29 class MalwareDetailsFactory; 30 class MalwareDetailsFactory;
30 31
32 namespace safe_browsing {
33 // Maps a URL to its Resource.
34 typedef base::hash_map<
35 std::string,
36 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap;
37 }
38
31 class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>, 39 class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>,
32 public TabContentsObserver { 40 public TabContentsObserver {
33 public: 41 public:
34 // Constructs a new MalwareDetails instance, using the factory. 42 // Constructs a new MalwareDetails instance, using the factory.
35 static MalwareDetails* NewMalwareDetails( 43 static MalwareDetails* NewMalwareDetails(
44 SafeBrowsingService* sb_service,
36 TabContents* tab_contents, 45 TabContents* tab_contents,
37 const SafeBrowsingService::UnsafeResource& resource); 46 const SafeBrowsingService::UnsafeResource& resource);
38 47
39 // Makes the passed |factory| the factory used to instanciate 48 // Makes the passed |factory| the factory used to instanciate
40 // SafeBrowsingBlockingPage objects. Useful for tests. 49 // SafeBrowsingBlockingPage objects. Useful for tests.
41 static void RegisterFactory(MalwareDetailsFactory* factory) { 50 static void RegisterFactory(MalwareDetailsFactory* factory) {
42 factory_ = factory; 51 factory_ = factory;
43 } 52 }
44 53
45 // The SafeBrowsingService calls this from the IO thread, to get the 54 // The SafeBrowsingBlockingPage calls this from the IO thread when
46 // serialized report as a string and send it over. 55 // the user is leaving the blocking page and has opted-in to sending
47 const std::string* GetSerializedReport(); 56 // the report. We start the cache collection, and when we are done,
57 // we send the report.
58 void FinishCollection();
59
60 void OnCacheCollectionReady();
48 61
49 // TabContentsObserver implementation. 62 // TabContentsObserver implementation.
50 virtual bool OnMessageReceived(const IPC::Message& message); 63 virtual bool OnMessageReceived(const IPC::Message& message);
51 64
52 protected: 65 protected:
53 friend class MalwareDetailsFactoryImpl; 66 friend class MalwareDetailsFactoryImpl;
54 67
55 MalwareDetails(TabContents* tab_contents, 68 MalwareDetails(SafeBrowsingService* sb_service,
69 TabContents* tab_contents,
56 const SafeBrowsingService::UnsafeResource& resource); 70 const SafeBrowsingService::UnsafeResource& resource);
57 71
72 virtual ~MalwareDetails();
73
58 // Called on the IO thread with the DOM details. 74 // Called on the IO thread with the DOM details.
59 virtual void AddDOMDetails( 75 virtual void AddDOMDetails(
60 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); 76 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params);
61 77
62 virtual ~MalwareDetails(); 78 // The report protocol buffer.
79 scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_;
80
81 // Used to get a pointer to the HTTP cache.
82 URLRequestContextGetter* request_context_getter_;
63 83
64 private: 84 private:
65 friend class base::RefCountedThreadSafe<MalwareDetails>; 85 friend class base::RefCountedThreadSafe<MalwareDetails>;
66 86
67 // Maps a URL to its Resource.
68 typedef base::hash_map<
69 std::string,
70 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> >
71 ResourceMap;
72
73 // Starts the collection of the report. 87 // Starts the collection of the report.
74 void StartCollection(); 88 void StartCollection();
75 89
76 // Whether the url is "public" so we can add it to the report. 90 // Whether the url is "public" so we can add it to the report.
77 bool IsPublicUrl(const GURL& url) const; 91 bool IsPublicUrl(const GURL& url) const;
78 92
79 // Finds an existing Resource for the given url, or creates a new 93 // Finds an existing Resource for the given url, or creates a new
80 // one if not found, and adds it to |resources_|. Returns the 94 // one if not found, and adds it to |resources_|. Returns the
81 // found/created resource. 95 // found/created resource.
82 safe_browsing::ClientMalwareReportRequest::Resource* FindOrCreateResource( 96 safe_browsing::ClientMalwareReportRequest::Resource* FindOrCreateResource(
83 const GURL& url); 97 const GURL& url);
84 98
85 // Adds a Resource to resources_ with the given parent-child 99 // Adds a Resource to resources_ with the given parent-child
86 // relationship. |parent| and |tagname| can be empty, |children| can be NULL. 100 // relationship. |parent| and |tagname| can be empty, |children| can be NULL.
87 void AddUrl(const GURL& url, 101 void AddUrl(const GURL& url,
88 const GURL& parent, 102 const GURL& parent,
89 const std::string& tagname, 103 const std::string& tagname,
90 const std::vector<GURL>* children); 104 const std::vector<GURL>* children);
91 105
92 // Message handler. 106 // Message handler.
93 void OnReceivedMalwareDOMDetails( 107 void OnReceivedMalwareDOMDetails(
94 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params); 108 const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params);
95 109
110 SafeBrowsingService* sb_service_;
noelutz 2011/04/06 20:34:19 I think you need a scoped ref pointer here just to
panayiotis 2011/04/07 20:08:32 Done.
111
96 const SafeBrowsingService::UnsafeResource resource_; 112 const SafeBrowsingService::UnsafeResource resource_;
97 113
98 // For every Url we collect we create a Resource message. We keep 114 // For every Url we collect we create a Resource message. We keep
99 // them in a map so we can avoid duplicates. 115 // them in a map so we can avoid duplicates.
100 ResourceMap resources_; 116 safe_browsing::ResourceMap resources_;
101 117
102 // The report protocol buffer. 118 // Result from the cache extractor.
103 scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_; 119 int cache_result_;
104 120
105 // The factory used to instanciate SafeBrowsingBlockingPage objects. 121 // The factory used to instanciate SafeBrowsingBlockingPage objects.
106 // Usefull for tests, so they can provide their own implementation of 122 // Usefull for tests, so they can provide their own implementation of
107 // SafeBrowsingBlockingPage. 123 // SafeBrowsingBlockingPage.
108 static MalwareDetailsFactory* factory_; 124 static MalwareDetailsFactory* factory_;
109 125
126 // Used to collect details from the HTTP Cache.
127 scoped_refptr<MalwareDetailsCacheCollector> cache_collector_;
128
110 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails); 129 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails);
130 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache);
131 FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries);
111 132
112 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); 133 DISALLOW_COPY_AND_ASSIGN(MalwareDetails);
113 }; 134 };
114 135
115 // Factory for creating MalwareDetails. Useful for tests. 136 // Factory for creating MalwareDetails. Useful for tests.
116 class MalwareDetailsFactory { 137 class MalwareDetailsFactory {
117 public: 138 public:
118 virtual ~MalwareDetailsFactory() { } 139 virtual ~MalwareDetailsFactory() { }
119 140
120 virtual MalwareDetails* CreateMalwareDetails( 141 virtual MalwareDetails* CreateMalwareDetails(
142 SafeBrowsingService* sb_service,
121 TabContents* tab_contents, 143 TabContents* tab_contents,
122 const SafeBrowsingService::UnsafeResource& unsafe_resource) = 0; 144 const SafeBrowsingService::UnsafeResource& unsafe_resource) = 0;
123 }; 145 };
124 146
125 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ 147 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/malware_details.cc » ('j') | chrome/browser/safe_browsing/malware_details.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698