OLD | NEW |
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 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // ---------------------------------------------------------------- | 164 // ---------------------------------------------------------------- |
165 | 165 |
166 FullHashCallbackInfo::FullHashCallbackInfo() {} | 166 FullHashCallbackInfo::FullHashCallbackInfo() {} |
167 | 167 |
168 FullHashCallbackInfo::FullHashCallbackInfo( | 168 FullHashCallbackInfo::FullHashCallbackInfo( |
169 const std::vector<FullHashInfo>& cached_full_hash_infos, | 169 const std::vector<FullHashInfo>& cached_full_hash_infos, |
170 const std::vector<HashPrefix>& prefixes_requested, | 170 const std::vector<HashPrefix>& prefixes_requested, |
171 std::unique_ptr<net::URLFetcher> fetcher, | 171 std::unique_ptr<net::URLFetcher> fetcher, |
172 const FullHashToStoreAndHashPrefixesMap& | 172 const FullHashToStoreAndHashPrefixesMap& |
173 full_hash_to_store_and_hash_prefixes, | 173 full_hash_to_store_and_hash_prefixes, |
174 const FullHashCallback& callback) | 174 const FullHashCallback& callback, |
| 175 const base::Time& network_start_time) |
175 : cached_full_hash_infos(cached_full_hash_infos), | 176 : cached_full_hash_infos(cached_full_hash_infos), |
176 callback(callback), | 177 callback(callback), |
177 fetcher(std::move(fetcher)), | 178 fetcher(std::move(fetcher)), |
178 full_hash_to_store_and_hash_prefixes( | 179 full_hash_to_store_and_hash_prefixes( |
179 full_hash_to_store_and_hash_prefixes), | 180 full_hash_to_store_and_hash_prefixes), |
| 181 network_start_time(network_start_time), |
180 prefixes_requested(prefixes_requested) {} | 182 prefixes_requested(prefixes_requested) {} |
181 | 183 |
182 FullHashCallbackInfo::~FullHashCallbackInfo() {} | 184 FullHashCallbackInfo::~FullHashCallbackInfo() {} |
183 | 185 |
184 // ---------------------------------------------------------------- | 186 // ---------------------------------------------------------------- |
185 | 187 |
186 FullHashInfo::FullHashInfo(const FullHash& full_hash, | 188 FullHashInfo::FullHashInfo(const FullHash& full_hash, |
187 const ListIdentifier& list_id, | 189 const ListIdentifier& list_id, |
188 const base::Time& positive_expiry) | 190 const base::Time& positive_expiry) |
189 : full_hash(full_hash), | 191 : full_hash(full_hash), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 std::string req_base64 = GetHashRequest(prefixes_to_request); | 293 std::string req_base64 = GetHashRequest(prefixes_to_request); |
292 GURL gethash_url; | 294 GURL gethash_url; |
293 net::HttpRequestHeaders headers; | 295 net::HttpRequestHeaders headers; |
294 GetHashUrlAndHeaders(req_base64, &gethash_url, &headers); | 296 GetHashUrlAndHeaders(req_base64, &gethash_url, &headers); |
295 | 297 |
296 std::unique_ptr<net::URLFetcher> owned_fetcher = net::URLFetcher::Create( | 298 std::unique_ptr<net::URLFetcher> owned_fetcher = net::URLFetcher::Create( |
297 url_fetcher_id_++, gethash_url, net::URLFetcher::GET, this); | 299 url_fetcher_id_++, gethash_url, net::URLFetcher::GET, this); |
298 net::URLFetcher* fetcher = owned_fetcher.get(); | 300 net::URLFetcher* fetcher = owned_fetcher.get(); |
299 pending_hash_requests_[fetcher].reset(new FullHashCallbackInfo( | 301 pending_hash_requests_[fetcher].reset(new FullHashCallbackInfo( |
300 cached_full_hash_infos, prefixes_to_request, std::move(owned_fetcher), | 302 cached_full_hash_infos, prefixes_to_request, std::move(owned_fetcher), |
301 full_hash_to_store_and_hash_prefixes, callback)); | 303 full_hash_to_store_and_hash_prefixes, callback, clock_->Now())); |
302 | 304 |
303 fetcher->SetExtraRequestHeaders(headers.ToString()); | 305 fetcher->SetExtraRequestHeaders(headers.ToString()); |
304 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 306 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
305 fetcher->SetRequestContext(request_context_getter_.get()); | 307 fetcher->SetRequestContext(request_context_getter_.get()); |
306 fetcher->Start(); | 308 fetcher->Start(); |
307 } | 309 } |
308 | 310 |
309 void V4GetHashProtocolManager::GetFullHashesWithApis( | 311 void V4GetHashProtocolManager::GetFullHashesWithApis( |
310 const GURL& url, | 312 const GURL& url, |
311 ThreatMetadataForApiCallback api_callback) { | 313 ThreatMetadataForApiCallback api_callback) { |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 << " and response code: " << response_code; | 721 << " and response code: " << response_code; |
720 | 722 |
721 if (status.status() == net::URLRequestStatus::FAILED) { | 723 if (status.status() == net::URLRequestStatus::FAILED) { |
722 RecordGetHashResult(V4OperationResult::NETWORK_ERROR); | 724 RecordGetHashResult(V4OperationResult::NETWORK_ERROR); |
723 } else { | 725 } else { |
724 RecordGetHashResult(V4OperationResult::HTTP_ERROR); | 726 RecordGetHashResult(V4OperationResult::HTTP_ERROR); |
725 } | 727 } |
726 } | 728 } |
727 | 729 |
728 const std::unique_ptr<FullHashCallbackInfo>& fhci = it->second; | 730 const std::unique_ptr<FullHashCallbackInfo>& fhci = it->second; |
| 731 UMA_HISTOGRAM_LONG_TIMES("SafeBrowsing.V4GetHashNetwork.Time", |
| 732 clock_->Now() - fhci->network_start_time); |
729 UpdateCache(fhci->prefixes_requested, full_hash_infos, negative_cache_expire); | 733 UpdateCache(fhci->prefixes_requested, full_hash_infos, negative_cache_expire); |
730 MergeResults(fhci->full_hash_to_store_and_hash_prefixes, full_hash_infos, | 734 MergeResults(fhci->full_hash_to_store_and_hash_prefixes, full_hash_infos, |
731 &fhci->cached_full_hash_infos); | 735 &fhci->cached_full_hash_infos); |
732 | 736 |
733 fhci->callback.Run(fhci->cached_full_hash_infos); | 737 fhci->callback.Run(fhci->cached_full_hash_infos); |
734 | 738 |
735 pending_hash_requests_.erase(it); | 739 pending_hash_requests_.erase(it); |
736 } | 740 } |
737 | 741 |
738 #ifndef DEBUG | 742 #ifndef DEBUG |
739 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { | 743 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { |
740 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id | 744 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id |
741 << "; positive_expiry: " << fhi.positive_expiry | 745 << "; positive_expiry: " << fhi.positive_expiry |
742 << "; metadata.api_permissions.size(): " | 746 << "; metadata.api_permissions.size(): " |
743 << fhi.metadata.api_permissions.size() << "}"; | 747 << fhi.metadata.api_permissions.size() << "}"; |
744 return os; | 748 return os; |
745 } | 749 } |
746 #endif | 750 #endif |
747 | 751 |
748 } // namespace safe_browsing | 752 } // namespace safe_browsing |
OLD | NEW |