Chromium Code Reviews| 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 "chrome/browser/search_engines/template_url.h" | 5 #include "chrome/browser/search_engines/template_url.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 default: | 361 default: |
| 362 NOTREACHED(); | 362 NOTREACHED(); |
| 363 break; | 363 break; |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 return url; | 367 return url; |
| 368 } | 368 } |
| 369 | 369 |
| 370 bool TemplateURLRef::IsValid() const { | 370 bool TemplateURLRef::IsValid() const { |
| 371 UIThreadSearchTermsData search_terms_data(owner_->profile()); | 371 // Do not use a UIThreadSearchTermsData if a profile wasn't provided as it |
| 372 return IsValidUsingTermsData(search_terms_data); | 372 // results in the same thing (relevant UIThreadSearchTermsData methods default |
|
Peter Kasting
2013/04/17 22:11:56
This is the wrong layer to be doing this. All Tem
gab
2013/04/17 22:46:50
Sounds good, hesitated between the two, PTAL.
| |
| 373 // to SearchTermsData methods when the profile is NULL), but prevents | |
| 374 // validity checks on non-UI threads. | |
| 375 scoped_ptr<SearchTermsData> search_terms_data(owner_->profile() ? | |
| 376 new UIThreadSearchTermsData(owner_->profile()) : new SearchTermsData()); | |
| 377 return IsValidUsingTermsData(*search_terms_data); | |
| 373 } | 378 } |
| 374 | 379 |
| 375 bool TemplateURLRef::IsValidUsingTermsData( | 380 bool TemplateURLRef::IsValidUsingTermsData( |
| 376 const SearchTermsData& search_terms_data) const { | 381 const SearchTermsData& search_terms_data) const { |
| 377 ParseIfNecessaryUsingTermsData(search_terms_data); | 382 ParseIfNecessaryUsingTermsData(search_terms_data); |
| 378 return valid_; | 383 return valid_; |
| 379 } | 384 } |
| 380 | 385 |
| 381 string16 TemplateURLRef::DisplayURL() const { | 386 string16 TemplateURLRef::DisplayURL() const { |
| 382 ParseIfNecessary(); | 387 ParseIfNecessary(); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 // patterns. This means that given patterns | 1001 // patterns. This means that given patterns |
| 997 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1002 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 998 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1003 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 999 // return false. This is important for at least Google, where such URLs | 1004 // return false. This is important for at least Google, where such URLs |
| 1000 // are invalid. | 1005 // are invalid. |
| 1001 return !search_terms->empty(); | 1006 return !search_terms->empty(); |
| 1002 } | 1007 } |
| 1003 } | 1008 } |
| 1004 return false; | 1009 return false; |
| 1005 } | 1010 } |
| OLD | NEW |