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_service.h" | 5 #include "components/search_engines/template_url_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 // The meaningful keyword length is the length of any portion before the | 182 // The meaningful keyword length is the length of any portion before the |
183 // registry ("co.uk") and its preceding dot. | 183 // registry ("co.uk") and its preceding dot. |
184 return keyword.length() - (registry_length ? (registry_length + 1) : 0); | 184 return keyword.length() - (registry_length ? (registry_length + 1) : 0); |
185 } | 185 } |
186 | 186 |
187 bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls, | 187 bool Contains(TemplateURLService::OwnedTemplateURLVector* template_urls, |
188 TemplateURL* turl) { | 188 TemplateURL* turl) { |
189 return FindTemplateURL(template_urls, turl) != template_urls->end(); | 189 return FindTemplateURL(template_urls, turl) != template_urls->end(); |
190 } | 190 } |
191 | 191 |
192 bool IsCreatedByExtension(TemplateURL* template_url) { | |
193 return template_url->type() == | |
194 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION || | |
195 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; | |
196 } | |
197 | |
192 } // namespace | 198 } // namespace |
193 | 199 |
194 // TemplateURLService::LessWithPrefix ----------------------------------------- | 200 // TemplateURLService::LessWithPrefix ----------------------------------------- |
195 | 201 |
196 class TemplateURLService::LessWithPrefix { | 202 class TemplateURLService::LessWithPrefix { |
197 public: | 203 public: |
198 // We want to find the set of keywords that begin with a prefix. The STL | 204 // We want to find the set of keywords that begin with a prefix. The STL |
199 // algorithms will return the set of elements that are "equal to" the | 205 // algorithms will return the set of elements that are "equal to" the |
200 // prefix, where "equal(x, y)" means "!(cmp(x, y) || cmp(y, x))". When | 206 // prefix, where "equal(x, y)" means "!(cmp(x, y) || cmp(y, x))". When |
201 // cmp() is the typical std::less<>, this results in lexicographic equality; | 207 // cmp() is the typical std::less<>, this results in lexicographic equality; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 DCHECK(!keyword.empty()); | 465 DCHECK(!keyword.empty()); |
460 DCHECK(!url.empty()); | 466 DCHECK(!url.empty()); |
461 template_url->data_.SetShortName(short_name); | 467 template_url->data_.SetShortName(short_name); |
462 template_url->data_.SetKeyword(keyword); | 468 template_url->data_.SetKeyword(keyword); |
463 template_url->SetURL(url); | 469 template_url->SetURL(url); |
464 return Add(std::move(template_url)); | 470 return Add(std::move(template_url)); |
465 } | 471 } |
466 | 472 |
467 TemplateURL* TemplateURLService::AddExtensionControlledTURL( | 473 TemplateURL* TemplateURLService::AddExtensionControlledTURL( |
468 std::unique_ptr<TemplateURL> template_url, | 474 std::unique_ptr<TemplateURL> template_url, |
469 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info) { | 475 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info, |
476 TemplateURL::Type type) { | |
470 DCHECK(loaded_); | 477 DCHECK(loaded_); |
471 DCHECK(template_url); | 478 DCHECK(template_url); |
472 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); | 479 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); |
473 DCHECK(info); | 480 DCHECK(info); |
474 DCHECK_NE(TemplateURL::NORMAL, info->type); | 481 DCHECK_NE(TemplateURL::NORMAL, type); |
475 DCHECK_EQ(info->wants_to_be_default_engine, | 482 DCHECK_EQ(info->wants_to_be_default_engine, |
476 template_url->show_in_default_list()); | 483 template_url->show_in_default_list()); |
477 DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); | 484 DCHECK(!FindTemplateURLForExtension(info->extension_id, type)); |
478 template_url->extension_info_.swap(info); | 485 template_url->extension_info_.swap(info); |
486 template_url->set_type(type); | |
Peter Kasting
2016/09/21 21:45:08
I don't think we should do this. Callers should s
Ian Wen
2016/09/21 23:12:38
Done.
| |
479 | 487 |
480 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); | 488 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
481 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true); | 489 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true); |
482 if (template_url_ptr) { | 490 if (template_url_ptr) { |
483 if (template_url_ptr->extension_info_->wants_to_be_default_engine) { | 491 if (template_url_ptr->extension_info_->wants_to_be_default_engine) { |
484 UpdateExtensionDefaultSearchEngine(); | 492 UpdateExtensionDefaultSearchEngine(); |
485 } | 493 } |
486 NotifyObservers(); | 494 NotifyObservers(); |
487 } | 495 } |
488 | 496 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 | 562 |
555 if (FindTemplateURLForExtension(extension_id, | 563 if (FindTemplateURLForExtension(extension_id, |
556 TemplateURL::OMNIBOX_API_EXTENSION)) | 564 TemplateURL::OMNIBOX_API_EXTENSION)) |
557 return; | 565 return; |
558 | 566 |
559 TemplateURLData data; | 567 TemplateURLData data; |
560 data.SetShortName(base::UTF8ToUTF16(extension_name)); | 568 data.SetShortName(base::UTF8ToUTF16(extension_name)); |
561 data.SetKeyword(base::UTF8ToUTF16(keyword)); | 569 data.SetKeyword(base::UTF8ToUTF16(keyword)); |
562 data.SetURL(template_url_string); | 570 data.SetURL(template_url_string); |
563 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info( | 571 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info( |
564 new TemplateURL::AssociatedExtensionInfo( | 572 new TemplateURL::AssociatedExtensionInfo(extension_id)); |
565 TemplateURL::OMNIBOX_API_EXTENSION, extension_id)); | |
566 AddExtensionControlledTURL(base::MakeUnique<TemplateURL>(data), | 573 AddExtensionControlledTURL(base::MakeUnique<TemplateURL>(data), |
567 std::move(info)); | 574 std::move(info), |
575 TemplateURL::OMNIBOX_API_EXTENSION); | |
568 } | 576 } |
569 | 577 |
570 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { | 578 TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() { |
571 TemplateURLVector result; | 579 TemplateURLVector result; |
572 for (const auto& turl : template_urls_) | 580 for (const auto& turl : template_urls_) |
573 result.push_back(turl.get()); | 581 result.push_back(turl.get()); |
574 return result; | 582 return result; |
575 } | 583 } |
576 | 584 |
577 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { | 585 void TemplateURLService::IncrementUsageCount(TemplateURL* url) { |
578 DCHECK(url); | 586 DCHECK(url); |
579 // Extension-controlled search engines are not persisted. | 587 // Extension-controlled search engines are not persisted. |
580 if (url->GetType() != TemplateURL::NORMAL) | 588 if (url->type() != TemplateURL::NORMAL) |
581 return; | 589 return; |
582 if (!Contains(&template_urls_, url)) | 590 if (!Contains(&template_urls_, url)) |
583 return; | 591 return; |
584 ++url->data_.usage_count; | 592 ++url->data_.usage_count; |
585 | 593 |
586 if (web_data_service_.get()) | 594 if (web_data_service_.get()) |
587 web_data_service_->UpdateKeyword(url->data()); | 595 web_data_service_->UpdateKeyword(url->data()); |
588 } | 596 } |
589 | 597 |
590 void TemplateURLService::ResetTemplateURL(TemplateURL* url, | 598 void TemplateURLService::ResetTemplateURL(TemplateURL* url, |
591 const base::string16& title, | 599 const base::string16& title, |
592 const base::string16& keyword, | 600 const base::string16& keyword, |
593 const std::string& search_url) { | 601 const std::string& search_url) { |
594 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) | 602 if (ResetTemplateURLNoNotify(url, title, keyword, search_url)) |
595 NotifyObservers(); | 603 NotifyObservers(); |
596 } | 604 } |
597 | 605 |
598 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { | 606 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { |
599 return | 607 return |
600 ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || | 608 ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || |
601 (default_search_provider_source_ == | 609 (default_search_provider_source_ == |
602 DefaultSearchManager::FROM_FALLBACK)) && | 610 DefaultSearchManager::FROM_FALLBACK)) && |
603 (url != GetDefaultSearchProvider()) && | 611 (url != GetDefaultSearchProvider()) && |
604 url->url_ref().SupportsReplacement(search_terms_data()) && | 612 url->url_ref().SupportsReplacement(search_terms_data()) && |
605 (url->GetType() == TemplateURL::NORMAL); | 613 (url->type() == TemplateURL::NORMAL); |
606 } | 614 } |
607 | 615 |
608 void TemplateURLService::SetUserSelectedDefaultSearchProvider( | 616 void TemplateURLService::SetUserSelectedDefaultSearchProvider( |
609 TemplateURL* url) { | 617 TemplateURL* url) { |
610 // Omnibox keywords cannot be made default. Extension-controlled search | 618 // Omnibox keywords cannot be made default. Extension-controlled search |
611 // engines can be made default only by the extension itself because they | 619 // engines can be made default only by the extension itself because they |
612 // aren't persisted. | 620 // aren't persisted. |
613 DCHECK(!url || (url->GetType() == TemplateURL::NORMAL)); | 621 DCHECK(!url || !IsCreatedByExtension(url)); |
614 if (load_failed_) { | 622 if (load_failed_) { |
615 // Skip the DefaultSearchManager, which will persist to user preferences. | 623 // Skip the DefaultSearchManager, which will persist to user preferences. |
616 if ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || | 624 if ((default_search_provider_source_ == DefaultSearchManager::FROM_USER) || |
617 (default_search_provider_source_ == | 625 (default_search_provider_source_ == |
618 DefaultSearchManager::FROM_FALLBACK)) { | 626 DefaultSearchManager::FROM_FALLBACK)) { |
619 ApplyDefaultSearchChange(url ? &url->data() : nullptr, | 627 ApplyDefaultSearchChange(url ? &url->data() : nullptr, |
620 DefaultSearchManager::FROM_USER); | 628 DefaultSearchManager::FROM_USER); |
621 } | 629 } |
622 } else { | 630 } else { |
623 // We rely on the DefaultSearchManager to call OnDefaultSearchChange if, in | 631 // We rely on the DefaultSearchManager to call OnDefaultSearchChange if, in |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 | 868 |
861 base::string16 TemplateURLService::GetKeywordShortName( | 869 base::string16 TemplateURLService::GetKeywordShortName( |
862 const base::string16& keyword, | 870 const base::string16& keyword, |
863 bool* is_omnibox_api_extension_keyword) { | 871 bool* is_omnibox_api_extension_keyword) { |
864 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); | 872 const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); |
865 | 873 |
866 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService | 874 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService |
867 // to track changes to the model, this should become a DCHECK. | 875 // to track changes to the model, this should become a DCHECK. |
868 if (template_url) { | 876 if (template_url) { |
869 *is_omnibox_api_extension_keyword = | 877 *is_omnibox_api_extension_keyword = |
870 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; | 878 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; |
871 return template_url->AdjustedShortNameForLocaleDirection(); | 879 return template_url->AdjustedShortNameForLocaleDirection(); |
872 } | 880 } |
873 *is_omnibox_api_extension_keyword = false; | 881 *is_omnibox_api_extension_keyword = false; |
874 return base::string16(); | 882 return base::string16(); |
875 } | 883 } |
876 | 884 |
877 void TemplateURLService::OnHistoryURLVisited(const URLVisitedDetails& details) { | 885 void TemplateURLService::OnHistoryURLVisited(const URLVisitedDetails& details) { |
878 if (!loaded_) | 886 if (!loaded_) |
879 visits_to_add_.push_back(details); | 887 visits_to_add_.push_back(details); |
880 else | 888 else |
(...skipping 16 matching lines...) Expand all Loading... | |
897 syncer::SyncDataList TemplateURLService::GetAllSyncData( | 905 syncer::SyncDataList TemplateURLService::GetAllSyncData( |
898 syncer::ModelType type) const { | 906 syncer::ModelType type) const { |
899 DCHECK_EQ(syncer::SEARCH_ENGINES, type); | 907 DCHECK_EQ(syncer::SEARCH_ENGINES, type); |
900 | 908 |
901 syncer::SyncDataList current_data; | 909 syncer::SyncDataList current_data; |
902 for (const auto& turl : template_urls_) { | 910 for (const auto& turl : template_urls_) { |
903 // We don't sync keywords managed by policy. | 911 // We don't sync keywords managed by policy. |
904 if (turl->created_by_policy()) | 912 if (turl->created_by_policy()) |
905 continue; | 913 continue; |
906 // We don't sync extension-controlled search engines. | 914 // We don't sync extension-controlled search engines. |
907 if (turl->GetType() != TemplateURL::NORMAL) | 915 if (turl->type() != TemplateURL::NORMAL) |
908 continue; | 916 continue; |
909 current_data.push_back(CreateSyncDataFromTemplateURL(*turl)); | 917 current_data.push_back(CreateSyncDataFromTemplateURL(*turl)); |
910 } | 918 } |
911 | 919 |
912 return current_data; | 920 return current_data; |
913 } | 921 } |
914 | 922 |
915 syncer::SyncError TemplateURLService::ProcessSyncChanges( | 923 syncer::SyncError TemplateURLService::ProcessSyncChanges( |
916 const tracked_objects::Location& from_here, | 924 const tracked_objects::Location& from_here, |
917 const syncer::SyncChangeList& change_list) { | 925 const syncer::SyncChangeList& change_list) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1203 return; // Not syncing. | 1211 return; // Not syncing. |
1204 | 1212 |
1205 if (processing_syncer_changes_) | 1213 if (processing_syncer_changes_) |
1206 return; // These are changes originating from us. Ignore. | 1214 return; // These are changes originating from us. Ignore. |
1207 | 1215 |
1208 // Avoid syncing keywords managed by policy. | 1216 // Avoid syncing keywords managed by policy. |
1209 if (turl->created_by_policy()) | 1217 if (turl->created_by_policy()) |
1210 return; | 1218 return; |
1211 | 1219 |
1212 // Avoid syncing extension-controlled search engines. | 1220 // Avoid syncing extension-controlled search engines. |
1213 if (turl->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) | 1221 if (turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) |
1214 return; | 1222 return; |
1215 | 1223 |
1216 syncer::SyncChangeList changes; | 1224 syncer::SyncChangeList changes; |
1217 | 1225 |
1218 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 1226 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
1219 changes.push_back(syncer::SyncChange(from_here, | 1227 changes.push_back(syncer::SyncChange(from_here, |
1220 type, | 1228 type, |
1221 sync_data)); | 1229 sync_data)); |
1222 | 1230 |
1223 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 1231 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1344 UpdateTemplateURLIfPrepopulated(turl.get(), prefs); | 1352 UpdateTemplateURLIfPrepopulated(turl.get(), prefs); |
1345 | 1353 |
1346 // We used to sync keywords associated with omnibox extensions, but no longer | 1354 // We used to sync keywords associated with omnibox extensions, but no longer |
1347 // want to. However, if we delete these keywords from sync, we'll break any | 1355 // want to. However, if we delete these keywords from sync, we'll break any |
1348 // synced old versions of Chrome which were relying on them. Instead, for now | 1356 // synced old versions of Chrome which were relying on them. Instead, for now |
1349 // we simply ignore these. | 1357 // we simply ignore these. |
1350 // TODO(vasilii): After a few Chrome versions, change this to go ahead and | 1358 // TODO(vasilii): After a few Chrome versions, change this to go ahead and |
1351 // delete these from sync. | 1359 // delete these from sync. |
1352 DCHECK(client); | 1360 DCHECK(client); |
1353 client->RestoreExtensionInfoIfNecessary(turl.get()); | 1361 client->RestoreExtensionInfoIfNecessary(turl.get()); |
1354 if (turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) | 1362 if (turl->type() == TemplateURL::OMNIBOX_API_EXTENSION) |
1355 return nullptr; | 1363 return nullptr; |
1356 | 1364 |
1357 DCHECK_EQ(TemplateURL::NORMAL, turl->GetType()); | 1365 DCHECK_EQ(TemplateURL::NORMAL, turl->type()); |
1358 if (reset_keyword || deduped) { | 1366 if (reset_keyword || deduped) { |
1359 if (reset_keyword) | 1367 if (reset_keyword) |
1360 turl->ResetKeywordIfNecessary(search_terms_data, true); | 1368 turl->ResetKeywordIfNecessary(search_terms_data, true); |
1361 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); | 1369 syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); |
1362 change_list->push_back(syncer::SyncChange(FROM_HERE, | 1370 change_list->push_back(syncer::SyncChange(FROM_HERE, |
1363 syncer::SyncChange::ACTION_UPDATE, | 1371 syncer::SyncChange::ACTION_UPDATE, |
1364 sync_data)); | 1372 sync_data)); |
1365 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword(search_terms_data)) { | 1373 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword(search_terms_data)) { |
1366 if (!existing_turl) { | 1374 if (!existing_turl) { |
1367 // We're adding a new TemplateURL that uses the Google base URL, so set | 1375 // We're adding a new TemplateURL that uses the Google base URL, so set |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1458 // extension keywords and how they can coexist with non-extension keywords. | 1466 // extension keywords and how they can coexist with non-extension keywords. |
1459 // In the case of more than one extension, we use the most recently | 1467 // In the case of more than one extension, we use the most recently |
1460 // installed (which will be the most recently added, which will have the | 1468 // installed (which will be the most recently added, which will have the |
1461 // highest ID). | 1469 // highest ID). |
1462 TemplateURL* best_fallback = nullptr; | 1470 TemplateURL* best_fallback = nullptr; |
1463 for (const auto& turl : template_urls_) { | 1471 for (const auto& turl : template_urls_) { |
1464 // This next statement relies on the fact that there can only be one | 1472 // This next statement relies on the fact that there can only be one |
1465 // non-Omnibox API TemplateURL with a given keyword. | 1473 // non-Omnibox API TemplateURL with a given keyword. |
1466 if ((turl.get() != template_url) && (turl->keyword() == keyword) && | 1474 if ((turl.get() != template_url) && (turl->keyword() == keyword) && |
1467 (!best_fallback || | 1475 (!best_fallback || |
1468 (best_fallback->GetType() != TemplateURL::OMNIBOX_API_EXTENSION) || | 1476 (best_fallback->type() != TemplateURL::OMNIBOX_API_EXTENSION) || |
1469 ((turl->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) && | 1477 ((turl->type() == TemplateURL::OMNIBOX_API_EXTENSION) && |
1470 (turl->id() > best_fallback->id())))) | 1478 (turl->id() > best_fallback->id())))) |
1471 best_fallback = turl.get(); | 1479 best_fallback = turl.get(); |
1472 } | 1480 } |
1473 RemoveFromDomainMap(template_url); | 1481 RemoveFromDomainMap(template_url); |
1474 if (best_fallback) { | 1482 if (best_fallback) { |
1475 AddToMap(best_fallback); | 1483 AddToMap(best_fallback); |
1476 AddToDomainMap(best_fallback); | 1484 AddToDomainMap(best_fallback); |
1477 } else { | 1485 } else { |
1478 keyword_to_turl_and_length_.erase(keyword); | 1486 keyword_to_turl_and_length_.erase(keyword); |
1479 } | 1487 } |
1480 } | 1488 } |
1481 | 1489 |
1482 if (template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) | 1490 if (template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION) |
1483 return; | 1491 return; |
1484 | 1492 |
1485 if (!template_url->sync_guid().empty()) | 1493 if (!template_url->sync_guid().empty()) |
1486 guid_to_turl_.erase(template_url->sync_guid()); | 1494 guid_to_turl_.erase(template_url->sync_guid()); |
1487 // |provider_map_| is only initialized after loading has completed. | 1495 // |provider_map_| is only initialized after loading has completed. |
1488 if (loaded_) { | 1496 if (loaded_) { |
1489 provider_map_->Remove(template_url); | 1497 provider_map_->Remove(template_url); |
1490 } | 1498 } |
1491 } | 1499 } |
1492 | 1500 |
1493 void TemplateURLService::AddToMaps(TemplateURL* template_url) { | 1501 void TemplateURLService::AddToMaps(TemplateURL* template_url) { |
1494 bool template_url_is_omnibox_api = | 1502 bool template_url_is_omnibox_api = |
1495 template_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; | 1503 template_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; |
1496 const base::string16& keyword = template_url->keyword(); | 1504 const base::string16& keyword = template_url->keyword(); |
1497 KeywordToTURLAndMeaningfulLength::const_iterator i = | 1505 KeywordToTURLAndMeaningfulLength::const_iterator i = |
1498 keyword_to_turl_and_length_.find(keyword); | 1506 keyword_to_turl_and_length_.find(keyword); |
1499 if (i == keyword_to_turl_and_length_.end()) { | 1507 if (i == keyword_to_turl_and_length_.end()) { |
1500 AddToMap(template_url); | 1508 AddToMap(template_url); |
1501 AddToDomainMap(template_url); | 1509 AddToDomainMap(template_url); |
1502 } else { | 1510 } else { |
1503 const TemplateURL* existing_url = i->second.first; | 1511 const TemplateURL* existing_url = i->second.first; |
1504 // We should only have overlapping keywords when at least one comes from | 1512 // We should only have overlapping keywords when at least one comes from |
1505 // an extension. In that case, the ranking order is: | 1513 // an extension. In that case, the ranking order is: |
1506 // Manually-modified keywords > extension keywords > replaceable keywords | 1514 // Manually-modified keywords > extension keywords > replaceable keywords |
1507 // When there are multiple extensions, the last-added wins. | 1515 // When there are multiple extensions, the last-added wins. |
1508 bool existing_url_is_omnibox_api = | 1516 bool existing_url_is_omnibox_api = |
1509 existing_url->GetType() == TemplateURL::OMNIBOX_API_EXTENSION; | 1517 existing_url->type() == TemplateURL::OMNIBOX_API_EXTENSION; |
1510 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api); | 1518 DCHECK(existing_url_is_omnibox_api || template_url_is_omnibox_api); |
1511 if (existing_url_is_omnibox_api ? | 1519 if (existing_url_is_omnibox_api ? |
1512 !CanReplace(template_url) : CanReplace(existing_url)) { | 1520 !CanReplace(template_url) : CanReplace(existing_url)) { |
1513 RemoveFromDomainMap(existing_url); | 1521 RemoveFromDomainMap(existing_url); |
1514 AddToMap(template_url); | 1522 AddToMap(template_url); |
1515 AddToDomainMap(template_url); | 1523 AddToDomainMap(template_url); |
1516 } | 1524 } |
1517 } | 1525 } |
1518 | 1526 |
1519 if (template_url_is_omnibox_api) | 1527 if (template_url_is_omnibox_api) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1633 } | 1641 } |
1634 | 1642 |
1635 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { | 1643 bool TemplateURLService::CanReplace(const TemplateURL* t_url) { |
1636 return (t_url != default_search_provider_ && !t_url->show_in_default_list() && | 1644 return (t_url != default_search_provider_ && !t_url->show_in_default_list() && |
1637 t_url->safe_for_autoreplace()); | 1645 t_url->safe_for_autoreplace()); |
1638 } | 1646 } |
1639 | 1647 |
1640 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( | 1648 TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword( |
1641 const base::string16& keyword) { | 1649 const base::string16& keyword) { |
1642 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); | 1650 TemplateURL* keyword_turl = GetTemplateURLForKeyword(keyword); |
1643 if (!keyword_turl || (keyword_turl->GetType() == TemplateURL::NORMAL)) | 1651 if (!keyword_turl || (keyword_turl->type() == TemplateURL::NORMAL)) |
1644 return keyword_turl; | 1652 return keyword_turl; |
1645 // The extension keyword in the model may be hiding a replaceable | 1653 // The extension keyword in the model may be hiding a replaceable |
1646 // non-extension keyword. Look for it. | 1654 // non-extension keyword. Look for it. |
1647 for (const auto& turl : template_urls_) { | 1655 for (const auto& turl : template_urls_) { |
1648 if ((turl->GetType() == TemplateURL::NORMAL) && | 1656 if ((turl->type() == TemplateURL::NORMAL) && |
1649 (turl->keyword() == keyword)) | 1657 (turl->keyword() == keyword)) |
1650 return turl.get(); | 1658 return turl.get(); |
1651 } | 1659 } |
1652 return nullptr; | 1660 return nullptr; |
1653 } | 1661 } |
1654 | 1662 |
1655 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, | 1663 bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, |
1656 const TemplateURL& new_values) { | 1664 const TemplateURL& new_values) { |
1657 DCHECK(existing_turl); | 1665 DCHECK(existing_turl); |
1658 if (!Contains(&template_urls_, existing_turl)) | 1666 if (!Contains(&template_urls_, existing_turl)) |
1659 return false; | 1667 return false; |
1660 | 1668 |
1661 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->GetType()); | 1669 DCHECK_NE(TemplateURL::OMNIBOX_API_EXTENSION, existing_turl->type()); |
1662 | 1670 |
1663 base::string16 old_keyword(existing_turl->keyword()); | 1671 base::string16 old_keyword(existing_turl->keyword()); |
1664 keyword_to_turl_and_length_.erase(old_keyword); | 1672 keyword_to_turl_and_length_.erase(old_keyword); |
1665 RemoveFromDomainMap(existing_turl); | 1673 RemoveFromDomainMap(existing_turl); |
1666 if (!existing_turl->sync_guid().empty()) | 1674 if (!existing_turl->sync_guid().empty()) |
1667 guid_to_turl_.erase(existing_turl->sync_guid()); | 1675 guid_to_turl_.erase(existing_turl->sync_guid()); |
1668 | 1676 |
1669 // |provider_map_| is only initialized after loading has completed. | 1677 // |provider_map_| is only initialized after loading has completed. |
1670 if (loaded_) | 1678 if (loaded_) |
1671 provider_map_->Remove(existing_turl); | 1679 provider_map_->Remove(existing_turl); |
(...skipping 15 matching lines...) Expand all Loading... | |
1687 } else { | 1695 } else { |
1688 // We can theoretically reach here in two cases: | 1696 // We can theoretically reach here in two cases: |
1689 // * There is an existing extension keyword and sync brings in a rename of | 1697 // * There is an existing extension keyword and sync brings in a rename of |
1690 // a non-extension keyword to match. In this case we just need to pick | 1698 // a non-extension keyword to match. In this case we just need to pick |
1691 // which keyword has priority to update the keyword map. | 1699 // which keyword has priority to update the keyword map. |
1692 // * Autogeneration of the keyword for a Google default search provider | 1700 // * Autogeneration of the keyword for a Google default search provider |
1693 // at load time causes it to conflict with an existing keyword. In this | 1701 // at load time causes it to conflict with an existing keyword. In this |
1694 // case we delete the existing keyword if it's replaceable, or else undo | 1702 // case we delete the existing keyword if it's replaceable, or else undo |
1695 // the change in keyword for |existing_turl|. | 1703 // the change in keyword for |existing_turl|. |
1696 TemplateURL* existing_keyword_turl = i->second.first; | 1704 TemplateURL* existing_keyword_turl = i->second.first; |
1697 if (existing_keyword_turl->GetType() != TemplateURL::NORMAL) { | 1705 if (existing_keyword_turl->type() != TemplateURL::NORMAL) { |
1698 if (!CanReplace(existing_turl)) { | 1706 if (!CanReplace(existing_turl)) { |
1699 AddToMap(existing_turl); | 1707 AddToMap(existing_turl); |
1700 AddToDomainMap(existing_turl); | 1708 AddToDomainMap(existing_turl); |
1701 } | 1709 } |
1702 } else { | 1710 } else { |
1703 if (CanReplace(existing_keyword_turl)) { | 1711 if (CanReplace(existing_keyword_turl)) { |
1704 RemoveNoNotify(existing_keyword_turl); | 1712 RemoveNoNotify(existing_keyword_turl); |
1705 } else { | 1713 } else { |
1706 existing_turl->data_.SetKeyword(old_keyword); | 1714 existing_turl->data_.SetKeyword(old_keyword); |
1707 AddToMap(existing_turl); | 1715 AddToMap(existing_turl); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2007 | 2015 |
2008 // Check whether |template_url|'s keyword conflicts with any already in the | 2016 // Check whether |template_url|'s keyword conflicts with any already in the |
2009 // model. Note that we can reach here during the loading phase while | 2017 // model. Note that we can reach here during the loading phase while |
2010 // processing the template URLs from the web data service. In this case, | 2018 // processing the template URLs from the web data service. In this case, |
2011 // GetTemplateURLForKeyword() will look not only at what's already in the | 2019 // GetTemplateURLForKeyword() will look not only at what's already in the |
2012 // model, but at the |initial_default_search_provider_|. Since this engine | 2020 // model, but at the |initial_default_search_provider_|. Since this engine |
2013 // will presumably also be present in the web data, we need to double-check | 2021 // will presumably also be present in the web data, we need to double-check |
2014 // that any "pre-existing" entries we find are actually coming from | 2022 // that any "pre-existing" entries we find are actually coming from |
2015 // |template_urls_|, lest we detect a "conflict" between the | 2023 // |template_urls_|, lest we detect a "conflict" between the |
2016 // |initial_default_search_provider_| and the web data version of itself. | 2024 // |initial_default_search_provider_| and the web data version of itself. |
2017 if (template_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION && | 2025 if (template_url->type() != TemplateURL::OMNIBOX_API_EXTENSION && |
2018 existing_keyword_turl && | 2026 existing_keyword_turl && |
2019 existing_keyword_turl->GetType() != TemplateURL::OMNIBOX_API_EXTENSION && | 2027 existing_keyword_turl->type() != TemplateURL::OMNIBOX_API_EXTENSION && |
2020 Contains(&template_urls_, existing_keyword_turl)) { | 2028 Contains(&template_urls_, existing_keyword_turl)) { |
2021 DCHECK_NE(existing_keyword_turl, template_url.get()); | 2029 DCHECK_NE(existing_keyword_turl, template_url.get()); |
2022 // Only replace one of the TemplateURLs if they are either both extensions, | 2030 // Only replace one of the TemplateURLs if they are either both extensions, |
2023 // or both not extensions. | 2031 // or both not extensions. |
2024 bool are_same_type = existing_keyword_turl->GetType() == | 2032 bool are_same_type = IsCreatedByExtension(existing_keyword_turl) == |
2025 template_url->GetType(); | 2033 IsCreatedByExtension(template_url.get()); |
2026 if (CanReplace(existing_keyword_turl) && are_same_type) { | 2034 if (CanReplace(existing_keyword_turl) && are_same_type) { |
2027 RemoveNoNotify(existing_keyword_turl); | 2035 RemoveNoNotify(existing_keyword_turl); |
2028 } else if (CanReplace(template_url.get()) && are_same_type) { | 2036 } else if (CanReplace(template_url.get()) && are_same_type) { |
2029 return nullptr; | 2037 return nullptr; |
2030 } else { | 2038 } else { |
2031 base::string16 new_keyword = | 2039 base::string16 new_keyword = |
2032 UniquifyKeyword(*existing_keyword_turl, false); | 2040 UniquifyKeyword(*existing_keyword_turl, false); |
2033 ResetTemplateURLNoNotify(existing_keyword_turl, | 2041 ResetTemplateURLNoNotify(existing_keyword_turl, |
2034 existing_keyword_turl->short_name(), new_keyword, | 2042 existing_keyword_turl->short_name(), new_keyword, |
2035 existing_keyword_turl->url()); | 2043 existing_keyword_turl->url()); |
2036 } | 2044 } |
2037 } | 2045 } |
2038 TemplateURL* template_url_ptr = template_url.get(); | 2046 TemplateURL* template_url_ptr = template_url.get(); |
2039 template_urls_.push_back(std::move(template_url)); | 2047 template_urls_.push_back(std::move(template_url)); |
2040 AddToMaps(template_url_ptr); | 2048 AddToMaps(template_url_ptr); |
2041 | 2049 |
2042 if (newly_adding && (template_url_ptr->GetType() == TemplateURL::NORMAL)) { | 2050 if (newly_adding && (template_url_ptr->type() == TemplateURL::NORMAL)) { |
2043 if (web_data_service_.get()) | 2051 if (web_data_service_.get()) |
2044 web_data_service_->AddKeyword(template_url_ptr->data()); | 2052 web_data_service_->AddKeyword(template_url_ptr->data()); |
2045 | 2053 |
2046 // Inform sync of the addition. Note that this will assign a GUID to | 2054 // Inform sync of the addition. Note that this will assign a GUID to |
2047 // template_url and add it to the guid_to_turl_. | 2055 // template_url and add it to the guid_to_turl_. |
2048 ProcessTemplateURLChange(FROM_HERE, template_url_ptr, | 2056 ProcessTemplateURLChange(FROM_HERE, template_url_ptr, |
2049 syncer::SyncChange::ACTION_ADD); | 2057 syncer::SyncChange::ACTION_ADD); |
2050 } | 2058 } |
2051 | 2059 |
2052 return template_url_ptr; | 2060 return template_url_ptr; |
2053 } | 2061 } |
2054 | 2062 |
2055 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { | 2063 void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { |
2056 DCHECK(template_url != default_search_provider_); | 2064 DCHECK(template_url != default_search_provider_); |
2057 | 2065 |
2058 auto i = FindTemplateURL(&template_urls_, template_url); | 2066 auto i = FindTemplateURL(&template_urls_, template_url); |
2059 if (i == template_urls_.end()) | 2067 if (i == template_urls_.end()) |
2060 return; | 2068 return; |
2061 | 2069 |
2062 RemoveFromMaps(template_url); | 2070 RemoveFromMaps(template_url); |
2063 | 2071 |
2064 // Remove it from the vector containing all TemplateURLs. | 2072 // Remove it from the vector containing all TemplateURLs. |
2065 std::unique_ptr<TemplateURL> scoped_turl = std::move(*i); | 2073 std::unique_ptr<TemplateURL> scoped_turl = std::move(*i); |
2066 template_urls_.erase(i); | 2074 template_urls_.erase(i); |
2067 | 2075 |
2068 if (template_url->GetType() == TemplateURL::NORMAL) { | 2076 if (template_url->type() == TemplateURL::NORMAL) { |
2069 if (web_data_service_.get()) | 2077 if (web_data_service_.get()) |
2070 web_data_service_->RemoveKeyword(template_url->id()); | 2078 web_data_service_->RemoveKeyword(template_url->id()); |
2071 | 2079 |
2072 // Inform sync of the deletion. | 2080 // Inform sync of the deletion. |
2073 ProcessTemplateURLChange(FROM_HERE, | 2081 ProcessTemplateURLChange(FROM_HERE, |
2074 template_url, | 2082 template_url, |
2075 syncer::SyncChange::ACTION_DELETE); | 2083 syncer::SyncChange::ACTION_DELETE); |
2076 | 2084 |
2077 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, | 2085 UMA_HISTOGRAM_ENUMERATION(kDeleteSyncedEngineHistogramName, |
2078 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); | 2086 DELETE_ENGINE_USER_ACTION, DELETE_ENGINE_MAX); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2178 bool force) { | 2186 bool force) { |
2179 if (!force) { | 2187 if (!force) { |
2180 // Already unique. | 2188 // Already unique. |
2181 if (!GetTemplateURLForKeyword(turl.keyword())) | 2189 if (!GetTemplateURLForKeyword(turl.keyword())) |
2182 return turl.keyword(); | 2190 return turl.keyword(); |
2183 | 2191 |
2184 // First, try to return the generated keyword for the TemplateURL (except | 2192 // First, try to return the generated keyword for the TemplateURL (except |
2185 // for extensions, as their keywords are not associated with their URLs). | 2193 // for extensions, as their keywords are not associated with their URLs). |
2186 GURL gurl(turl.url()); | 2194 GURL gurl(turl.url()); |
2187 if (gurl.is_valid() && | 2195 if (gurl.is_valid() && |
2188 (turl.GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { | 2196 (turl.type() != TemplateURL::OMNIBOX_API_EXTENSION)) { |
2189 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl); | 2197 base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl); |
2190 if (!GetTemplateURLForKeyword(keyword_candidate)) | 2198 if (!GetTemplateURLForKeyword(keyword_candidate)) |
2191 return keyword_candidate; | 2199 return keyword_candidate; |
2192 } | 2200 } |
2193 } | 2201 } |
2194 | 2202 |
2195 // We try to uniquify the keyword by appending a special character to the end. | 2203 // We try to uniquify the keyword by appending a special character to the end. |
2196 // This is a best-effort approach where we try to preserve the original | 2204 // This is a best-effort approach where we try to preserve the original |
2197 // keyword and let the user do what they will after our attempt. | 2205 // keyword and let the user do what they will after our attempt. |
2198 base::string16 keyword_candidate(turl.keyword()); | 2206 base::string16 keyword_candidate(turl.keyword()); |
(...skipping 15 matching lines...) Expand all Loading... | |
2214 | 2222 |
2215 void TemplateURLService::ResolveSyncKeywordConflict( | 2223 void TemplateURLService::ResolveSyncKeywordConflict( |
2216 TemplateURL* unapplied_sync_turl, | 2224 TemplateURL* unapplied_sync_turl, |
2217 TemplateURL* applied_sync_turl, | 2225 TemplateURL* applied_sync_turl, |
2218 syncer::SyncChangeList* change_list) { | 2226 syncer::SyncChangeList* change_list) { |
2219 DCHECK(loaded_); | 2227 DCHECK(loaded_); |
2220 DCHECK(unapplied_sync_turl); | 2228 DCHECK(unapplied_sync_turl); |
2221 DCHECK(applied_sync_turl); | 2229 DCHECK(applied_sync_turl); |
2222 DCHECK(change_list); | 2230 DCHECK(change_list); |
2223 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword()); | 2231 DCHECK_EQ(applied_sync_turl->keyword(), unapplied_sync_turl->keyword()); |
2224 DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->GetType()); | 2232 DCHECK_EQ(TemplateURL::NORMAL, applied_sync_turl->type()); |
2225 | 2233 |
2226 // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so | 2234 // Both |unapplied_sync_turl| and |applied_sync_turl| are known to Sync, so |
2227 // don't delete either of them. Instead, determine which is "better" and | 2235 // don't delete either of them. Instead, determine which is "better" and |
2228 // uniquify the other one, sending an update to the server for the updated | 2236 // uniquify the other one, sending an update to the server for the updated |
2229 // entry. | 2237 // entry. |
2230 const bool applied_turl_is_better = | 2238 const bool applied_turl_is_better = |
2231 IsLocalTemplateURLBetter(applied_sync_turl, unapplied_sync_turl); | 2239 IsLocalTemplateURLBetter(applied_sync_turl, unapplied_sync_turl); |
2232 TemplateURL* loser = applied_turl_is_better ? | 2240 TemplateURL* loser = applied_turl_is_better ? |
2233 unapplied_sync_turl : applied_sync_turl; | 2241 unapplied_sync_turl : applied_sync_turl; |
2234 base::string16 new_keyword = UniquifyKeyword(*loser, false); | 2242 base::string16 new_keyword = UniquifyKeyword(*loser, false); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2359 merge_result->set_num_items_added(merge_result->num_items_added() + 1); | 2367 merge_result->set_num_items_added(merge_result->num_items_added() + 1); |
2360 } | 2368 } |
2361 } | 2369 } |
2362 | 2370 |
2363 void TemplateURLService::PatchMissingSyncGUIDs( | 2371 void TemplateURLService::PatchMissingSyncGUIDs( |
2364 OwnedTemplateURLVector* template_urls) { | 2372 OwnedTemplateURLVector* template_urls) { |
2365 DCHECK(template_urls); | 2373 DCHECK(template_urls); |
2366 for (auto& template_url : *template_urls) { | 2374 for (auto& template_url : *template_urls) { |
2367 DCHECK(template_url); | 2375 DCHECK(template_url); |
2368 if (template_url->sync_guid().empty() && | 2376 if (template_url->sync_guid().empty() && |
2369 (template_url->GetType() == TemplateURL::NORMAL)) { | 2377 (template_url->type() == TemplateURL::NORMAL)) { |
2370 template_url->data_.sync_guid = base::GenerateGUID(); | 2378 template_url->data_.sync_guid = base::GenerateGUID(); |
2371 if (web_data_service_.get()) | 2379 if (web_data_service_.get()) |
2372 web_data_service_->UpdateKeyword(template_url->data()); | 2380 web_data_service_->UpdateKeyword(template_url->data()); |
2373 } | 2381 } |
2374 } | 2382 } |
2375 } | 2383 } |
2376 | 2384 |
2377 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { | 2385 void TemplateURLService::OnSyncedDefaultSearchProviderGUIDChanged() { |
2378 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2386 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
2379 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); | 2387 &dsp_change_origin_, DSP_CHANGE_SYNC_PREF); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2426 return turl.get(); | 2434 return turl.get(); |
2427 } | 2435 } |
2428 return nullptr; | 2436 return nullptr; |
2429 } | 2437 } |
2430 | 2438 |
2431 TemplateURL* TemplateURLService::FindTemplateURLForExtension( | 2439 TemplateURL* TemplateURLService::FindTemplateURLForExtension( |
2432 const std::string& extension_id, | 2440 const std::string& extension_id, |
2433 TemplateURL::Type type) { | 2441 TemplateURL::Type type) { |
2434 DCHECK_NE(TemplateURL::NORMAL, type); | 2442 DCHECK_NE(TemplateURL::NORMAL, type); |
2435 for (const auto& turl : template_urls_) { | 2443 for (const auto& turl : template_urls_) { |
2436 if (turl->GetType() == type && turl->GetExtensionId() == extension_id) | 2444 if (turl->type() == type && turl->GetExtensionId() == extension_id) |
2437 return turl.get(); | 2445 return turl.get(); |
2438 } | 2446 } |
2439 return nullptr; | 2447 return nullptr; |
2440 } | 2448 } |
2441 | 2449 |
2442 TemplateURL* TemplateURLService::FindMatchingExtensionTemplateURL( | 2450 TemplateURL* TemplateURLService::FindMatchingExtensionTemplateURL( |
2443 const TemplateURLData& data, | 2451 const TemplateURLData& data, |
2444 TemplateURL::Type type) { | 2452 TemplateURL::Type type) { |
2445 DCHECK_NE(TemplateURL::NORMAL, type); | 2453 DCHECK_NE(TemplateURL::NORMAL, type); |
2446 for (const auto& turl : template_urls_) { | 2454 for (const auto& turl : template_urls_) { |
2447 if (turl->GetType() == type && | 2455 if (turl->type() == type && |
2448 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) | 2456 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) |
2449 return turl.get(); | 2457 return turl.get(); |
2450 } | 2458 } |
2451 return nullptr; | 2459 return nullptr; |
2452 } | 2460 } |
2453 | 2461 |
2454 void TemplateURLService::UpdateExtensionDefaultSearchEngine() { | 2462 void TemplateURLService::UpdateExtensionDefaultSearchEngine() { |
2455 TemplateURL* most_recently_intalled_default = nullptr; | 2463 TemplateURL* most_recently_intalled_default = nullptr; |
2456 for (const auto& turl : template_urls_) { | 2464 for (const auto& turl : template_urls_) { |
2457 if ((turl->GetType() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) && | 2465 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) && |
2458 turl->extension_info_->wants_to_be_default_engine && | 2466 turl->extension_info_->wants_to_be_default_engine && |
2459 turl->SupportsReplacement(search_terms_data()) && | 2467 turl->SupportsReplacement(search_terms_data()) && |
2460 (!most_recently_intalled_default || | 2468 (!most_recently_intalled_default || |
2461 (most_recently_intalled_default->extension_info_->install_time < | 2469 (most_recently_intalled_default->extension_info_->install_time < |
2462 turl->extension_info_->install_time))) | 2470 turl->extension_info_->install_time))) |
2463 most_recently_intalled_default = turl.get(); | 2471 most_recently_intalled_default = turl.get(); |
2464 } | 2472 } |
2465 | 2473 |
2466 if (most_recently_intalled_default) { | 2474 if (most_recently_intalled_default) { |
2467 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2475 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
2468 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2476 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
2469 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2477 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
2470 most_recently_intalled_default->data()); | 2478 most_recently_intalled_default->data()); |
2471 } else { | 2479 } else { |
2472 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2480 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
2473 } | 2481 } |
2474 } | 2482 } |
OLD | NEW |