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

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

Issue 1843383002: Safe Browsing: CheckApiBlacklist request implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review Comments Created 4 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 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/database_manager.h" 5 #include "components/safe_browsing_db/database_manager.h"
6 6
7 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" 7 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "net/url_request/url_request_context_getter.h" 9 #include "net/url_request/url_request_context_getter.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 using content::BrowserThread; 12 using content::BrowserThread;
13 13
14 namespace safe_browsing { 14 namespace safe_browsing {
15 15
16 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager() 16 SafeBrowsingDatabaseManager::SafeBrowsingDatabaseManager()
17 : v4_get_hash_protocol_manager_(NULL) { 17 : v4_get_hash_protocol_manager_(NULL) {
18 } 18 }
19 19
20 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() { 20 SafeBrowsingDatabaseManager::~SafeBrowsingDatabaseManager() {
21 DCHECK(v4_get_hash_protocol_manager_ == NULL); 21 DCHECK(v4_get_hash_protocol_manager_ == NULL);
22 } 22 }
23 23
24 void SafeBrowsingDatabaseManager::StartOnIOThread( 24 void SafeBrowsingDatabaseManager::StartOnIOThread(
25 net::URLRequestContextGetter* request_context_getter, 25 net::URLRequestContextGetter* request_context_getter,
26 const V4ProtocolConfig& config) { 26 const V4ProtocolConfig& config) {
27 DCHECK_CURRENTLY_ON(BrowserThread::IO); 27 DCHECK_CURRENTLY_ON(BrowserThread::IO);
28 if (request_context_getter) { 28
29 // Instantiate a V4GetHashProtocolManager. 29 v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create(
30 v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( 30 request_context_getter, config);
31 request_context_getter, config);
32 }
33 } 31 }
34 32
35 // |shutdown| not used. Destroys the v4 protocol managers. This may be called 33 // |shutdown| not used. Destroys the v4 protocol managers. This may be called
36 // multiple times during the life of the DatabaseManager. 34 // multiple times during the life of the DatabaseManager.
37 // Must be called on IO thread. 35 // Must be called on IO thread.
38 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { 36 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) {
39 DCHECK_CURRENTLY_ON(BrowserThread::IO); 37 DCHECK_CURRENTLY_ON(BrowserThread::IO);
40 // This cancels all in-flight GetHash requests. 38 // This cancels all in-flight GetHash requests.
41 if (v4_get_hash_protocol_manager_) { 39 if (v4_get_hash_protocol_manager_) {
42 delete v4_get_hash_protocol_manager_; 40 delete v4_get_hash_protocol_manager_;
43 v4_get_hash_protocol_manager_ = NULL; 41 v4_get_hash_protocol_manager_ = NULL;
44 } 42 }
43 // TODO(kcarattini): Call back clients with pending requests.
45 } 44 }
46 45
47 void SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, 46 bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url,
48 Client* client) { 47 Client* client) {
49 // TODO(kcarattini): Implement this. 48 DCHECK_CURRENTLY_ON(BrowserThread::IO);
49 DCHECK(v4_get_hash_protocol_manager_);
50
51 // Make sure we can check this url.
52 if (!(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) {
53 return true;
54 }
55
56 // Compute a list of hashes for this url.
57 std::vector<SBFullHash> full_hashes;
58 UrlToFullHashes(url, false, &full_hashes);
59 if (full_hashes.empty())
60 return true;
61
62 // Copy to prefixes.
63 std::vector<SBPrefix> prefixes;
64 for (const SBFullHash& full_hash : full_hashes) {
65 prefixes.push_back(full_hash.prefix);
66 }
67 // Multiple full hashes could share a prefix, remove duplicates.
68 std::sort(prefixes.begin(), prefixes.end());
69 prefixes.erase(std::unique(prefixes.begin(), prefixes.end()), prefixes.end());
70 DCHECK(!prefixes.empty());
71
72 // TODO(kcarattini): Track checks in a map.
Nathan Parker 2016/04/11 16:28:50 Related to my CancelClient question... Should we k
kcarattini 2016/04/12 01:27:02 The SafeBorwsingCheck seems overly complicated for
Nathan Parker 2016/04/12 04:35:48 Sounds like a plan!
73 SafeBrowsingApiCheck* check = new
Nathan Parker 2016/04/11 16:28:50 Maybe a std::unique_ptr<>?
kcarattini 2016/04/12 01:27:02 I need this to live past the end of this function
Nathan Parker 2016/04/12 04:35:48 Yes, but I think you can pass it into Bind() and h
kcarattini 2016/04/12 07:47:49 Since I plan to track this also in a map, I don't
kcarattini 2016/04/13 06:13:30 Updated to use shared_ptr. Let me know if you thin
74 SafeBrowsingApiCheck(url, full_hashes, client);
75
76 // TODO(kcarattini): Implement cache compliance.
77 v4_get_hash_protocol_manager_->GetFullHashesWithApis(prefixes,
78 base::Bind(&SafeBrowsingDatabaseManager::HandleGetHashesWithApisResults,
79 base::Unretained(this), check));
80
81 return false;
82 }
83
84 void SafeBrowsingDatabaseManager::HandleGetHashesWithApisResults(
85 SafeBrowsingApiCheck* check,
86 const std::vector<SBFullHashResult>& full_hash_results,
87 const base::TimeDelta& negative_cache_duration) {
88 DCHECK_CURRENTLY_ON(BrowserThread::IO);
89 if (check)
90 delete check;
91 // TODO(kcarattini): Implement response handler.
92 }
93
94 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::SafeBrowsingApiCheck(
95 const GURL& url, const std::vector<SBFullHash>& full_hashes, Client* client)
96 : url(url), full_hashes(full_hashes), client(client) {
97 }
98
99 SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::~SafeBrowsingApiCheck() {
50 } 100 }
51 101
52 } // namespace safe_browsing 102 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698