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

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

Issue 2784253004: Componentize safe_browsing: decouple threat_details* from the chrome/ layer. (Closed)
Patch Set: fix compile for browser tests Created 3 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
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_THREAT_DETAILS_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_
7 7
8 // A class that encapsulates the detailed threat reports sent when 8 // A class that encapsulates the detailed threat reports sent when
9 // users opt-in to do so from the safe browsing warning page. 9 // users opt-in to do so from the safe browsing warning page.
10 10
11 // An instance of this class is generated when a safe browsing warning page 11 // An instance of this class is generated when a safe browsing warning page
12 // is shown (SafeBrowsingBlockingPage). 12 // is shown (SafeBrowsingBlockingPage).
13 13
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <unordered_set> 16 #include <unordered_set>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/containers/hash_tables.h" 19 #include "base/containers/hash_tables.h"
20 #include "base/gtest_prod_util.h" 20 #include "base/gtest_prod_util.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/memory/ref_counted.h" 22 #include "base/memory/ref_counted.h"
23 #include "chrome/browser/safe_browsing/ui_manager.h" 23 #include "components/safe_browsing/base_ui_manager.h"
Jialiu Lin 2017/04/07 18:42:05 nit: Maybe use a forward declaration here. and put
timvolodine 2017/04/10 15:02:55 yes indeed. done. (still required unsafe_resource.
24 #include "components/safe_browsing/common/safebrowsing_types.h" 24 #include "components/safe_browsing/common/safebrowsing_types.h"
25 #include "components/safe_browsing/csd.pb.h" 25 #include "components/safe_browsing/csd.pb.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/web_contents_observer.h" 27 #include "content/public/browser/web_contents_observer.h"
28 #include "net/base/completion_callback.h" 28 #include "net/base/completion_callback.h"
29 29
30 namespace net { 30 namespace net {
31 class URLRequestContextGetter; 31 class URLRequestContextGetter;
32 } 32 }
33 33
34 class Profile;
35 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node; 34 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node;
36 35
37 namespace safe_browsing { 36 namespace safe_browsing {
38 37
39 // Maps a URL to its Resource. 38 // Maps a URL to its Resource.
40 class ThreatDetailsCacheCollector; 39 class ThreatDetailsCacheCollector;
41 class ThreatDetailsRedirectsCollector; 40 class ThreatDetailsRedirectsCollector;
42 class ThreatDetailsFactory; 41 class ThreatDetailsFactory;
43 42
44 using ResourceMap = 43 using ResourceMap =
(...skipping 20 matching lines...) Expand all
65 using UrlToChildIdsMap = base::hash_map<std::string, std::unordered_set<int>>; 64 using UrlToChildIdsMap = base::hash_map<std::string, std::unordered_set<int>>;
66 65
67 class ThreatDetails : public base::RefCountedThreadSafe< 66 class ThreatDetails : public base::RefCountedThreadSafe<
68 ThreatDetails, 67 ThreatDetails,
69 content::BrowserThread::DeleteOnUIThread>, 68 content::BrowserThread::DeleteOnUIThread>,
70 public content::WebContentsObserver { 69 public content::WebContentsObserver {
71 public: 70 public:
72 typedef security_interstitials::UnsafeResource UnsafeResource; 71 typedef security_interstitials::UnsafeResource UnsafeResource;
73 72
74 // Constructs a new ThreatDetails instance, using the factory. 73 // Constructs a new ThreatDetails instance, using the factory.
75 static ThreatDetails* NewThreatDetails(BaseUIManager* ui_manager, 74 static ThreatDetails* NewThreatDetails(
76 content::WebContents* web_contents, 75 BaseUIManager* ui_manager,
77 const UnsafeResource& resource); 76 content::WebContents* web_contents,
77 const UnsafeResource& resource,
78 net::URLRequestContextGetter* request_context_getter,
79 history::HistoryService* history_service);
78 80
79 // Makes the passed |factory| the factory used to instanciate 81 // Makes the passed |factory| the factory used to instanciate
80 // SafeBrowsingBlockingPage objects. Useful for tests. 82 // SafeBrowsingBlockingPage objects. Useful for tests.
81 static void RegisterFactory(ThreatDetailsFactory* factory) { 83 static void RegisterFactory(ThreatDetailsFactory* factory) {
82 factory_ = factory; 84 factory_ = factory;
83 } 85 }
84 86
85 // The SafeBrowsingBlockingPage calls this from the IO thread when 87 // The SafeBrowsingBlockingPage calls this from the IO thread when
86 // the user is leaving the blocking page and has opted-in to sending 88 // the user is leaving the blocking page and has opted-in to sending
87 // the report. We start the redirection urls collection from history service 89 // the report. We start the redirection urls collection from history service
88 // in UI thread; then do cache collection back in IO thread. We also record 90 // in UI thread; then do cache collection back in IO thread. We also record
89 // if the user did proceed with the warning page, and how many times user 91 // if the user did proceed with the warning page, and how many times user
90 // visited this page before. When we are done, we send the report. 92 // visited this page before. When we are done, we send the report.
91 void FinishCollection(bool did_proceed, int num_visits); 93 void FinishCollection(bool did_proceed, int num_visits);
92 94
93 void OnCacheCollectionReady(); 95 void OnCacheCollectionReady();
94 96
95 void OnRedirectionCollectionReady(); 97 void OnRedirectionCollectionReady();
96 98
97 // content::WebContentsObserver implementation. 99 // content::WebContentsObserver implementation.
98 bool OnMessageReceived(const IPC::Message& message, 100 bool OnMessageReceived(const IPC::Message& message,
99 content::RenderFrameHost* render_frame_host) override; 101 content::RenderFrameHost* render_frame_host) override;
100 102
101 protected: 103 protected:
102 friend class ThreatDetailsFactoryImpl; 104 friend class ThreatDetailsFactoryImpl;
103 friend class TestThreatDetailsFactory; 105 friend class TestThreatDetailsFactory;
104 106
105 ThreatDetails(BaseUIManager* ui_manager, 107 ThreatDetails(BaseUIManager* ui_manager,
106 content::WebContents* web_contents, 108 content::WebContents* web_contents,
107 const UnsafeResource& resource); 109 const UnsafeResource& resource,
110 net::URLRequestContextGetter* request_context_getter,
111 history::HistoryService* history_service);
108 112
109 ~ThreatDetails() override; 113 ~ThreatDetails() override;
110 114
111 // Called on the IO thread with the DOM details. 115 // Called on the IO thread with the DOM details.
112 virtual void AddDOMDetails( 116 virtual void AddDOMDetails(
113 const int frame_tree_node_id, 117 const int frame_tree_node_id,
114 const GURL& frame_last_committed_url, 118 const GURL& frame_last_committed_url,
115 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); 119 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params);
116 120
117 Profile* profile_;
118
119 // The report protocol buffer. 121 // The report protocol buffer.
120 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; 122 std::unique_ptr<ClientSafeBrowsingReportRequest> report_;
121 123
122 // Used to get a pointer to the HTTP cache. 124 // Used to get a pointer to the HTTP cache.
123 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 125 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
124 126
125 private: 127 private:
126 friend class base::RefCountedThreadSafe<ThreatDetails>; 128 friend class base::RefCountedThreadSafe<ThreatDetails>;
127 friend struct content::BrowserThread::DeleteOnThread< 129 friend struct content::BrowserThread::DeleteOnThread<
128 content::BrowserThread::UI>; 130 content::BrowserThread::UI>;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 }; 239 };
238 240
239 // Factory for creating ThreatDetails. Useful for tests. 241 // Factory for creating ThreatDetails. Useful for tests.
240 class ThreatDetailsFactory { 242 class ThreatDetailsFactory {
241 public: 243 public:
242 virtual ~ThreatDetailsFactory() {} 244 virtual ~ThreatDetailsFactory() {}
243 245
244 virtual ThreatDetails* CreateThreatDetails( 246 virtual ThreatDetails* CreateThreatDetails(
245 BaseUIManager* ui_manager, 247 BaseUIManager* ui_manager,
246 content::WebContents* web_contents, 248 content::WebContents* web_contents,
247 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource) = 0; 249 const security_interstitials::UnsafeResource& unsafe_resource,
250 net::URLRequestContextGetter* request_context_getter,
251 history::HistoryService* history_service) = 0;
248 }; 252 };
249 253
250 } // namespace safe_browsing 254 } // namespace safe_browsing
251 255
252 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ 256 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc ('k') | chrome/browser/safe_browsing/threat_details.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698