OLD | NEW |
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 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" | 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/browser_features.h" | 18 #include "chrome/browser/safe_browsing/browser_features.h" |
19 #include "chrome/browser/safe_browsing/client_side_detection_host.h" | 19 #include "chrome/browser/safe_browsing/client_side_detection_host.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
21 #include "chrome/browser/safe_browsing/ui_manager.h" | 21 #include "chrome/browser/safe_browsing/ui_manager.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 22 #include "chrome/common/safe_browsing/csd.pb.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const ClientMalwareRequest& request, | 199 const ClientMalwareRequest& request, |
200 std::map<std::string, std::set<std::string> >* urls) { | 200 std::map<std::string, std::set<std::string> >* urls) { |
201 for (int i = 0; i < request.bad_ip_url_info_size(); ++i) { | 201 for (int i = 0; i < request.bad_ip_url_info_size(); ++i) { |
202 const ClientMalwareRequest::UrlInfo& urlinfo = | 202 const ClientMalwareRequest::UrlInfo& urlinfo = |
203 request.bad_ip_url_info(i); | 203 request.bad_ip_url_info(i); |
204 (*urls)[urlinfo.ip()].insert(urlinfo.url()); | 204 (*urls)[urlinfo.ip()].insert(urlinfo.url()); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 int num_pending_; // Number of pending feature extractions. | 208 int num_pending_; // Number of pending feature extractions. |
209 scoped_ptr<BrowserFeatureExtractor> extractor_; | 209 std::unique_ptr<BrowserFeatureExtractor> extractor_; |
210 std::map<void*, bool> success_; | 210 std::map<void*, bool> success_; |
211 scoped_ptr<BrowseInfo> browse_info_; | 211 std::unique_ptr<BrowseInfo> browse_info_; |
212 scoped_ptr<StrictMock<MockClientSideDetectionHost> > host_; | 212 std::unique_ptr<StrictMock<MockClientSideDetectionHost>> host_; |
213 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > db_manager_; | 213 scoped_refptr<StrictMock<MockSafeBrowsingDatabaseManager> > db_manager_; |
214 | 214 |
215 private: | 215 private: |
216 void ExtractFeaturesDone(bool success, | 216 void ExtractFeaturesDone(bool success, |
217 scoped_ptr<ClientPhishingRequest> request) { | 217 std::unique_ptr<ClientPhishingRequest> request) { |
218 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 218 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
219 ASSERT_EQ(0U, success_.count(request.get())); | 219 ASSERT_EQ(0U, success_.count(request.get())); |
220 // The pointer doesn't really belong to us. It belongs to | 220 // The pointer doesn't really belong to us. It belongs to |
221 // the test case which passed it to ExtractFeatures above. | 221 // the test case which passed it to ExtractFeatures above. |
222 success_[request.release()] = success; | 222 success_[request.release()] = success; |
223 if (--num_pending_ == 0) { | 223 if (--num_pending_ == 0) { |
224 base::MessageLoop::current()->QuitWhenIdle(); | 224 base::MessageLoop::current()->QuitWhenIdle(); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 void ExtractMalwareFeaturesDone( | 228 void ExtractMalwareFeaturesDone( |
229 bool success, | 229 bool success, |
230 scoped_ptr<ClientMalwareRequest> request) { | 230 std::unique_ptr<ClientMalwareRequest> request) { |
231 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 231 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
232 ASSERT_EQ(0U, success_.count(request.get())); | 232 ASSERT_EQ(0U, success_.count(request.get())); |
233 // The pointer doesn't really belong to us. It belongs to | 233 // The pointer doesn't really belong to us. It belongs to |
234 // the test case which passed it to ExtractMalwareFeatures above. | 234 // the test case which passed it to ExtractMalwareFeatures above. |
235 success_[request.release()] = success; | 235 success_[request.release()] = success; |
236 if (--num_pending_ == 0) { | 236 if (--num_pending_ == 0) { |
237 base::MessageLoopForUI::current()->QuitWhenIdle(); | 237 base::MessageLoopForUI::current()->QuitWhenIdle(); |
238 } | 238 } |
239 } | 239 } |
240 }; | 240 }; |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 // First ip is good but all the others are bad. | 652 // First ip is good but all the others are bad. |
653 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); | 653 EXPECT_CALL(*db_manager_, MatchMalwareIP(ip)).WillOnce(Return(i > 0)); |
654 } | 654 } |
655 | 655 |
656 ExtractMalwareFeatures(&request); | 656 ExtractMalwareFeatures(&request); |
657 // The number of IP matched url we store is capped at 5 IPs per request. | 657 // The number of IP matched url we store is capped at 5 IPs per request. |
658 EXPECT_EQ(5, request.bad_ip_url_info_size()); | 658 EXPECT_EQ(5, request.bad_ip_url_info_size()); |
659 } | 659 } |
660 | 660 |
661 } // namespace safe_browsing | 661 } // namespace safe_browsing |
OLD | NEW |