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

Side by Side Diff: chrome/browser/search_engines/template_url_fetcher.cc

Issue 10021008: Reland r131019: Move most TemplateURL data members to a new struct, TemplateURLData. This allows us… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 std::string data; 140 std::string data;
141 if (!source->GetStatus().is_success() || 141 if (!source->GetStatus().is_success() ||
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(), false,
151 data.length(), NULL)); 151 data.data(), data.length(), NULL));
152 if (!template_url_.get() || !template_url_->url_ref().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
(...skipping 25 matching lines...) Expand all
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.
197 template_url_->set_keyword(keyword_); 197 TemplateURLData data(template_url_->data());
198 template_url_->set_originating_url(osdd_url_); 198 data.SetKeyword(keyword_);
199 data.originating_url = osdd_url_;
199 200
200 // The page may have specified a URL to use for favicons, if not, set it. 201 // The page may have specified a URL to use for favicons, if not, set it.
201 if (!template_url_->favicon_url().is_valid()) 202 if (!data.favicon_url.is_valid())
202 template_url_->set_favicon_url(favicon_url_); 203 data.favicon_url = favicon_url_;
203 204
204 switch (provider_type_) { 205 switch (provider_type_) {
205 case AUTODETECTED_PROVIDER: 206 case AUTODETECTED_PROVIDER:
206 // Mark the keyword as replaceable so it can be removed if necessary. 207 // Mark the keyword as replaceable so it can be removed if necessary.
207 template_url_->set_safe_for_autoreplace(true); 208 data.safe_for_autoreplace = true;
208 model->Add(template_url_.release()); 209 model->Add(new TemplateURL(data));
209 break; 210 break;
210 211
211 case EXPLICIT_PROVIDER: 212 case EXPLICIT_PROVIDER:
212 // Confirm addition and allow user to edit default choices. It's ironic 213 // Confirm addition and allow user to edit default choices. It's ironic
213 // that only *non*-autodetected additions get confirmed, but the user 214 // that only *non*-autodetected additions get confirmed, but the user
214 // expects feedback that his action did something. 215 // expects feedback that his action did something.
215 // The source TabContents' delegate takes care of adding the URL to the 216 // The source TabContents' delegate takes care of adding the URL to the
216 // model, which takes ownership, or of deleting it if the add is 217 // model, which takes ownership, or of deleting it if the add is
217 // cancelled. 218 // cancelled.
218 callbacks_->ConfirmAddSearchProvider(template_url_.release(), 219 callbacks_->ConfirmAddSearchProvider(new TemplateURL(data),
219 fetcher_->profile()); 220 fetcher_->profile());
220 break; 221 break;
221 222
222 default: 223 default:
223 NOTREACHED(); 224 NOTREACHED();
224 break; 225 break;
225 } 226 }
226 227
227 fetcher_->RequestCompleted(this); 228 fetcher_->RequestCompleted(this);
228 // WARNING: RequestCompleted deletes us. 229 // WARNING: RequestCompleted deletes us.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 owned_callbacks.release(), provider_type)); 286 owned_callbacks.release(), provider_type));
286 } 287 }
287 288
288 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { 289 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) {
289 Requests::iterator i = 290 Requests::iterator i =
290 std::find(requests_->begin(), requests_->end(), request); 291 std::find(requests_->begin(), requests_->end(), request);
291 DCHECK(i != requests_->end()); 292 DCHECK(i != requests_->end());
292 requests_->erase(i); 293 requests_->erase(i);
293 delete request; 294 delete request;
294 } 295 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.cc ('k') | chrome/browser/search_engines/template_url_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698