| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (!source->GetStatus().is_success() || | 105 if (!source->GetStatus().is_success() || |
| 106 ((source->GetResponseCode() != -1) && | 106 ((source->GetResponseCode() != -1) && |
| 107 (source->GetResponseCode() != 200)) || | 107 (source->GetResponseCode() != 200)) || |
| 108 !source->GetResponseAsString(&data)) { | 108 !source->GetResponseAsString(&data)) { |
| 109 fetcher_->RequestCompleted(this); | 109 fetcher_->RequestCompleted(this); |
| 110 // WARNING: RequestCompleted deletes us. | 110 // WARNING: RequestCompleted deletes us. |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 | 113 |
| 114 template_url_ = TemplateURLParser::Parse( | 114 template_url_ = TemplateURLParser::Parse( |
| 115 fetcher_->template_url_service_->search_terms_data(), false, data.data(), | 115 fetcher_->template_url_service_->search_terms_data(), data.data(), |
| 116 data.length(), nullptr); | 116 data.length(), nullptr); |
| 117 if (!template_url_.get() || | 117 if (!template_url_.get() || |
| 118 !template_url_->url_ref().SupportsReplacement( | 118 !template_url_->url_ref().SupportsReplacement( |
| 119 fetcher_->template_url_service_->search_terms_data())) { | 119 fetcher_->template_url_service_->search_terms_data())) { |
| 120 fetcher_->RequestCompleted(this); | 120 fetcher_->RequestCompleted(this); |
| 121 // WARNING: RequestCompleted deletes us. | 121 // WARNING: RequestCompleted deletes us. |
| 122 return; | 122 return; |
| 123 } | 123 } |
| 124 | 124 |
| 125 if (keyword_.empty()) { | 125 if (keyword_.empty()) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |