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

Side by Side Diff: components/safe_browsing_db/remote_database_manager.cc

Issue 1726403006: Switch Safe Browsing's metadata from string to struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix safe_browsing_service_browsertest and update components_tests.gyp Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/safe_browsing_db/remote_database_manager.h" 5 #include "components/safe_browsing_db/remote_database_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 24 matching lines...) Expand all
35 // RemoteSafeBrowsingDatabaseManager::ClientRequest methods 35 // RemoteSafeBrowsingDatabaseManager::ClientRequest methods
36 // 36 //
37 class RemoteSafeBrowsingDatabaseManager::ClientRequest { 37 class RemoteSafeBrowsingDatabaseManager::ClientRequest {
38 public: 38 public:
39 ClientRequest(Client* client, 39 ClientRequest(Client* client,
40 RemoteSafeBrowsingDatabaseManager* db_manager, 40 RemoteSafeBrowsingDatabaseManager* db_manager,
41 const GURL& url); 41 const GURL& url);
42 42
43 static void OnRequestDoneWeak(const base::WeakPtr<ClientRequest>& req, 43 static void OnRequestDoneWeak(const base::WeakPtr<ClientRequest>& req,
44 SBThreatType matched_threat_type, 44 SBThreatType matched_threat_type,
45 const std::string& metadata); 45 const ThreatMetadata& metadata);
46 void OnRequestDone(SBThreatType matched_threat_type, 46 void OnRequestDone(SBThreatType matched_threat_type,
47 const std::string& metadata); 47 const ThreatMetadata& metadata);
48 48
49 // Accessors 49 // Accessors
50 Client* client() const { return client_; } 50 Client* client() const { return client_; }
51 const GURL& url() const { return url_; } 51 const GURL& url() const { return url_; }
52 base::WeakPtr<ClientRequest> GetWeakPtr() { 52 base::WeakPtr<ClientRequest> GetWeakPtr() {
53 return weak_factory_.GetWeakPtr(); 53 return weak_factory_.GetWeakPtr();
54 } 54 }
55 55
56 private: 56 private:
57 Client* client_; 57 Client* client_;
58 RemoteSafeBrowsingDatabaseManager* db_manager_; 58 RemoteSafeBrowsingDatabaseManager* db_manager_;
59 GURL url_; 59 GURL url_;
60 base::ElapsedTimer timer_; 60 base::ElapsedTimer timer_;
61 base::WeakPtrFactory<ClientRequest> weak_factory_; 61 base::WeakPtrFactory<ClientRequest> weak_factory_;
62 }; 62 };
63 63
64 RemoteSafeBrowsingDatabaseManager::ClientRequest::ClientRequest( 64 RemoteSafeBrowsingDatabaseManager::ClientRequest::ClientRequest(
65 Client* client, 65 Client* client,
66 RemoteSafeBrowsingDatabaseManager* db_manager, 66 RemoteSafeBrowsingDatabaseManager* db_manager,
67 const GURL& url) 67 const GURL& url)
68 : client_(client), 68 : client_(client),
69 db_manager_(db_manager), 69 db_manager_(db_manager),
70 url_(url), 70 url_(url),
71 weak_factory_(this) {} 71 weak_factory_(this) {}
72 72
73 // Static 73 // Static
74 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDoneWeak( 74 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDoneWeak(
75 const base::WeakPtr<ClientRequest>& req, 75 const base::WeakPtr<ClientRequest>& req,
76 SBThreatType matched_threat_type, 76 SBThreatType matched_threat_type,
77 const std::string& metadata) { 77 const ThreatMetadata& metadata) {
78 DCHECK_CURRENTLY_ON(BrowserThread::IO); 78 DCHECK_CURRENTLY_ON(BrowserThread::IO);
79 if (!req) 79 if (!req)
80 return; // Previously canceled 80 return; // Previously canceled
81 req->OnRequestDone(matched_threat_type, metadata); 81 req->OnRequestDone(matched_threat_type, metadata);
82 } 82 }
83 83
84 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDone( 84 void RemoteSafeBrowsingDatabaseManager::ClientRequest::OnRequestDone(
85 SBThreatType matched_threat_type, 85 SBThreatType matched_threat_type,
86 const std::string& metadata) { 86 const ThreatMetadata& metadata) {
87 DVLOG(1) << "OnRequestDone took " << timer_.Elapsed().InMilliseconds() 87 DVLOG(1) << "OnRequestDone took " << timer_.Elapsed().InMilliseconds()
88 << " ms for client " << client_ << " and URL " << url_; 88 << " ms for client " << client_ << " and URL " << url_;
89 client_->OnCheckBrowseUrlResult(url_, matched_threat_type, metadata); 89 client_->OnCheckBrowseUrlResult(url_, matched_threat_type, metadata);
90 UMA_HISTOGRAM_TIMES("SB2.RemoteCall.Elapsed", timer_.Elapsed()); 90 UMA_HISTOGRAM_TIMES("SB2.RemoteCall.Elapsed", timer_.Elapsed());
91 // CancelCheck() will delete *this. 91 // CancelCheck() will delete *this.
92 db_manager_->CancelCheck(client_); 92 db_manager_->CancelCheck(client_);
93 } 93 }
94 94
95 // 95 //
96 // RemoteSafeBrowsingDatabaseManager methods 96 // RemoteSafeBrowsingDatabaseManager methods
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 UMA_HISTOGRAM_BOOLEAN("SB2.RemoteCall.CanCheckUrl", can_check_url); 244 UMA_HISTOGRAM_BOOLEAN("SB2.RemoteCall.CanCheckUrl", can_check_url);
245 if (!can_check_url) 245 if (!can_check_url)
246 return true; // Safe, continue right away. 246 return true; // Safe, continue right away.
247 247
248 scoped_ptr<ClientRequest> req(new ClientRequest(client, this, url)); 248 scoped_ptr<ClientRequest> req(new ClientRequest(client, this, url));
249 std::vector<SBThreatType> threat_types; // Not currently used. 249 std::vector<SBThreatType> threat_types; // Not currently used.
250 250
251 DVLOG(1) << "Checking for client " << client << " and URL " << url; 251 DVLOG(1) << "Checking for client " << client << " and URL " << url;
252 SafeBrowsingApiHandler* api_handler = SafeBrowsingApiHandler::GetInstance(); 252 SafeBrowsingApiHandler* api_handler = SafeBrowsingApiHandler::GetInstance();
253 // This shouldn't happen since SafeBrowsingResourceThrottle checks 253 // This shouldn't happen since SafeBrowsingResourceThrottle checks
254 // IsSupported() ealier. 254 // IsSupported() earlier.
255 DCHECK(api_handler) << "SafeBrowsingApiHandler was never constructed"; 255 DCHECK(api_handler) << "SafeBrowsingApiHandler was never constructed";
256 api_handler->StartURLCheck( 256 api_handler->StartURLCheck(
257 base::Bind(&ClientRequest::OnRequestDoneWeak, req->GetWeakPtr()), url, 257 base::Bind(&ClientRequest::OnRequestDoneWeak, req->GetWeakPtr()), url,
258 threat_types); 258 threat_types);
259 259
260 UMA_HISTOGRAM_COUNTS_10000("SB2.RemoteCall.ChecksPending", 260 UMA_HISTOGRAM_COUNTS_10000("SB2.RemoteCall.ChecksPending",
261 current_requests_.size()); 261 current_requests_.size());
262 current_requests_.push_back(req.release()); 262 current_requests_.push_back(req.release());
263 263
264 // Defer the resource load. 264 // Defer the resource load.
(...skipping 26 matching lines...) Expand all
291 void RemoteSafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { 291 void RemoteSafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) {
292 // |shutdown| is not used. 292 // |shutdown| is not used.
293 DCHECK_CURRENTLY_ON(BrowserThread::IO); 293 DCHECK_CURRENTLY_ON(BrowserThread::IO);
294 DVLOG(1) << "RemoteSafeBrowsingDatabaseManager stopping"; 294 DVLOG(1) << "RemoteSafeBrowsingDatabaseManager stopping";
295 295
296 // Call back and delete any remaining clients. OnRequestDone() modifies 296 // Call back and delete any remaining clients. OnRequestDone() modifies
297 // |current_requests_|, so we make a copy first. 297 // |current_requests_|, so we make a copy first.
298 std::vector<ClientRequest*> to_callback(current_requests_); 298 std::vector<ClientRequest*> to_callback(current_requests_);
299 for (auto req : to_callback) { 299 for (auto req : to_callback) {
300 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url(); 300 DVLOG(1) << "Stopping: Invoking unfinished req for URL " << req->url();
301 req->OnRequestDone(SB_THREAT_TYPE_SAFE, std::string()); 301 req->OnRequestDone(SB_THREAT_TYPE_SAFE, ThreatMetadata());
302 } 302 }
303 enabled_ = false; 303 enabled_ = false;
304 304
305 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown); 305 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown);
306 } 306 }
307 307
308 } // namespace safe_browsing 308 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698