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

Unified Diff: components/safe_browsing_db/v4_get_hash_protocol_manager.cc

Issue 2284863002: Remove a use of stl_util in safe browsing. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: components/safe_browsing_db/v4_get_hash_protocol_manager.cc
diff --git a/components/safe_browsing_db/v4_get_hash_protocol_manager.cc b/components/safe_browsing_db/v4_get_hash_protocol_manager.cc
index 4b5f911d3aea69310fb8be800b29b7dff126aac1..bc495a33ce33284b1fbf468e723343619f7e2697 100644
--- a/components/safe_browsing_db/v4_get_hash_protocol_manager.cc
+++ b/components/safe_browsing_db/v4_get_hash_protocol_manager.cc
@@ -8,6 +8,7 @@
#include "base/base64url.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/timer/timer.h"
#include "net/base/load_flags.h"
@@ -90,6 +91,15 @@ class V4GetHashProtocolManagerFactoryImpl
// V4GetHashProtocolManager implementation --------------------------------
+struct V4GetHashProtocolManager::FetcherAndCallback {
+ FetcherAndCallback(std::unique_ptr<net::URLFetcher> fetcher,
+ FullHashCallback callback)
mattm 2016/08/27 01:43:25 const ref
Avi (use Gerrit) 2016/08/29 18:04:23 moot
+ : fetcher(std::move(fetcher)), callback(callback) {}
+
+ std::unique_ptr<net::URLFetcher> fetcher;
+ FullHashCallback callback;
+};
+
// static
V4GetHashProtocolManagerFactory* V4GetHashProtocolManager::factory_ = NULL;
@@ -119,10 +129,6 @@ V4GetHashProtocolManager::V4GetHashProtocolManager(
clock_(new base::DefaultClock()) {}
V4GetHashProtocolManager::~V4GetHashProtocolManager() {
- // Delete in-progress SafeBrowsing requests.
- STLDeleteContainerPairFirstPointers(hash_requests_.begin(),
- hash_requests_.end());
- hash_requests_.clear();
}
// static
@@ -328,7 +334,8 @@ void V4GetHashProtocolManager::GetFullHashes(
net::URLFetcher::GET, this)
.release();
fetcher->SetExtraRequestHeaders(headers.ToString());
- hash_requests_[fetcher] = callback;
+ hash_requests_[fetcher] =
+ base::MakeUnique<FetcherAndCallback>(base::WrapUnique(fetcher), callback);
fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
fetcher->SetRequestContext(request_context_getter_.get());
@@ -357,16 +364,12 @@ void V4GetHashProtocolManager::OnURLFetchComplete(
HashRequests::iterator it = hash_requests_.find(source);
DCHECK(it != hash_requests_.end()) << "Request not found";
- // FindFullHashes response.
- // Reset the scoped pointer so the fetcher gets destroyed properly.
- std::unique_ptr<const net::URLFetcher> fetcher(it->first);
-
int response_code = source->GetResponseCode();
net::URLRequestStatus status = source->GetStatus();
V4ProtocolManagerUtil::RecordHttpResponseOrErrorCode(
kUmaV4HashResponseMetricName, status, response_code);
- const FullHashCallback& callback = it->second;
+ const FullHashCallback& callback = it->second->callback;
std::vector<SBFullHashResult> full_hashes;
base::Time negative_cache_expire;
if (status.is_success() && response_code == net::HTTP_OK) {

Powered by Google App Engine
This is Rietveld 408576698