Chromium Code Reviews| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { | 142 void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { |
| 143 DCHECK(template_url_.get()); | 143 DCHECK(template_url_.get()); |
| 144 DCHECK(!keyword_.empty()); | 144 DCHECK(!keyword_.empty()); |
| 145 TemplateURLService* model = fetcher_->template_url_service_; | 145 TemplateURLService* model = fetcher_->template_url_service_; |
| 146 DCHECK(model); | 146 DCHECK(model); |
| 147 DCHECK(model->loaded()); | 147 DCHECK(model->loaded()); |
| 148 | 148 |
| 149 TemplateURL* existing_url = NULL; | 149 TemplateURL* existing_url = NULL; |
| 150 if (!model->CanAddAutogeneratedKeyword(keyword_, GURL(template_url_->url()), | 150 if (!model->CanAddAutogeneratedKeyword(keyword_, GURL(template_url_->url()), |
| 151 &existing_url)) { | 151 &existing_url)) { |
| 152 model->UpdateTemplateURLVisitTime(existing_url); | |
|
Peter Kasting
2016/11/21 03:35:08
I don't think the changes in this file are the rig
ltian
2016/11/28 22:08:02
Thanks for the info, Peter. Originally I was tryin
| |
| 152 fetcher_->RequestCompleted(this); // WARNING: Deletes us! | 153 fetcher_->RequestCompleted(this); // WARNING: Deletes us! |
| 153 return; | 154 return; |
| 154 } | 155 } |
| 155 | 156 |
| 156 if (existing_url) | 157 if (existing_url) |
| 157 model->Remove(existing_url); | 158 model->Remove(existing_url); |
| 158 | 159 |
| 159 // The short name is what is shown to the user. We preserve original names | 160 // The short name is what is shown to the user. We preserve original names |
| 160 // since it is better when generated keyword in many cases. | 161 // since it is better when generated keyword in many cases. |
| 161 TemplateURLData data(template_url_->data()); | 162 TemplateURLData data(template_url_->data()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 DCHECK(osdd_url.is_valid()); | 195 DCHECK(osdd_url.is_valid()); |
| 195 DCHECK(!keyword.empty()); | 196 DCHECK(!keyword.empty()); |
| 196 | 197 |
| 197 if (!template_url_service_->loaded()) { | 198 if (!template_url_service_->loaded()) { |
| 198 // We could try to set up a callback to this function again once the model | 199 // We could try to set up a callback to this function again once the model |
| 199 // is loaded but meh. | 200 // is loaded but meh. |
| 200 template_url_service_->Load(); | 201 template_url_service_->Load(); |
| 201 return; | 202 return; |
| 202 } | 203 } |
| 203 | 204 |
| 204 const TemplateURL* template_url = | 205 TemplateURL* template_url = |
| 205 template_url_service_->GetTemplateURLForKeyword(keyword); | 206 template_url_service_->GetTemplateURLForKeyword(keyword); |
| 206 if (template_url && (!template_url->safe_for_autoreplace() || | 207 if (template_url && (!template_url->safe_for_autoreplace() || |
| 207 template_url->originating_url() == osdd_url)) | 208 template_url->originating_url() == osdd_url)) { |
| 209 template_url_service_->UpdateTemplateURLVisitTime(template_url); | |
| 208 return; | 210 return; |
| 211 } | |
| 209 | 212 |
| 210 // Make sure we aren't already downloading this request. | 213 // Make sure we aren't already downloading this request. |
| 211 for (const auto& request : requests_) { | 214 for (const auto& request : requests_) { |
| 212 if ((request->url() == osdd_url) || (request->keyword() == keyword)) | 215 if ((request->url() == osdd_url) || (request->keyword() == keyword)) |
| 213 return; | 216 return; |
| 214 } | 217 } |
| 215 | 218 |
| 216 requests_.push_back(base::MakeUnique<RequestDelegate>( | 219 requests_.push_back(base::MakeUnique<RequestDelegate>( |
| 217 this, keyword, osdd_url, favicon_url, url_fetcher_customize_callback)); | 220 this, keyword, osdd_url, favicon_url, url_fetcher_customize_callback)); |
| 218 } | 221 } |
| 219 | 222 |
| 220 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { | 223 void TemplateURLFetcher::RequestCompleted(RequestDelegate* request) { |
| 221 auto i = std::find_if(requests_.begin(), requests_.end(), | 224 auto i = std::find_if(requests_.begin(), requests_.end(), |
| 222 [request](const std::unique_ptr<RequestDelegate>& ptr) { | 225 [request](const std::unique_ptr<RequestDelegate>& ptr) { |
| 223 return ptr.get() == request; | 226 return ptr.get() == request; |
| 224 }); | 227 }); |
| 225 DCHECK(i != requests_.end()); | 228 DCHECK(i != requests_.end()); |
| 226 requests_.erase(i); | 229 requests_.erase(i); |
| 227 } | 230 } |
| OLD | NEW |