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

Unified Diff: net/cert_net/cert_net_fetcher_impl.cc

Issue 1075563002: Use a base::LinkedList rather than a std::deque to back CertNetFetcherImpl's request list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_fetcher
Patch Set: rebase onto master Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert_net/cert_net_fetcher_impl.cc
diff --git a/net/cert_net/cert_net_fetcher_impl.cc b/net/cert_net/cert_net_fetcher_impl.cc
index f69e564af2c0347e4498303c65bd774269a87473..7b119caf39243844bc7398e3d4c2f1b8fbe0b051 100644
--- a/net/cert_net/cert_net_fetcher_impl.cc
+++ b/net/cert_net/cert_net_fetcher_impl.cc
@@ -4,9 +4,8 @@
#include "net/cert_net/cert_net_fetcher_impl.h"
-#include <deque>
-
#include "base/callback_helpers.h"
+#include "base/containers/linked_list.h"
#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "base/stl_util.h"
@@ -74,7 +73,8 @@ enum HttpMethod {
} // namespace
// CertNetFetcherImpl::RequestImpl tracks an outstanding call to Fetch().
-class CertNetFetcherImpl::RequestImpl : public CertNetFetcher::Request {
+class CertNetFetcherImpl::RequestImpl : public CertNetFetcher::Request,
+ public base::LinkNode<RequestImpl> {
davidben 2015/04/08 22:45:33 Huh, I didn't know that existed. Neat.
public:
RequestImpl(Job* job, const FetchCallback& callback)
: callback_(callback), job_(job) {
@@ -170,7 +170,7 @@ class CertNetFetcherImpl::Job : public URLRequest::Delegate {
private:
// The pointers in RequestList are not owned by the Job.
- using RequestList = std::deque<RequestImpl*>;
+ using RequestList = base::LinkedList<RequestImpl>;
// Implementation of URLRequest::Delegate
void OnReceivedRedirect(URLRequest* request,
@@ -244,9 +244,16 @@ CertNetFetcherImpl::Job::~Job() {
void CertNetFetcherImpl::Job::Cancel() {
parent_ = nullptr;
- for (RequestImpl* request : requests_)
- request->OnJobCancelled(this);
- requests_.clear();
+ // Notify each request of cancellation and remove it from the list.
+ for (base::LinkNode<RequestImpl>* current = requests_.head();
+ current != requests_.end();) {
+ base::LinkNode<RequestImpl>* next = current->next();
+ current->value()->OnJobCancelled(this);
+ current->RemoveFromList();
+ current = next;
+ }
+
+ DCHECK(requests_.empty());
Stop();
}
@@ -254,18 +261,14 @@ void CertNetFetcherImpl::Job::Cancel() {
scoped_ptr<CertNetFetcher::Request> CertNetFetcherImpl::Job::CreateRequest(
const FetchCallback& callback) {
scoped_ptr<RequestImpl> request(new RequestImpl(this, callback));
- requests_.push_back(request.get());
+ requests_.Append(request.get());
return request.Pass();
}
void CertNetFetcherImpl::Job::DetachRequest(RequestImpl* request) {
scoped_ptr<Job> delete_this;
- // TODO(eroman): If a lot of requests are cancelled this is not efficient.
- RequestList::iterator it =
- std::find(requests_.begin(), requests_.end(), request);
- CHECK(it != requests_.end());
- requests_.erase(it);
+ request->RemoveFromList();
// If there are no longer any requests attached to the job then
// cancel and delete it.
@@ -413,9 +416,9 @@ void CertNetFetcherImpl::Job::OnJobCompleted() {
parent_->SetCurrentlyCompletingJob(this);
while (!requests_.empty()) {
- RequestImpl* request = requests_.front();
- requests_.pop_front();
- request->OnJobCompleted(this, result_net_error_, response_body_);
+ base::LinkNode<RequestImpl>* request = requests_.head();
+ request->RemoveFromList();
+ request->value()->OnJobCompleted(this, result_net_error_, response_body_);
}
if (parent_)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698