Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: components/search_engines/template_url_service.cc

Issue 2479113002: Make extensions DSE persistent in browser prefs (Closed)
Patch Set: Move extension overriden DSE logic to setting_override_api.cc Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 DCHECK_NE(TemplateURL::NORMAL, template_url->type()); 479 DCHECK_NE(TemplateURL::NORMAL, template_url->type());
480 DCHECK_EQ(info->wants_to_be_default_engine, 480 DCHECK_EQ(info->wants_to_be_default_engine,
481 template_url->show_in_default_list()); 481 template_url->show_in_default_list());
482 DCHECK( 482 DCHECK(
483 !FindTemplateURLForExtension(info->extension_id, template_url->type())); 483 !FindTemplateURLForExtension(info->extension_id, template_url->type()));
484 template_url->extension_info_.swap(info); 484 template_url->extension_info_.swap(info);
485 485
486 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 486 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
487 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true); 487 TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true);
488 if (template_url_ptr) { 488 if (template_url_ptr) {
489 if (template_url_ptr->extension_info_->wants_to_be_default_engine) {
490 UpdateExtensionDefaultSearchEngine();
491 }
492 NotifyObservers(); 489 NotifyObservers();
493 } 490 }
494 491
495 return template_url_ptr; 492 return template_url_ptr;
496 } 493 }
497 494
498 void TemplateURLService::Remove(TemplateURL* template_url) { 495 void TemplateURLService::Remove(TemplateURL* template_url) {
499 RemoveNoNotify(template_url); 496 RemoveNoNotify(template_url);
500 NotifyObservers(); 497 NotifyObservers();
501 } 498 }
502 499
503 void TemplateURLService::RemoveExtensionControlledTURL( 500 void TemplateURLService::RemoveExtensionControlledTURL(
504 const std::string& extension_id, 501 const std::string& extension_id,
505 TemplateURL::Type type) { 502 TemplateURL::Type type) {
506 DCHECK(loaded_); 503 DCHECK(loaded_);
507 TemplateURL* url = FindTemplateURLForExtension(extension_id, type); 504 TemplateURL* url = FindTemplateURLForExtension(extension_id, type);
508 if (!url) 505 if (!url)
509 return; 506 return;
510 // NULL this out so that we can call RemoveNoNotify. 507 // NULL this out so that we can call RemoveNoNotify.
511 // UpdateExtensionDefaultSearchEngine will cause it to be reset.
512 if (default_search_provider_ == url) 508 if (default_search_provider_ == url)
513 default_search_provider_ = nullptr; 509 default_search_provider_ = nullptr;
514 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); 510 KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
515 RemoveNoNotify(url); 511 RemoveNoNotify(url);
516 UpdateExtensionDefaultSearchEngine();
517 NotifyObservers(); 512 NotifyObservers();
518 } 513 }
519 514
520 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) { 515 void TemplateURLService::RemoveAutoGeneratedSince(base::Time created_after) {
521 RemoveAutoGeneratedBetween(created_after, base::Time()); 516 RemoveAutoGeneratedBetween(created_after, base::Time());
522 } 517 }
523 518
524 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after, 519 void TemplateURLService::RemoveAutoGeneratedBetween(base::Time created_after,
525 base::Time created_before) { 520 base::Time created_before) {
526 RemoveAutoGeneratedForUrlsBetween(base::Callback<bool(const GURL&)>(), 521 RemoveAutoGeneratedForUrlsBetween(base::Callback<bool(const GURL&)>(),
(...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 const TemplateURLData& data, 2446 const TemplateURLData& data,
2452 TemplateURL::Type type) { 2447 TemplateURL::Type type) {
2453 DCHECK_NE(TemplateURL::NORMAL, type); 2448 DCHECK_NE(TemplateURL::NORMAL, type);
2454 for (const auto& turl : template_urls_) { 2449 for (const auto& turl : template_urls_) {
2455 if (turl->type() == type && 2450 if (turl->type() == type &&
2456 TemplateURL::MatchesData(turl.get(), &data, search_terms_data())) 2451 TemplateURL::MatchesData(turl.get(), &data, search_terms_data()))
2457 return turl.get(); 2452 return turl.get();
2458 } 2453 }
2459 return nullptr; 2454 return nullptr;
2460 } 2455 }
2461
2462 void TemplateURLService::UpdateExtensionDefaultSearchEngine() {
2463 TemplateURL* most_recently_intalled_default = nullptr;
2464 for (const auto& turl : template_urls_) {
2465 if ((turl->type() == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) &&
2466 turl->extension_info_->wants_to_be_default_engine &&
2467 turl->SupportsReplacement(search_terms_data()) &&
2468 (!most_recently_intalled_default ||
2469 (most_recently_intalled_default->extension_info_->install_time <
2470 turl->extension_info_->install_time)))
2471 most_recently_intalled_default = turl.get();
2472 }
2473
2474 if (most_recently_intalled_default) {
2475 base::AutoReset<DefaultSearchChangeOrigin> change_origin(
2476 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION);
2477 default_search_manager_.SetExtensionControlledDefaultSearchEngine(
2478 most_recently_intalled_default->data());
2479 } else {
2480 default_search_manager_.ClearExtensionControlledDefaultSearchEngine();
2481 }
2482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698