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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 DCHECK(osdd_url.is_valid()); | 194 DCHECK(osdd_url.is_valid()); |
195 DCHECK(!keyword.empty()); | 195 DCHECK(!keyword.empty()); |
196 | 196 |
197 if (!template_url_service_->loaded()) { | 197 if (!template_url_service_->loaded()) { |
198 // We could try to set up a callback to this function again once the model | 198 // We could try to set up a callback to this function again once the model |
199 // is loaded but meh. | 199 // is loaded but meh. |
200 template_url_service_->Load(); | 200 template_url_service_->Load(); |
201 return; | 201 return; |
202 } | 202 } |
203 | 203 |
204 const TemplateURL* template_url = | 204 TemplateURL* template_url = |
Peter Kasting
2016/12/01 07:38:24
Restore the const here
ltian
2016/12/01 10:02:58
Done.
| |
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 (const auto& request : requests_) { | 211 for (const auto& request : requests_) { |
212 if ((request->url() == osdd_url) || (request->keyword() == keyword)) | 212 if ((request->url() == osdd_url) || (request->keyword() == keyword)) |
213 return; | 213 return; |
214 } | 214 } |
215 | 215 |
216 requests_.push_back(base::MakeUnique<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 auto i = std::find_if(requests_.begin(), requests_.end(), | 221 auto i = std::find_if(requests_.begin(), requests_.end(), |
222 [request](const std::unique_ptr<RequestDelegate>& ptr) { | 222 [request](const std::unique_ptr<RequestDelegate>& ptr) { |
223 return ptr.get() == request; | 223 return ptr.get() == request; |
224 }); | 224 }); |
225 DCHECK(i != requests_.end()); | 225 DCHECK(i != requests_.end()); |
226 requests_.erase(i); | 226 requests_.erase(i); |
227 } | 227 } |
OLD | NEW |