| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/search_engines/template_url_fetcher.h" | 5 #include "components/search_engines/template_url_fetcher.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 const TemplateURL* template_url = | 204 const TemplateURL* template_url = |
| 205 template_url_service_->GetTemplateURLForKeyword(keyword); | 205 template_url_service_->GetTemplateURLForKeyword(keyword); |
| 206 if (template_url && (!template_url->safe_for_autoreplace() || | 206 if (template_url && (!template_url->safe_for_autoreplace() || |
| 207 template_url->originating_url() == osdd_url)) | 207 template_url->originating_url() == osdd_url)) |
| 208 return; | 208 return; |
| 209 | 209 |
| 210 // Make sure we aren't already downloading this request. | 210 // Make sure we aren't already downloading this request. |
| 211 for (Requests::iterator i = requests_.begin(); i != requests_.end(); ++i) { | 211 for (const auto& request : requests_) { |
| 212 if (((*i)->url() == osdd_url) || ((*i)->keyword() == keyword)) | 212 if ((request->url() == osdd_url) || (request->keyword() == keyword)) |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 requests_.push_back(new RequestDelegate( | 216 requests_.push_back(base::MakeUnique<RequestDelegate>( |
| 217 this, keyword, osdd_url, favicon_url, url_fetcher_customize_callback)); | 217 this, keyword, osdd_url, favicon_url, url_fetcher_customize_callback)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 220 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
| 221 Requests::iterator i = | 221 auto i = std::find_if(requests_.begin(), requests_.end(), |
| 222 std::find(requests_.begin(), requests_.end(), request); | 222 [request](const std::unique_ptr<RequestDelegate>& ptr) { |
| 223 return ptr.get() == request; |
| 224 }); |
| 223 DCHECK(i != requests_.end()); | 225 DCHECK(i != requests_.end()); |
| 224 requests_.weak_erase(i); | 226 requests_.erase(i); |
| 225 delete request; | |
| 226 } | 227 } |
| OLD | NEW |