summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines/template_url_service.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/search_engines/template_url_service.cc')
-rw-r--r--chrome/browser/search_engines/template_url_service.cc73
1 files changed, 22 insertions, 51 deletions
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc
index b0c1b09..6b8967f 100644
--- a/chrome/browser/search_engines/template_url_service.cc
+++ b/chrome/browser/search_engines/template_url_service.cc
@@ -40,7 +40,6 @@
#include "components/search_engines/template_url_prepopulate_data.h"
#include "components/url_fixer/url_fixer.h"
#include "content/public/browser/notification_service.h"
-#include "extensions/common/constants.h"
#include "net/base/net_util.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_error_factory.h"
@@ -188,20 +187,6 @@ void LogDuplicatesHistogram(
} // namespace
-// TemplateURLService::ExtensionKeyword ---------------------------------------
-
-TemplateURLService::ExtensionKeyword::ExtensionKeyword(
- const std::string& id,
- const std::string& name,
- const std::string& keyword)
- : extension_id(id),
- extension_name(name),
- extension_keyword(keyword) {
-}
-
-TemplateURLService::ExtensionKeyword::~ExtensionKeyword() {}
-
-
// TemplateURLService::LessWithPrefix -----------------------------------------
class TemplateURLService::LessWithPrefix {
@@ -597,17 +582,16 @@ void TemplateURLService::AddWithOverrides(TemplateURL* template_url,
void TemplateURLService::AddExtensionControlledTURL(
TemplateURL* template_url,
- scoped_ptr<AssociatedExtensionInfo> info) {
+ scoped_ptr<TemplateURL::AssociatedExtensionInfo> info) {
DCHECK(loaded_);
DCHECK(template_url);
DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
DCHECK(info);
+ DCHECK_NE(TemplateURL::NORMAL, info->type);
DCHECK_EQ(info->wants_to_be_default_engine,
template_url->show_in_default_list());
+ DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type));
template_url->extension_info_.swap(info);
- DCHECK(!FindTemplateURLForExtension(
- template_url->GetExtensionId(),
- TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION));
WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get());
if (AddNoNotify(template_url, true)) {
@@ -623,10 +607,10 @@ void TemplateURLService::Remove(TemplateURL* template_url) {
}
void TemplateURLService::RemoveExtensionControlledTURL(
- const std::string& extension_id) {
+ const std::string& extension_id,
+ TemplateURL::Type type) {
DCHECK(loaded_);
- TemplateURL* url = FindTemplateURLForExtension(
- extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
+ TemplateURL* url = FindTemplateURLForExtension(extension_id, type);
if (!url)
return;
// NULL this out so that we can call RemoveNoNotify.
@@ -673,27 +657,26 @@ void TemplateURLService::RemoveAutoGeneratedForOriginBetween(
NotifyObservers();
}
-
void TemplateURLService::RegisterOmniboxKeyword(
- const std::string& extension_id,
- const std::string& extension_name,
- const std::string& keyword) {
+ const std::string& extension_id,
+ const std::string& extension_name,
+ const std::string& keyword,
+ const std::string& template_url_string) {
DCHECK(loaded_);
- if (!FindTemplateURLForExtension(extension_id,
- TemplateURL::OMNIBOX_API_EXTENSION)) {
- ExtensionKeyword extension_url(extension_id, extension_name, keyword);
- Add(CreateTemplateURLForExtension(extension_url));
- }
-}
+ if (FindTemplateURLForExtension(extension_id,
+ TemplateURL::OMNIBOX_API_EXTENSION))
+ return;
-void TemplateURLService::UnregisterOmniboxKeyword(
- const std::string& extension_id) {
- DCHECK(loaded_);
- TemplateURL* url = FindTemplateURLForExtension(
- extension_id, TemplateURL::OMNIBOX_API_EXTENSION);
- if (url)
- Remove(url);
+ TemplateURLData data;
+ data.short_name = base::UTF8ToUTF16(extension_name);
+ data.SetKeyword(base::UTF8ToUTF16(keyword));
+ data.SetURL(template_url_string);
+ TemplateURL* url = new TemplateURL(data);
+ scoped_ptr<TemplateURL::AssociatedExtensionInfo> info(
+ new TemplateURL::AssociatedExtensionInfo(
+ TemplateURL::OMNIBOX_API_EXTENSION, extension_id));
+ AddExtensionControlledTURL(url, info.Pass());
}
TemplateURLService::TemplateURLVector TemplateURLService::GetTemplateURLs() {
@@ -2420,18 +2403,6 @@ TemplateURL* TemplateURLService::FindPrepopulatedTemplateURL(
return NULL;
}
-TemplateURL* TemplateURLService::CreateTemplateURLForExtension(
- const ExtensionKeyword& extension_keyword) {
- TemplateURLData data;
- data.short_name = base::UTF8ToUTF16(extension_keyword.extension_name);
- data.SetKeyword(base::UTF8ToUTF16(extension_keyword.extension_keyword));
- // This URL is not actually used for navigation. It holds the extension's
- // ID, as well as forcing the TemplateURL to be treated as a search keyword.
- data.SetURL(std::string(extensions::kExtensionScheme) + "://" +
- extension_keyword.extension_id + "/?q={searchTerms}");
- return new TemplateURL(data);
-}
-
TemplateURL* TemplateURLService::FindTemplateURLForExtension(
const std::string& extension_id,
TemplateURL::Type type) {