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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 std::string osd_url(initializers[i].url); | 1384 std::string osd_url(initializers[i].url); |
1385 osd_url.replace(template_position, arraysize(kTemplateParameter) - 1, | 1385 osd_url.replace(template_position, arraysize(kTemplateParameter) - 1, |
1386 kSearchTermParameter); | 1386 kSearchTermParameter); |
1387 | 1387 |
1388 // TemplateURLService ends up owning the TemplateURL, don't try and free | 1388 // TemplateURLService ends up owning the TemplateURL, don't try and free |
1389 // it. | 1389 // it. |
1390 TemplateURLData data; | 1390 TemplateURLData data; |
1391 data.short_name = UTF8ToUTF16(initializers[i].content); | 1391 data.short_name = UTF8ToUTF16(initializers[i].content); |
1392 data.SetKeyword(UTF8ToUTF16(initializers[i].keyword)); | 1392 data.SetKeyword(UTF8ToUTF16(initializers[i].keyword)); |
1393 data.SetURL(osd_url); | 1393 data.SetURL(osd_url); |
1394 AddNoNotify(new TemplateURL(profile_, data), true); | 1394 TemplateURL* template_url = new TemplateURL(profile_, data); |
| 1395 AddNoNotify(template_url, true); |
| 1396 |
| 1397 // Set the first provided identifier to be the default. |
| 1398 if (!i) |
| 1399 SetDefaultSearchProviderNoNotify(template_url); |
1395 } | 1400 } |
1396 } | 1401 } |
1397 | 1402 |
1398 // Initialize default search. | 1403 // Initialize default search. |
1399 UpdateDefaultSearch(); | 1404 UpdateDefaultSearch(); |
1400 | 1405 |
1401 // Request a server check for the correct Google URL if Google is the | 1406 // Request a server check for the correct Google URL if Google is the |
1402 // default search engine, not in headless mode and not in Chrome Frame. | 1407 // default search engine, not in headless mode and not in Chrome Frame. |
1403 if (profile_ && initial_default_search_provider_.get() && | 1408 if (profile_ && initial_default_search_provider_.get() && |
1404 initial_default_search_provider_->url_ref().HasGoogleBaseURLs()) { | 1409 initial_default_search_provider_->url_ref().HasGoogleBaseURLs()) { |
(...skipping 1119 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 | 2529 // 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. | 2530 // logged value of 0 indicates a custom default search provider. |
2526 if (default_search_provider_) { | 2531 if (default_search_provider_) { |
2527 UMA_HISTOGRAM_ENUMERATION( | 2532 UMA_HISTOGRAM_ENUMERATION( |
2528 kDSPHistogramName, | 2533 kDSPHistogramName, |
2529 default_search_provider_->prepopulate_id(), | 2534 default_search_provider_->prepopulate_id(), |
2530 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); | 2535 TemplateURLPrepopulateData::kMaxPrepopulatedEngineID); |
2531 } | 2536 } |
2532 } | 2537 } |
2533 } | 2538 } |
OLD | NEW |