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

Unified Diff: components/search_engines/template_url_service.cc

Issue 2814743006: Refactoring after comments in https://codereview.chromium.org/2639153002 (Closed)
Patch Set: Fixed after review, round 2 Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/search_engines/template_url_service.cc
diff --git a/components/search_engines/template_url_service.cc b/components/search_engines/template_url_service.cc
index ca6401082f4f5c12ba4f65d6e200f92f2f448f07..54a5ce7ec2959d4a385ff296d528910a6fb4163f 100644
--- a/components/search_engines/template_url_service.cc
+++ b/components/search_engines/template_url_service.cc
@@ -431,6 +431,13 @@ TemplateURL* TemplateURLService::GetTemplateURLForHost(
TemplateURL* TemplateURLService::Add(
std::unique_ptr<TemplateURL> template_url) {
+ DCHECK(template_url);
+ DCHECK(
+ !IsCreatedByExtension(template_url.get()) ||
+ (!FindTemplateURLForExtension(template_url->extension_info_->extension_id,
+ template_url->type()) &&
+ template_url->id() == kInvalidTemplateURLID));
+
KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get());
TemplateURL* template_url_ptr = AddNoNotify(std::move(template_url), true);
if (template_url_ptr)
@@ -452,21 +459,6 @@ TemplateURL* TemplateURLService::AddWithOverrides(
return Add(std::move(template_url));
}
-TemplateURL* TemplateURLService::AddExtensionControlledTURL(
- std::unique_ptr<TemplateURL> template_url,
- std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info) {
- DCHECK(template_url);
- DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
- DCHECK(info);
- DCHECK_NE(TemplateURL::NORMAL, template_url->type());
- DCHECK(
- !FindTemplateURLForExtension(info->extension_id, template_url->type()));
-
- template_url->extension_info_.swap(info);
-
- return Add(std::move(template_url));
-}
-
void TemplateURLService::Remove(TemplateURL* template_url) {
RemoveNoNotify(template_url);
NotifyObservers();
@@ -534,12 +526,9 @@ void TemplateURLService::RegisterOmniboxKeyword(
data.SetShortName(base::UTF8ToUTF16(extension_name));
data.SetKeyword(base::UTF8ToUTF16(keyword));
data.SetURL(template_url_string);
- std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info(
- new TemplateURL::AssociatedExtensionInfo(extension_id));
- info->install_time = extension_install_time;
- AddExtensionControlledTURL(
- base::MakeUnique<TemplateURL>(data, TemplateURL::OMNIBOX_API_EXTENSION),
- std::move(info));
+ Add(base::MakeUnique<TemplateURL>(data, TemplateURL::OMNIBOX_API_EXTENSION,
+ extension_id, extension_install_time,
+ false));
}
TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() {
@@ -1979,11 +1968,8 @@ bool TemplateURLService::ApplyDefaultSearchChangeNoMetrics(
// (1) Tests that initialize the TemplateURLService in peculiar ways.
// (2) If the user deleted the pre-populated default and we subsequently
// lost their user-selected value.
- std::unique_ptr<TemplateURL> new_dse_ptr =
- base::MakeUnique<TemplateURL>(*data);
- TemplateURL* new_dse = new_dse_ptr.get();
- if (AddNoNotify(std::move(new_dse_ptr), true))
- default_search_provider_ = new_dse;
+ default_search_provider_ =
+ AddNoNotify(base::MakeUnique<TemplateURL>(*data), true);
}
} else if (source == DefaultSearchManager::FROM_USER) {
default_search_provider_ = GetTemplateURLForGUID(data->sync_guid);
@@ -1996,11 +1982,8 @@ bool TemplateURLService::ApplyDefaultSearchChangeNoMetrics(
UpdateNoNotify(default_search_provider_, TemplateURL(new_data));
} else {
new_data.id = kInvalidTemplateURLID;
- std::unique_ptr<TemplateURL> new_dse_ptr =
- base::MakeUnique<TemplateURL>(new_data);
- TemplateURL* new_dse = new_dse_ptr.get();
- if (AddNoNotify(std::move(new_dse_ptr), true))
- default_search_provider_ = new_dse;
+ default_search_provider_ =
+ AddNoNotify(base::MakeUnique<TemplateURL>(new_data), true);
}
if (default_search_provider_ && prefs_) {
prefs_->SetString(prefs::kSyncedDefaultSearchProviderGUID,
« no previous file with comments | « components/search_engines/template_url_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698