OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/search_engines/template_url_fetcher.h" | 7 #include "chrome/browser/search_engines/template_url_fetcher.h" |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 ((source->GetResponseCode() != -1) && | 142 ((source->GetResponseCode() != -1) && |
143 (source->GetResponseCode() != 200)) || | 143 (source->GetResponseCode() != 200)) || |
144 !source->GetResponseAsString(&data)) { | 144 !source->GetResponseAsString(&data)) { |
145 fetcher_->RequestCompleted(this); | 145 fetcher_->RequestCompleted(this); |
146 // WARNING: RequestCompleted deletes us. | 146 // WARNING: RequestCompleted deletes us. |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 template_url_.reset(TemplateURLParser::Parse(fetcher_->profile(), data.data(), | 150 template_url_.reset(TemplateURLParser::Parse(fetcher_->profile(), data.data(), |
151 data.length(), NULL)); | 151 data.length(), NULL)); |
152 if (!template_url_.get() || !template_url_->url()->SupportsReplacement()) { | 152 if (!template_url_.get() || !template_url_->url_ref().SupportsReplacement()) { |
153 fetcher_->RequestCompleted(this); | 153 fetcher_->RequestCompleted(this); |
154 // WARNING: RequestCompleted deletes us. | 154 // WARNING: RequestCompleted deletes us. |
155 return; | 155 return; |
156 } | 156 } |
157 | 157 |
158 if (provider_type_ != AUTODETECTED_PROVIDER || keyword_.empty()) { | 158 if (provider_type_ != AUTODETECTED_PROVIDER || keyword_.empty()) { |
159 // Use the parser-generated new keyword from the URL in the OSDD for the | 159 // Use the parser-generated new keyword from the URL in the OSDD for the |
160 // non-autodetected case. The existing |keyword_| was generated from the | 160 // non-autodetected case. The existing |keyword_| was generated from the |
161 // URL that hosted the OSDD, which results in the wrong keyword when the | 161 // URL that hosted the OSDD, which results in the wrong keyword when the |
162 // OSDD was located on a third-party site that has nothing in common with | 162 // OSDD was located on a third-party site that has nothing in common with |
(...skipping 13 matching lines...) Expand all Loading... |
176 | 176 |
177 void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { | 177 void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { |
178 DCHECK(template_url_.get()); | 178 DCHECK(template_url_.get()); |
179 DCHECK(!keyword_.empty()); | 179 DCHECK(!keyword_.empty()); |
180 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 180 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
181 fetcher_->profile()); | 181 fetcher_->profile()); |
182 DCHECK(model); | 182 DCHECK(model); |
183 DCHECK(model->loaded()); | 183 DCHECK(model->loaded()); |
184 | 184 |
185 const TemplateURL* existing_url = NULL; | 185 const TemplateURL* existing_url = NULL; |
186 if (model->CanReplaceKeyword(keyword_, GURL(template_url_->url()->url()), | 186 if (model->CanReplaceKeyword(keyword_, GURL(template_url_->url()), |
187 &existing_url)) { | 187 &existing_url)) { |
188 if (existing_url) | 188 if (existing_url) |
189 model->Remove(existing_url); | 189 model->Remove(existing_url); |
190 } else if (provider_type_ == AUTODETECTED_PROVIDER) { | 190 } else if (provider_type_ == AUTODETECTED_PROVIDER) { |
191 fetcher_->RequestCompleted(this); // WARNING: Deletes us! | 191 fetcher_->RequestCompleted(this); // WARNING: Deletes us! |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 // The short name is what is shown to the user. We preserve original names | 195 // The short name is what is shown to the user. We preserve original names |
196 // since it is better when generated keyword in many cases. | 196 // since it is better when generated keyword in many cases. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 owned_callbacks.release(), provider_type)); | 285 owned_callbacks.release(), provider_type)); |
286 } | 286 } |
287 | 287 |
288 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 288 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
289 Requests::iterator i = | 289 Requests::iterator i = |
290 std::find(requests_->begin(), requests_->end(), request); | 290 std::find(requests_->begin(), requests_->end(), request); |
291 DCHECK(i != requests_->end()); | 291 DCHECK(i != requests_->end()); |
292 requests_->erase(i); | 292 requests_->erase(i); |
293 delete request; | 293 delete request; |
294 } | 294 } |
OLD | NEW |