| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 MalwareDetails(TabContents* tab_contents, | 29 MalwareDetails(TabContents* tab_contents, |
| 30 const SafeBrowsingService::UnsafeResource resource); | 30 const SafeBrowsingService::UnsafeResource resource); |
| 31 | 31 |
| 32 // The SafeBrowsingService calls this from the IO thread, to get the | 32 // The SafeBrowsingService calls this from the IO thread, to get the |
| 33 // serialized report as a string and send it over. | 33 // serialized report as a string and send it over. |
| 34 const std::string* GetSerializedReport(); | 34 const std::string* GetSerializedReport(); |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 friend class base::RefCountedThreadSafe<MalwareDetails>; | 37 friend class base::RefCountedThreadSafe<MalwareDetails>; |
| 38 | 38 |
| 39 // url -> Resource |
| 39 typedef base::hash_map< | 40 typedef base::hash_map< |
| 40 std::string, | 41 std::string, |
| 41 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > | 42 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > |
| 42 ResourceMap; | 43 ResourceMap; |
| 43 | 44 |
| 45 // id -> Node |
| 46 typedef base::hash_map< |
| 47 int, |
| 48 linked_ptr<safe_browsing::ClientMalwareReportRequest::Node> > |
| 49 NodeMap; |
| 50 |
| 44 // Starts the collection of the report. | 51 // Starts the collection of the report. |
| 45 void StartCollection(); | 52 void StartCollection(); |
| 46 | 53 |
| 47 // Whether the url is "public" so we can add it to the report. | 54 // Whether the url is "public" so we can add it to the report. |
| 48 bool IsPublicUrl(const GURL& url) const; | 55 bool IsPublicUrl(const GURL& url) const; |
| 49 | 56 |
| 50 // Adds a node to |urls_|. |parent| can be empty. | 57 // Finds an existing Resource and Node for the given url, or creates a new one |
| 51 void AddNode(const std::string& url, const std::string& parent); | 58 // if not found, and adds them to |resources_| and |nodes_| respectively. |
| 59 // Updates |resource| and |node|. |
| 60 // Note: We create exactly one Node for each Resource. |
| 61 void FindOrCreateResource( |
| 62 const std::string& url, |
| 63 safe_browsing::ClientMalwareReportRequest::Resource** resource, |
| 64 safe_browsing::ClientMalwareReportRequest::Node** node); |
| 65 |
| 66 // Adds a Resource and Node to resources_ and nodes_ with the given |
| 67 // parent relationship. If a Node already exist, and |parent| is |
| 68 // non-empty, it updates the Node's parent field. |
| 69 void AddUrl(const std::string& url, const std::string& parent); |
| 52 | 70 |
| 53 ~MalwareDetails(); | 71 ~MalwareDetails(); |
| 54 | 72 |
| 55 TabContents* tab_contents_; | 73 TabContents* tab_contents_; |
| 56 const SafeBrowsingService::UnsafeResource resource_; | 74 const SafeBrowsingService::UnsafeResource resource_; |
| 57 | 75 |
| 58 // The urls that we collect. We first add them into this map and then | 76 // For every Url we collect we create a Resource message. We keep |
| 59 // generate a protocol buffer from it. | 77 // them in a map so we can avoid duplicates. Currently a Resource is |
| 60 ResourceMap urls_; | 78 // a (Url, id) pair. |
| 79 ResourceMap resources_; |
| 80 |
| 81 // Each Resource has a corresponding Node (keyed by the id) that |
| 82 // knows the parent id of the resource. |
| 83 NodeMap nodes_; |
| 61 | 84 |
| 62 // The report protocol buffer. | 85 // The report protocol buffer. |
| 63 scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_; | 86 scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_; |
| 64 | 87 |
| 65 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); | 88 DISALLOW_COPY_AND_ASSIGN(MalwareDetails); |
| 66 }; | 89 }; |
| 67 | 90 |
| 68 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ | 91 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_H_ |
| OLD | NEW |