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

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

Issue 2784253004: Componentize safe_browsing: decouple threat_details* from the chrome/ layer. (Closed)
Patch Set: address comment 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implementation of the ThreatDetails class. 5 // Implementation of the ThreatDetails class.
6 6
7 #include "chrome/browser/safe_browsing/threat_details.h" 7 #include "chrome/browser/safe_browsing/threat_details.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <unordered_set>
12 11
13 #include "base/bind.h" 12 #include "base/bind.h"
14 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
15 #include "base/macros.h"
16 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
17 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
18 #include "chrome/browser/history/history_service_factory.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/safe_browsing/threat_details_cache.h" 16 #include "chrome/browser/safe_browsing/threat_details_cache.h"
21 #include "chrome/browser/safe_browsing/threat_details_history.h" 17 #include "chrome/browser/safe_browsing/threat_details_history.h"
22 #include "components/history/core/browser/history_service.h" 18 #include "components/history/core/browser/history_service.h"
19 #include "components/safe_browsing/base_ui_manager.h"
23 #include "components/safe_browsing/common/safebrowsing_messages.h" 20 #include "components/safe_browsing/common/safebrowsing_messages.h"
24 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/navigation_controller.h" 22 #include "content/public/browser/navigation_controller.h"
26 #include "content/public/browser/navigation_entry.h" 23 #include "content/public/browser/navigation_entry.h"
27 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
29 #include "net/url_request/url_request_context_getter.h" 26 #include "net/url_request/url_request_context_getter.h"
30 27
31 using content::BrowserThread; 28 using content::BrowserThread;
32 using content::NavigationEntry; 29 using content::NavigationEntry;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 130
134 } // namespace 131 } // namespace
135 132
136 // The default ThreatDetailsFactory. Global, made a singleton so we 133 // The default ThreatDetailsFactory. Global, made a singleton so we
137 // don't leak it. 134 // don't leak it.
138 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { 135 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory {
139 public: 136 public:
140 ThreatDetails* CreateThreatDetails( 137 ThreatDetails* CreateThreatDetails(
141 BaseUIManager* ui_manager, 138 BaseUIManager* ui_manager,
142 WebContents* web_contents, 139 WebContents* web_contents,
143 const security_interstitials::UnsafeResource& unsafe_resource) override { 140 const security_interstitials::UnsafeResource& unsafe_resource,
144 return new ThreatDetails(ui_manager, web_contents, unsafe_resource); 141 net::URLRequestContextGetter* request_context_getter,
142 history::HistoryService* history_service) override {
143 return new ThreatDetails(ui_manager, web_contents, unsafe_resource,
144 request_context_getter, history_service);
145 } 145 }
146 146
147 private: 147 private:
148 friend struct base::LazyInstanceTraitsBase<ThreatDetailsFactoryImpl>; 148 friend struct base::LazyInstanceTraitsBase<ThreatDetailsFactoryImpl>;
149 149
150 ThreatDetailsFactoryImpl() {} 150 ThreatDetailsFactoryImpl() {}
151 151
152 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsFactoryImpl); 152 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsFactoryImpl);
153 }; 153 };
154 154
155 static base::LazyInstance<ThreatDetailsFactoryImpl>::DestructorAtExit 155 static base::LazyInstance<ThreatDetailsFactoryImpl>::DestructorAtExit
156 g_threat_details_factory_impl = LAZY_INSTANCE_INITIALIZER; 156 g_threat_details_factory_impl = LAZY_INSTANCE_INITIALIZER;
157 157
158 // Create a ThreatDetails for the given tab. 158 // Create a ThreatDetails for the given tab.
159 /* static */ 159 /* static */
160 ThreatDetails* ThreatDetails::NewThreatDetails( 160 ThreatDetails* ThreatDetails::NewThreatDetails(
161 BaseUIManager* ui_manager, 161 BaseUIManager* ui_manager,
162 WebContents* web_contents, 162 WebContents* web_contents,
163 const UnsafeResource& resource) { 163 const UnsafeResource& resource,
164 net::URLRequestContextGetter* request_context_getter,
165 history::HistoryService* history_service) {
164 // Set up the factory if this has not been done already (tests do that 166 // Set up the factory if this has not been done already (tests do that
165 // before this method is called). 167 // before this method is called).
166 if (!factory_) 168 if (!factory_)
167 factory_ = g_threat_details_factory_impl.Pointer(); 169 factory_ = g_threat_details_factory_impl.Pointer();
168 return factory_->CreateThreatDetails(ui_manager, web_contents, resource); 170 return factory_->CreateThreatDetails(ui_manager, web_contents, resource,
171 request_context_getter, history_service);
169 } 172 }
170 173
171 // Create a ThreatDetails for the given tab. Runs in the UI thread. 174 // Create a ThreatDetails for the given tab. Runs in the UI thread.
172 ThreatDetails::ThreatDetails(BaseUIManager* ui_manager, 175 ThreatDetails::ThreatDetails(
173 content::WebContents* web_contents, 176 BaseUIManager* ui_manager,
174 const UnsafeResource& resource) 177 content::WebContents* web_contents,
178 const UnsafeResource& resource,
179 net::URLRequestContextGetter* request_context_getter,
180 history::HistoryService* history_service)
175 : content::WebContentsObserver(web_contents), 181 : content::WebContentsObserver(web_contents),
176 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 182 request_context_getter_(request_context_getter),
177 request_context_getter_(profile_->GetRequestContext()),
178 ui_manager_(ui_manager), 183 ui_manager_(ui_manager),
179 resource_(resource), 184 resource_(resource),
180 cache_result_(false), 185 cache_result_(false),
181 did_proceed_(false), 186 did_proceed_(false),
182 num_visits_(0), 187 num_visits_(0),
183 ambiguous_dom_(false), 188 ambiguous_dom_(false),
184 cache_collector_(new ThreatDetailsCacheCollector) { 189 cache_collector_(new ThreatDetailsCacheCollector) {
185 history::HistoryService* history_service =
186 HistoryServiceFactory::GetForProfile(profile_,
187 ServiceAccessType::EXPLICIT_ACCESS);
188 redirects_collector_ = new ThreatDetailsRedirectsCollector( 190 redirects_collector_ = new ThreatDetailsRedirectsCollector(
189 history_service ? history_service->AsWeakPtr() 191 history_service ? history_service->AsWeakPtr()
190 : base::WeakPtr<history::HistoryService>()); 192 : base::WeakPtr<history::HistoryService>());
191 StartCollection(); 193 StartCollection();
192 } 194 }
193 195
194 ThreatDetails::~ThreatDetails() {} 196 ThreatDetails::~ThreatDetails() {}
195 197
196 bool ThreatDetails::OnMessageReceived(const IPC::Message& message, 198 bool ThreatDetails::OnMessageReceived(const IPC::Message& message,
197 RenderFrameHost* render_frame_host) { 199 RenderFrameHost* render_frame_host) {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // Send the report, using the SafeBrowsingService. 592 // Send the report, using the SafeBrowsingService.
591 std::string serialized; 593 std::string serialized;
592 if (!report_->SerializeToString(&serialized)) { 594 if (!report_->SerializeToString(&serialized)) {
593 DLOG(ERROR) << "Unable to serialize the threat report."; 595 DLOG(ERROR) << "Unable to serialize the threat report.";
594 return; 596 return;
595 } 597 }
596 ui_manager_->SendSerializedThreatDetails(serialized); 598 ui_manager_->SendSerializedThreatDetails(serialized);
597 } 599 }
598 600
599 } // namespace safe_browsing 601 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/threat_details.h ('k') | chrome/browser/safe_browsing/threat_details_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698