| 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_service.h" | 5 #include "chrome/browser/search_engines/template_url_service.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // be replaced. We do this to ensure that if the user assigns a different | 403 // be replaced. We do this to ensure that if the user assigns a different |
| 404 // keyword to a generated TemplateURL, we won't regenerate another keyword for | 404 // keyword to a generated TemplateURL, we won't regenerate another keyword for |
| 405 // the same host. | 405 // the same host. |
| 406 return !url.is_valid() || url.host().empty() || | 406 return !url.is_valid() || url.host().empty() || |
| 407 CanReplaceKeywordForHost(url.host(), template_url_to_replace); | 407 CanReplaceKeywordForHost(url.host(), template_url_to_replace); |
| 408 } | 408 } |
| 409 | 409 |
| 410 void TemplateURLService::FindMatchingKeywords( | 410 void TemplateURLService::FindMatchingKeywords( |
| 411 const string16& prefix, | 411 const string16& prefix, |
| 412 bool support_replacement_only, | 412 bool support_replacement_only, |
| 413 std::vector<string16>* matches) const { | 413 TemplateURLVector* matches) const { |
| 414 // Sanity check args. | 414 // Sanity check args. |
| 415 if (prefix.empty()) | 415 if (prefix.empty()) |
| 416 return; | 416 return; |
| 417 DCHECK(matches != NULL); | 417 DCHECK(matches != NULL); |
| 418 DCHECK(matches->empty()); // The code for exact matches assumes this. | 418 DCHECK(matches->empty()); // The code for exact matches assumes this. |
| 419 | 419 |
| 420 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair | 420 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
| 421 TemplateURL* const kNullTemplateURL = NULL; | 421 TemplateURL* const kNullTemplateURL = NULL; |
| 422 | 422 |
| 423 // Find matching keyword range. Searches the element map for keywords | 423 // Find matching keyword range. Searches the element map for keywords |
| 424 // beginning with |prefix| and stores the endpoints of the resulting set in | 424 // beginning with |prefix| and stores the endpoints of the resulting set in |
| 425 // |match_range|. | 425 // |match_range|. |
| 426 const std::pair<KeywordToTemplateMap::const_iterator, | 426 const std::pair<KeywordToTemplateMap::const_iterator, |
| 427 KeywordToTemplateMap::const_iterator> match_range( | 427 KeywordToTemplateMap::const_iterator> match_range( |
| 428 std::equal_range( | 428 std::equal_range( |
| 429 keyword_to_template_map_.begin(), keyword_to_template_map_.end(), | 429 keyword_to_template_map_.begin(), keyword_to_template_map_.end(), |
| 430 KeywordToTemplateMap::value_type(prefix, kNullTemplateURL), | 430 KeywordToTemplateMap::value_type(prefix, kNullTemplateURL), |
| 431 LessWithPrefix())); | 431 LessWithPrefix())); |
| 432 | 432 |
| 433 // Return vector of matching keywords. | 433 // Return vector of matching keywords. |
| 434 for (KeywordToTemplateMap::const_iterator i(match_range.first); | 434 for (KeywordToTemplateMap::const_iterator i(match_range.first); |
| 435 i != match_range.second; ++i) { | 435 i != match_range.second; ++i) { |
| 436 if (!support_replacement_only || i->second->url_ref().SupportsReplacement()) | 436 if (!support_replacement_only || i->second->url_ref().SupportsReplacement()) |
| 437 matches->push_back(i->first); | 437 matches->push_back(i->second); |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( | 441 TemplateURL* TemplateURLService::GetTemplateURLForKeyword( |
| 442 const string16& keyword) { | 442 const string16& keyword) { |
| 443 KeywordToTemplateMap::const_iterator elem( | 443 KeywordToTemplateMap::const_iterator elem( |
| 444 keyword_to_template_map_.find(keyword)); | 444 keyword_to_template_map_.find(keyword)); |
| 445 if (elem != keyword_to_template_map_.end()) | 445 if (elem != keyword_to_template_map_.end()) |
| 446 return elem->second; | 446 return elem->second; |
| 447 return ((!loaded_ || load_failed_) && | 447 return ((!loaded_ || load_failed_) && |
| (...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2524 // Don't log anything if the user has a NULL default search provider. A | 2524 // Don't log anything if the user has a NULL default search provider. A |
| 2525 // logged value of 0 indicates a custom default search provider. | 2525 // logged value of 0 indicates a custom default search provider. |
| 2526 if (default_search_provider_) { | 2526 if (default_search_provider_) { |
| 2527 UMA_HISTOGRAM_ENUMERATION( | 2527 UMA_HISTOGRAM_ENUMERATION( |
| 2528 kDSPHistogramName, | 2528 kDSPHistogramName, |
| 2529 default_search_provider_->prepopulate_id(), | 2529 default_search_provider_->prepopulate_id(), |
| 2530 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); | 2530 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); |
| 2531 } | 2531 } |
| 2532 } | 2532 } |
| 2533 } | 2533 } |
| OLD | NEW |