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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 fetcher_->profile()); | 170 fetcher_->profile()); |
171 if (!model->loaded()) | 171 if (!model->loaded()) |
172 return; | 172 return; |
173 AddSearchProvider(); | 173 AddSearchProvider(); |
174 // WARNING: AddSearchProvider deletes us. | 174 // WARNING: AddSearchProvider deletes us. |
175 } | 175 } |
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 Profile* profile = fetcher_->profile(); |
181 fetcher_->profile()); | 181 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(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()), | 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. |
197 TemplateURLData data(template_url_->data()); | 197 TemplateURLData data(template_url_->data()); |
198 data.SetKeyword(keyword_); | 198 data.SetKeyword(keyword_); |
199 data.originating_url = osdd_url_; | 199 data.originating_url = osdd_url_; |
200 | 200 |
201 // 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. |
202 if (!data.favicon_url.is_valid()) | 202 if (!data.favicon_url.is_valid()) |
203 data.favicon_url = favicon_url_; | 203 data.favicon_url = favicon_url_; |
204 | 204 |
205 switch (provider_type_) { | 205 switch (provider_type_) { |
206 case AUTODETECTED_PROVIDER: | 206 case AUTODETECTED_PROVIDER: |
207 // 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. |
208 data.safe_for_autoreplace = true; | 208 data.safe_for_autoreplace = true; |
209 model->Add(new TemplateURL(data)); | 209 model->Add(new TemplateURL(profile, data)); |
210 break; | 210 break; |
211 | 211 |
212 case EXPLICIT_PROVIDER: | 212 case EXPLICIT_PROVIDER: |
213 // 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 |
214 // that only *non*-autodetected additions get confirmed, but the user | 214 // that only *non*-autodetected additions get confirmed, but the user |
215 // expects feedback that his action did something. | 215 // expects feedback that his action did something. |
216 // The source WebContents' delegate takes care of adding the URL to the | 216 // The source WebContents' delegate takes care of adding the URL to the |
217 // 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 |
218 // cancelled. | 218 // cancelled. |
219 callbacks_->ConfirmAddSearchProvider(new TemplateURL(data), | 219 callbacks_->ConfirmAddSearchProvider(new TemplateURL(profile, data), |
220 fetcher_->profile()); | 220 profile); |
221 break; | 221 break; |
222 | 222 |
223 default: | 223 default: |
224 NOTREACHED(); | 224 NOTREACHED(); |
225 break; | 225 break; |
226 } | 226 } |
227 | 227 |
228 fetcher_->RequestCompleted(this); | 228 fetcher_->RequestCompleted(this); |
229 // WARNING: RequestCompleted deletes us. | 229 // WARNING: RequestCompleted deletes us. |
230 } | 230 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 owned_callbacks.release(), provider_type)); | 286 owned_callbacks.release(), provider_type)); |
287 } | 287 } |
288 | 288 |
289 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 289 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
290 Requests::iterator i = | 290 Requests::iterator i = |
291 std::find(requests_->begin(), requests_->end(), request); | 291 std::find(requests_->begin(), requests_->end(), request); |
292 DCHECK(i != requests_->end()); | 292 DCHECK(i != requests_->end()); |
293 requests_->erase(i); | 293 requests_->erase(i); |
294 delete request; | 294 delete request; |
295 } | 295 } |
OLD | NEW |