Chromium Code Reviews| Index: components/safe_browsing_db/database_manager.cc |
| diff --git a/components/safe_browsing_db/database_manager.cc b/components/safe_browsing_db/database_manager.cc |
| index b8998b4431fcdde86dadd3b664dde8504c2f1b05..60c3957f95b70bbb8a82166f03dd3e070a607eac 100644 |
| --- a/components/safe_browsing_db/database_manager.cc |
| +++ b/components/safe_browsing_db/database_manager.cc |
| @@ -25,11 +25,9 @@ void SafeBrowsingDatabaseManager::StartOnIOThread( |
| net::URLRequestContextGetter* request_context_getter, |
| const V4ProtocolConfig& config) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - if (request_context_getter) { |
| - // Instantiate a V4GetHashProtocolManager. |
| - v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( |
| - request_context_getter, config); |
| - } |
| + |
| + v4_get_hash_protocol_manager_ = V4GetHashProtocolManager::Create( |
| + request_context_getter, config); |
| } |
| // |shutdown| not used. Destroys the v4 protocol managers. This may be called |
| @@ -42,11 +40,63 @@ void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |
| delete v4_get_hash_protocol_manager_; |
| v4_get_hash_protocol_manager_ = NULL; |
| } |
| + // TODO(kcarattini): Call back clients with pending requests. |
| } |
| -void SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, |
| +bool SafeBrowsingDatabaseManager::CheckApiBlacklistUrl(const GURL& url, |
| Client* client) { |
| - // TODO(kcarattini): Implement this. |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + DCHECK(v4_get_hash_protocol_manager_); |
| + |
| + // Make sure we can check this url. |
| + if (!(url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme))) { |
| + return true; |
| + } |
| + |
| + // Compute a list of hashes for this url. |
| + std::vector<SBFullHash> full_hashes; |
| + UrlToFullHashes(url, false, &full_hashes); |
| + if (full_hashes.empty()) |
| + return true; |
| + |
| + // Copy to prefixes. |
| + std::vector<SBPrefix> prefixes; |
| + for (const SBFullHash& full_hash : full_hashes) { |
| + prefixes.push_back(full_hash.prefix); |
| + } |
| + // Multiple full hashes could share a prefix, remove duplicates. |
| + std::sort(prefixes.begin(), prefixes.end()); |
| + prefixes.erase(std::unique(prefixes.begin(), prefixes.end()), prefixes.end()); |
| + DCHECK(!prefixes.empty()); |
| + |
| + // 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!
|
| + 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
|
| + SafeBrowsingApiCheck(url, full_hashes, client); |
| + |
| + // TODO(kcarattini): Implement cache compliance. |
| + v4_get_hash_protocol_manager_->GetFullHashesWithApis(prefixes, |
| + base::Bind(&SafeBrowsingDatabaseManager::HandleGetHashesWithApisResults, |
| + base::Unretained(this), check)); |
| + |
| + return false; |
| +} |
| + |
| +void SafeBrowsingDatabaseManager::HandleGetHashesWithApisResults( |
| + SafeBrowsingApiCheck* check, |
| + const std::vector<SBFullHashResult>& full_hash_results, |
| + const base::TimeDelta& negative_cache_duration) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + if (check) |
| + delete check; |
| + // TODO(kcarattini): Implement response handler. |
| +} |
| + |
| +SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::SafeBrowsingApiCheck( |
| + const GURL& url, const std::vector<SBFullHash>& full_hashes, Client* client) |
| + : url(url), full_hashes(full_hashes), client(client) { |
| +} |
| + |
| +SafeBrowsingDatabaseManager::SafeBrowsingApiCheck::~SafeBrowsingApiCheck() { |
| } |
| } // namespace safe_browsing |