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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); | 484 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); |
485 DCHECK(info); | 485 DCHECK(info); |
486 DCHECK_NE(TemplateURL::NORMAL, template_url->type()); | 486 DCHECK_NE(TemplateURL::NORMAL, template_url->type()); |
487 DCHECK( | 487 DCHECK( |
488 !FindTemplateURLForExtension(info->extension_id, template_url->type())); | 488 !FindTemplateURLForExtension(info->extension_id, template_url->type())); |
489 template_url->extension_info_.swap(info); | 489 template_url->extension_info_.swap(info); |
490 | 490 |
491 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); | 491 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
492 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true); | 492 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true); |
493 if (template_url_ptr) { | 493 if (template_url_ptr) { |
494 if (template_url_ptr->extension_info_->wants_to_be_default_engine) { | |
495 UpdateExtensionDefaultSearchEngine(); | |
496 } | |
497 NotifyObservers(); | 494 NotifyObservers(); |
498 } | 495 } |
499 | 496 |
500 return template_url_ptr; | 497 return template_url_ptr; |
501 } | 498 } |
502 | 499 |
503 void TemplateURLService::Remove(TemplateURL* template_url) { | 500 void TemplateURLService::Remove(TemplateURL* template_url) { |
504 RemoveNoNotify(template_url); | 501 RemoveNoNotify(template_url); |
505 NotifyObservers(); | 502 NotifyObservers(); |
506 } | 503 } |
507 | 504 |
508 void TemplateURLService::RemoveExtensionControlledTURL( | 505 void TemplateURLService::RemoveExtensionControlledTURL( |
509 const std::string& extension_id, | 506 const std::string& extension_id, |
510 TemplateURL::Type type) { | 507 TemplateURL::Type type) { |
511 DCHECK(loaded_); | 508 DCHECK(loaded_); |
512 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); | 509 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); |
513 if (!url) | 510 if (!url) |
514 return; | 511 return; |
515 // NULL this out so that we can call RemoveNoNotify. | 512 // NULL this out so that we can call RemoveNoNotify. |
516 // UpdateExtensionDefaultSearchEngine will cause it to be reset. | |
517 if (default_search_provider_ == url) | 513 if (default_search_provider_ == url) |
518 default_search_provider_ = nullptr; | 514 default_search_provider_ = nullptr; |
519 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); | 515 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
520 RemoveNoNotify(url); | 516 RemoveNoNotify(url); |
521 UpdateExtensionDefaultSearchEngine(); | |
522 NotifyObservers(); | 517 NotifyObservers(); |
523 } | 518 } |
524 | 519 |
525 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { | 520 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { |
526 RemoveAutoGeneratedBetween(created_after, base::Time()); | 521 RemoveAutoGeneratedBetween(created_after, base::Time()); |
527 } | 522 } |
528 | 523 |
529 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, | 524 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, |
530 base::Time created_before) { | 525 base::Time created_before) { |
531 RemoveAutoGeneratedForUrlsBetween(base::Callback<bool(const GURL&)>(), | 526 RemoveAutoGeneratedForUrlsBetween(base::Callback<bool(const GURL&)>(), |
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2453 const TemplateURLData& data, | 2448 const TemplateURLData& data, |
2454 TemplateURL::Type type) { | 2449 TemplateURL::Type type) { |
2455 DCHECK_NE(TemplateURL::NORMAL, type); | 2450 DCHECK_NE(TemplateURL::NORMAL, type); |
2456 for (const auto& turl : template_urls_) { | 2451 for (const auto& turl : template_urls_) { |
2457 if (turl->type() == type && | 2452 if (turl->type() == type && |
2458 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) | 2453 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) |
2459 return turl.get(); | 2454 return turl.get(); |
2460 } | 2455 } |
2461 return nullptr; | 2456 return nullptr; |
2462 } | 2457 } |
2463 | |
2464 void TemplateURLService::UpdateExtensionDefaultSearchEngine() { | |
2465 TemplateURL* most_recently_intalled_default = nullptr; | |
2466 for (const auto& turl : template_urls_) { | |
2467 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) && | |
2468 turl->extension_info_->wants_to_be_default_engine && | |
2469 turl->SupportsReplacement(search_terms_data()) && | |
2470 (!most_recently_intalled_default || | |
2471 (most_recently_intalled_default->extension_info_->install_time < | |
2472 turl->extension_info_->install_time))) | |
2473 most_recently_intalled_default = turl.get(); | |
2474 } | |
2475 | |
2476 if (most_recently_intalled_default) { | |
2477 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | |
2478 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | |
2479 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | |
2480 most_recently_intalled_default->data()); | |
2481 } else { | |
2482 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | |
2483 } | |
2484 } | |
OLD | NEW |