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

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

Issue 2225613002: V4LDM: Add check for HashPrefix match and some tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // This file should not be build on Android but is currently getting built. 5 // This file should not be build on Android but is currently getting built.
6 // TODO(vakh): Fix that: http://crbug.com/621647 6 // TODO(vakh): Fix that: http://crbug.com/621647
7 7
8 #include "components/safe_browsing_db/v4_local_database_manager.h" 8 #include "components/safe_browsing_db/v4_local_database_manager.h"
9 9
10 #include <vector> 10 #include <vector>
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 V4LocalDatabaseManager::~V4LocalDatabaseManager() { 37 V4LocalDatabaseManager::~V4LocalDatabaseManager() {
38 DCHECK(!enabled_); 38 DCHECK(!enabled_);
39 } 39 }
40 40
41 bool V4LocalDatabaseManager::IsSupported() const { 41 bool V4LocalDatabaseManager::IsSupported() const {
42 return true; 42 return true;
43 } 43 }
44 44
45 safe_browsing::ThreatSource V4LocalDatabaseManager::GetThreatSource() const { 45 ThreatSource V4LocalDatabaseManager::GetThreatSource() const {
46 return safe_browsing::ThreatSource::LOCAL_PVER4; 46 return ThreatSource::LOCAL_PVER4;
47 } 47 }
48 48
49 bool V4LocalDatabaseManager::ChecksAreAlwaysAsync() const { 49 bool V4LocalDatabaseManager::ChecksAreAlwaysAsync() const {
50 return false; 50 return false;
51 } 51 }
52 52
53 bool V4LocalDatabaseManager::CanCheckResourceType( 53 bool V4LocalDatabaseManager::CanCheckResourceType(
54 content::ResourceType resource_type) const { 54 content::ResourceType resource_type) const {
55 // We check all types since most checks are fast. 55 // We check all types since most checks are fast.
56 return true; 56 return true;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return true; 133 return true;
134 } 134 }
135 135
136 bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) { 136 bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) {
137 // TODO(vakh): Implement this skeleton. 137 // TODO(vakh): Implement this skeleton.
138 DCHECK_CURRENTLY_ON(BrowserThread::IO); 138 DCHECK_CURRENTLY_ON(BrowserThread::IO);
139 if (!enabled_ || !CanCheckUrl(url)) { 139 if (!enabled_ || !CanCheckUrl(url)) {
140 return true; 140 return true;
141 } 141 }
142 142
143 // TODO(vakh): Queue check if v4_database_ isn't ready yet.
144 if (v4_database_) {
145 base::hash_set<FullHash> full_hashes;
146 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes);
147
148 base::hash_set<HashPrefix> matched_hash_prefixes;
149 base::hash_set<UpdateListIdentifier> matched_stores;
150 base::hash_set<UpdateListIdentifier> stores_to_look(
151 {GetUrlMalwareId(), GetUrlSocEngId()});
152 MatchedHashPrefixMap matched_hash_prefix_map;
153 for (const auto& full_hash : full_hashes) {
154 v4_database_->GetStoresMatchingFullHash(full_hash, stores_to_look,
155 &matched_hash_prefix_map);
156 for (const auto& matched_pair : matched_hash_prefix_map) {
157 matched_stores.insert(matched_pair.first);
158 matched_hash_prefixes.insert(matched_pair.second);
159 }
160 }
161
162 DCHECK((matched_stores.empty() && matched_hash_prefixes.empty()) ||
Nathan Parker 2016/08/15 19:06:41 DECHECK_EQ(matched_stores.empty(), matched_hash_pr
vakh (use Gerrit instead) 2016/08/17 18:23:06 Done.
163 (!matched_stores.empty() && !matched_hash_prefixes.empty()));
164 // TODO(vakh): Fetch full hashes for the matching hash prefixes.
Nathan Parker 2016/08/15 19:06:41 You need to invoke the client's callback asynchron
vakh (use Gerrit instead) 2016/08/17 18:23:06 This method is not being called from product code
165 return matched_hash_prefixes.empty();
166 }
143 // Don't defer the resource load. 167 // Don't defer the resource load.
144 return true; 168 return true;
145 } 169 }
146 170
147 void V4LocalDatabaseManager::CancelCheck(Client* client) { 171 void V4LocalDatabaseManager::CancelCheck(Client* client) {
148 // TODO(vakh): Implement this skeleton. 172 // TODO(vakh): Implement this skeleton.
149 DCHECK_CURRENTLY_ON(BrowserThread::IO); 173 DCHECK_CURRENTLY_ON(BrowserThread::IO);
150 DCHECK(enabled_); 174 DCHECK(enabled_);
151 } 175 }
152 176
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 267 }
244 268
245 void V4LocalDatabaseManager::DatabaseUpdated() { 269 void V4LocalDatabaseManager::DatabaseUpdated() {
246 if (enabled_) { 270 if (enabled_) {
247 v4_update_protocol_manager_->ScheduleNextUpdate( 271 v4_update_protocol_manager_->ScheduleNextUpdate(
248 v4_database_->GetStoreStateMap()); 272 v4_database_->GetStoreStateMap());
249 } 273 }
250 } 274 }
251 275
252 } // namespace safe_browsing 276 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698