summaryrefslogtreecommitdiff
path: root/chromium/components/search_engines
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-05 14:08:31 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-04-11 07:46:53 +0000
commit6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (patch)
treeab00f70a5e89278d6a0d16ff0c42578dc4d84a2d /chromium/components/search_engines
parente733310db58160074f574c429d48f8308c0afe17 (diff)
downloadqtwebengine-chromium-6a4cabb866f66d4128a97cdc6d9d08ce074f1247.tar.gz
BASELINE: Update Chromium to 57.0.2987.144
Change-Id: I29db402ff696c71a04c4dbaec822c2e53efe0267 Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/components/search_engines')
-rw-r--r--chromium/components/search_engines/BUILD.gn13
-rw-r--r--chromium/components/search_engines/OWNERS2
-rw-r--r--chromium/components/search_engines/default_search_manager.cc154
-rw-r--r--chromium/components/search_engines/default_search_manager.h2
-rw-r--r--chromium/components/search_engines/default_search_manager_unittest.cc54
-rw-r--r--chromium/components/search_engines/default_search_policy_handler.cc163
-rw-r--r--chromium/components/search_engines/default_search_policy_handler.h22
-rw-r--r--chromium/components/search_engines/default_search_policy_handler_unittest.cc72
-rw-r--r--chromium/components/search_engines/default_search_pref_migration.cc170
-rw-r--r--chromium/components/search_engines/default_search_pref_migration.h17
-rw-r--r--chromium/components/search_engines/default_search_pref_migration_unittest.cc234
-rw-r--r--chromium/components/search_engines/default_search_pref_test_util.cc56
-rw-r--r--chromium/components/search_engines/default_search_pref_test_util.h60
-rw-r--r--chromium/components/search_engines/keyword_table.cc265
-rw-r--r--chromium/components/search_engines/keyword_table.h7
-rw-r--r--chromium/components/search_engines/keyword_table_unittest.cc8
-rw-r--r--chromium/components/search_engines/prepopulated_engines.json4
-rw-r--r--chromium/components/search_engines/search_engine_data_type_controller.cc10
-rw-r--r--chromium/components/search_engines/search_engine_data_type_controller.h9
-rw-r--r--chromium/components/search_engines/search_engine_data_type_controller_unittest.cc3
-rw-r--r--chromium/components/search_engines/search_engines_pref_names.cc76
-rw-r--r--chromium/components/search_engines/search_engines_pref_names.h17
-rw-r--r--chromium/components/search_engines/search_terms_data.cc3
-rw-r--r--chromium/components/search_engines/search_terms_data.h5
-rw-r--r--chromium/components/search_engines/template_url.cc65
-rw-r--r--chromium/components/search_engines/template_url.h53
-rw-r--r--chromium/components/search_engines/template_url_data.cc56
-rw-r--r--chromium/components/search_engines/template_url_data.h39
-rw-r--r--chromium/components/search_engines/template_url_data_util.cc244
-rw-r--r--chromium/components/search_engines/template_url_data_util.h39
-rw-r--r--chromium/components/search_engines/template_url_fetcher.cc2
-rw-r--r--chromium/components/search_engines/template_url_parser.cc12
-rw-r--r--chromium/components/search_engines/template_url_parser.h1
-rw-r--r--chromium/components/search_engines/template_url_prepopulate_data.cc129
-rw-r--r--chromium/components/search_engines/template_url_prepopulate_data.h8
-rw-r--r--chromium/components/search_engines/template_url_prepopulate_data_unittest.cc18
-rw-r--r--chromium/components/search_engines/template_url_service.cc103
-rw-r--r--chromium/components/search_engines/template_url_service.h26
-rw-r--r--chromium/components/search_engines/template_url_unittest.cc22
39 files changed, 777 insertions, 1466 deletions
diff --git a/chromium/components/search_engines/BUILD.gn b/chromium/components/search_engines/BUILD.gn
index 1d14a800820..2ca2e4ae1c7 100644
--- a/chromium/components/search_engines/BUILD.gn
+++ b/chromium/components/search_engines/BUILD.gn
@@ -9,8 +9,6 @@ static_library("search_engines") {
sources = [
"default_search_manager.cc",
"default_search_manager.h",
- "default_search_pref_migration.cc",
- "default_search_pref_migration.h",
"keyword_table.cc",
"keyword_table.h",
"keyword_web_data_service.cc",
@@ -30,6 +28,8 @@ static_library("search_engines") {
"template_url.h",
"template_url_data.cc",
"template_url_data.h",
+ "template_url_data_util.cc",
+ "template_url_data_util.h",
"template_url_fetcher.cc",
"template_url_fetcher.h",
"template_url_id.h",
@@ -81,7 +81,7 @@ static_library("search_engines") {
"//url",
]
- if (enable_configuration_policy) {
+ if (!is_ios) {
sources += [
"default_search_policy_handler.cc",
"default_search_policy_handler.h",
@@ -96,8 +96,6 @@ static_library("search_engines") {
static_library("test_support") {
testonly = true
sources = [
- "default_search_pref_test_util.cc",
- "default_search_pref_test_util.h",
"testing_search_terms_data.cc",
"testing_search_terms_data.h",
]
@@ -113,7 +111,6 @@ source_set("unit_tests") {
testonly = true
sources = [
"default_search_manager_unittest.cc",
- "default_search_pref_migration_unittest.cc",
"keyword_table_unittest.cc",
"search_engine_data_type_controller_unittest.cc",
"search_host_to_urls_map_unittest.cc",
@@ -128,7 +125,7 @@ source_set("unit_tests") {
"//base",
"//base/test:test_support",
"//components/google/core/browser",
- "//components/pref_registry:test_support",
+ "//components/pref_registry:pref_registry",
"//components/prefs",
"//components/sync:test_support_driver",
"//components/sync:test_support_model",
@@ -140,7 +137,7 @@ source_set("unit_tests") {
"//url",
]
- if (enable_configuration_policy) {
+ if (!is_ios) {
sources += [ "default_search_policy_handler_unittest.cc" ]
deps += [
diff --git a/chromium/components/search_engines/OWNERS b/chromium/components/search_engines/OWNERS
index c19e61b74ea..9608b235c80 100644
--- a/chromium/components/search_engines/OWNERS
+++ b/chromium/components/search_engines/OWNERS
@@ -1,2 +1,2 @@
pkasting@chromium.org
-stevet@chromium.org
+vasilii@chromium.org
diff --git a/chromium/components/search_engines/default_search_manager.cc b/chromium/components/search_engines/default_search_manager.cc
index 42b29d29ee7..869ce645584 100644
--- a/chromium/components/search_engines/default_search_manager.cc
+++ b/chromium/components/search_engines/default_search_manager.cc
@@ -25,6 +25,7 @@
#include "components/prefs/pref_value_map.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/template_url_data.h"
+#include "components/search_engines/template_url_data_util.h"
#include "components/search_engines/template_url_prepopulate_data.h"
namespace {
@@ -50,6 +51,8 @@ const char DefaultSearchManager::kSuggestionsURL[] = "suggestions_url";
const char DefaultSearchManager::kInstantURL[] = "instant_url";
const char DefaultSearchManager::kImageURL[] = "image_url";
const char DefaultSearchManager::kNewTabURL[] = "new_tab_url";
+const char DefaultSearchManager::kContextualSearchURL[] =
+ "contextual_search_url";
const char DefaultSearchManager::kFaviconURL[] = "favicon_url";
const char DefaultSearchManager::kOriginatingURL[] = "originating_url";
@@ -67,6 +70,7 @@ const char DefaultSearchManager::kInputEncodings[] = "input_encodings";
const char DefaultSearchManager::kDateCreated[] = "date_created";
const char DefaultSearchManager::kLastModified[] = "last_modified";
+const char DefaultSearchManager::kLastVisited[] = "last_visited";
const char DefaultSearchManager::kUsageCount[] = "usage_count";
const char DefaultSearchManager::kAlternateURLs[] = "alternate_urls";
@@ -159,57 +163,8 @@ void DefaultSearchManager::SetUserSelectedDefaultSearchEngine(
return;
}
- base::DictionaryValue url_dict;
- url_dict.SetString(kID, base::Int64ToString(data.id));
- url_dict.SetString(kShortName, data.short_name());
- url_dict.SetString(kKeyword, data.keyword());
- url_dict.SetInteger(kPrepopulateID, data.prepopulate_id);
- url_dict.SetString(kSyncGUID, data.sync_guid);
-
- url_dict.SetString(kURL, data.url());
- url_dict.SetString(kSuggestionsURL, data.suggestions_url);
- url_dict.SetString(kInstantURL, data.instant_url);
- url_dict.SetString(kImageURL, data.image_url);
- url_dict.SetString(kNewTabURL, data.new_tab_url);
- url_dict.SetString(kFaviconURL, data.favicon_url.spec());
- url_dict.SetString(kOriginatingURL, data.originating_url.spec());
-
- url_dict.SetString(kSearchURLPostParams, data.search_url_post_params);
- url_dict.SetString(kSuggestionsURLPostParams,
- data.suggestions_url_post_params);
- url_dict.SetString(kInstantURLPostParams, data.instant_url_post_params);
- url_dict.SetString(kImageURLPostParams, data.image_url_post_params);
-
- url_dict.SetBoolean(kSafeForAutoReplace, data.safe_for_autoreplace);
-
- url_dict.SetString(kDateCreated,
- base::Int64ToString(data.date_created.ToInternalValue()));
- url_dict.SetString(kLastModified,
- base::Int64ToString(data.last_modified.ToInternalValue()));
- url_dict.SetInteger(kUsageCount, data.usage_count);
-
- std::unique_ptr<base::ListValue> alternate_urls(new base::ListValue);
- for (std::vector<std::string>::const_iterator it =
- data.alternate_urls.begin();
- it != data.alternate_urls.end(); ++it) {
- alternate_urls->AppendString(*it);
- }
- url_dict.Set(kAlternateURLs, alternate_urls.release());
-
- std::unique_ptr<base::ListValue> encodings(new base::ListValue);
- for (std::vector<std::string>::const_iterator it =
- data.input_encodings.begin();
- it != data.input_encodings.end(); ++it) {
- encodings->AppendString(*it);
- }
- url_dict.Set(kInputEncodings, encodings.release());
-
- url_dict.SetString(kSearchTermsReplacementKey,
- data.search_terms_replacement_key);
-
- url_dict.SetBoolean(kCreatedByPolicy, data.created_by_policy);
-
- pref_service_->Set(kDefaultSearchProviderDataPrefName, url_dict);
+ pref_service_->Set(kDefaultSearchProviderDataPrefName,
+ *TemplateURLDataToDictionary(data));
}
void DefaultSearchManager::SetExtensionControlledDefaultSearchEngine(
@@ -261,10 +216,9 @@ void DefaultSearchManager::MergePrefsDataWithPrepopulated() {
if (!prefs_default_search_ || !prefs_default_search_->prepopulate_id)
return;
- size_t default_search_index;
std::vector<std::unique_ptr<TemplateURLData>> prepopulated_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(pref_service_,
- &default_search_index);
+ nullptr);
for (auto& engine : prepopulated_urls) {
if (engine->prepopulate_id != prefs_default_search_->prepopulate_id)
@@ -279,6 +233,7 @@ void DefaultSearchManager::MergePrefsDataWithPrepopulated() {
engine->sync_guid = prefs_default_search_->sync_guid;
engine->date_created = prefs_default_search_->date_created;
engine->last_modified = prefs_default_search_->last_modified;
+ engine->last_visited = prefs_default_search_->last_visited;
prefs_default_search_ = std::move(engine);
return;
@@ -307,98 +262,11 @@ void DefaultSearchManager::LoadDefaultSearchEngineFromPrefs() {
return;
}
- std::string search_url;
- base::string16 keyword;
- url_dict->GetString(kURL, &search_url);
- url_dict->GetString(kKeyword, &keyword);
- if (search_url.empty() || keyword.empty())
+ auto turl_data = TemplateURLDataFromDictionary(*url_dict);
+ if (!turl_data)
return;
- prefs_default_search_.reset(new TemplateURLData);
- prefs_default_search_->SetKeyword(keyword);
- prefs_default_search_->SetURL(search_url);
-
- std::string id;
- url_dict->GetString(kID, &id);
- base::StringToInt64(id, &prefs_default_search_->id);
- base::string16 short_name;
- url_dict->GetString(kShortName, &short_name);
- prefs_default_search_->SetShortName(short_name);
- url_dict->GetInteger(kPrepopulateID, &prefs_default_search_->prepopulate_id);
- url_dict->GetString(kSyncGUID, &prefs_default_search_->sync_guid);
-
- url_dict->GetString(kSuggestionsURL, &prefs_default_search_->suggestions_url);
- url_dict->GetString(kInstantURL, &prefs_default_search_->instant_url);
- url_dict->GetString(kImageURL, &prefs_default_search_->image_url);
- url_dict->GetString(kNewTabURL, &prefs_default_search_->new_tab_url);
-
- std::string favicon_url;
- std::string originating_url;
- url_dict->GetString(kFaviconURL, &favicon_url);
- url_dict->GetString(kOriginatingURL, &originating_url);
- prefs_default_search_->favicon_url = GURL(favicon_url);
- prefs_default_search_->originating_url = GURL(originating_url);
-
- url_dict->GetString(kSearchURLPostParams,
- &prefs_default_search_->search_url_post_params);
- url_dict->GetString(kSuggestionsURLPostParams,
- &prefs_default_search_->suggestions_url_post_params);
- url_dict->GetString(kInstantURLPostParams,
- &prefs_default_search_->instant_url_post_params);
- url_dict->GetString(kImageURLPostParams,
- &prefs_default_search_->image_url_post_params);
-
- url_dict->GetBoolean(kSafeForAutoReplace,
- &prefs_default_search_->safe_for_autoreplace);
-
- std::string date_created_str;
- std::string last_modified_str;
- url_dict->GetString(kDateCreated, &date_created_str);
- url_dict->GetString(kLastModified, &last_modified_str);
-
- int64_t date_created = 0;
- if (base::StringToInt64(date_created_str, &date_created)) {
- prefs_default_search_->date_created =
- base::Time::FromInternalValue(date_created);
- }
-
- int64_t last_modified = 0;
- if (base::StringToInt64(date_created_str, &last_modified)) {
- prefs_default_search_->last_modified =
- base::Time::FromInternalValue(last_modified);
- }
-
- url_dict->GetInteger(kUsageCount, &prefs_default_search_->usage_count);
-
- const base::ListValue* alternate_urls = NULL;
- if (url_dict->GetList(kAlternateURLs, &alternate_urls)) {
- for (base::ListValue::const_iterator it = alternate_urls->begin();
- it != alternate_urls->end();
- ++it) {
- std::string alternate_url;
- if ((*it)->GetAsString(&alternate_url))
- prefs_default_search_->alternate_urls.push_back(alternate_url);
- }
- }
-
- const base::ListValue* encodings = NULL;
- if (url_dict->GetList(kInputEncodings, &encodings)) {
- for (base::ListValue::const_iterator it = encodings->begin();
- it != encodings->end();
- ++it) {
- std::string encoding;
- if ((*it)->GetAsString(&encoding))
- prefs_default_search_->input_encodings.push_back(encoding);
- }
- }
-
- url_dict->GetString(kSearchTermsReplacementKey,
- &prefs_default_search_->search_terms_replacement_key);
-
- url_dict->GetBoolean(kCreatedByPolicy,
- &prefs_default_search_->created_by_policy);
-
- prefs_default_search_->show_in_default_list = true;
+ prefs_default_search_ = std::move(turl_data);
MergePrefsDataWithPrepopulated();
}
diff --git a/chromium/components/search_engines/default_search_manager.h b/chromium/components/search_engines/default_search_manager.h
index 3cf6960340e..aadc6a46489 100644
--- a/chromium/components/search_engines/default_search_manager.h
+++ b/chromium/components/search_engines/default_search_manager.h
@@ -40,6 +40,7 @@ class DefaultSearchManager {
static const char kInstantURL[];
static const char kImageURL[];
static const char kNewTabURL[];
+ static const char kContextualSearchURL[];
static const char kFaviconURL[];
static const char kOriginatingURL[];
@@ -53,6 +54,7 @@ class DefaultSearchManager {
static const char kDateCreated[];
static const char kLastModified[];
+ static const char kLastVisited[];
static const char kUsageCount[];
static const char kAlternateURLs[];
diff --git a/chromium/components/search_engines/default_search_manager_unittest.cc b/chromium/components/search_engines/default_search_manager_unittest.cc
index a8df14e94ba..a8611d775e2 100644
--- a/chromium/components/search_engines/default_search_manager_unittest.cc
+++ b/chromium/components/search_engines/default_search_manager_unittest.cc
@@ -15,10 +15,11 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/pref_registry/pref_registry_syncable.h"
-#include "components/pref_registry/testing_pref_service_syncable.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/template_url_data.h"
+#include "components/search_engines/template_url_data_util.h"
#include "components/search_engines/template_url_prepopulate_data.h"
+#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -28,8 +29,8 @@ namespace {
const char kDefaultSearchProviderData[] =
"default_search_provider_data.template_url_data";
-// Checks that the two TemplateURLs are similar. Does not check the id, the
-// date_created or the last_modified time. Neither pointer should be NULL.
+// Checks that the two TemplateURLs are similar. Does not check the id or
+// any time-related fields. Neither pointer should be null.
void ExpectSimilar(const TemplateURLData* expected,
const TemplateURLData* actual) {
ASSERT_TRUE(expected != NULL);
@@ -41,7 +42,6 @@ void ExpectSimilar(const TemplateURLData* expected,
EXPECT_EQ(expected->suggestions_url, actual->suggestions_url);
EXPECT_EQ(expected->favicon_url, actual->favicon_url);
EXPECT_EQ(expected->alternate_urls, actual->alternate_urls);
- EXPECT_EQ(expected->show_in_default_list, actual->show_in_default_list);
EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace);
EXPECT_EQ(expected->input_encodings, actual->input_encodings);
EXPECT_EQ(expected->search_terms_replacement_key,
@@ -49,7 +49,8 @@ void ExpectSimilar(const TemplateURLData* expected,
}
// TODO(caitkp): TemplateURLData-ify this.
-void SetOverrides(user_prefs::TestingPrefServiceSyncable* prefs, bool update) {
+void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs,
+ bool update) {
prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
new base::FundamentalValue(1));
base::ListValue* overrides = new base::ListValue;
@@ -83,42 +84,15 @@ void SetOverrides(user_prefs::TestingPrefServiceSyncable* prefs, bool update) {
prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
}
-void SetPolicy(user_prefs::TestingPrefServiceSyncable* prefs,
+void SetPolicy(sync_preferences::TestingPrefServiceSyncable* prefs,
bool enabled,
TemplateURLData* data) {
if (enabled) {
EXPECT_FALSE(data->keyword().empty());
EXPECT_FALSE(data->url().empty());
}
- std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
- entry->SetString(DefaultSearchManager::kShortName, data->short_name());
- entry->SetString(DefaultSearchManager::kKeyword, data->keyword());
- entry->SetString(DefaultSearchManager::kURL, data->url());
- entry->SetString(DefaultSearchManager::kFaviconURL, data->favicon_url.spec());
- entry->SetString(DefaultSearchManager::kSuggestionsURL,
- data->suggestions_url);
- entry->SetBoolean(DefaultSearchManager::kSafeForAutoReplace,
- data->safe_for_autoreplace);
- std::unique_ptr<base::ListValue> alternate_urls(new base::ListValue);
- for (std::vector<std::string>::const_iterator it =
- data->alternate_urls.begin();
- it != data->alternate_urls.end();
- ++it) {
- alternate_urls->AppendString(*it);
- }
- entry->Set(DefaultSearchManager::kAlternateURLs, alternate_urls.release());
-
- std::unique_ptr<base::ListValue> encodings(new base::ListValue);
- for (std::vector<std::string>::const_iterator it =
- data->input_encodings.begin();
- it != data->input_encodings.end();
- ++it) {
- encodings->AppendString(*it);
- }
- entry->Set(DefaultSearchManager::kInputEncodings, encodings.release());
-
- entry->SetString(DefaultSearchManager::kSearchTermsReplacementKey,
- data->search_terms_replacement_key);
+ std::unique_ptr<base::DictionaryValue> entry(
+ TemplateURLDataToDictionary(*data));
entry->SetBoolean(DefaultSearchManager::kDisabledByPolicy, !enabled);
prefs->SetManagedPref(kDefaultSearchProviderData, entry.release());
}
@@ -134,11 +108,11 @@ std::unique_ptr<TemplateURLData> GenerateDummyTemplateURLData(
std::string("http://").append(type).append("foo/alt"));
data->favicon_url = GURL("http://icon1");
data->safe_for_autoreplace = true;
- data->show_in_default_list = true;
data->input_encodings = base::SplitString(
"UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
data->date_created = base::Time();
data->last_modified = base::Time();
+ data->last_visited = base::Time();
return data;
}
@@ -149,17 +123,17 @@ class DefaultSearchManagerTest : public testing::Test {
DefaultSearchManagerTest() {};
void SetUp() override {
- pref_service_.reset(new user_prefs::TestingPrefServiceSyncable);
+ pref_service_.reset(new sync_preferences::TestingPrefServiceSyncable);
DefaultSearchManager::RegisterProfilePrefs(pref_service_->registry());
TemplateURLPrepopulateData::RegisterProfilePrefs(pref_service_->registry());
}
- user_prefs::TestingPrefServiceSyncable* pref_service() {
+ sync_preferences::TestingPrefServiceSyncable* pref_service() {
return pref_service_.get();
}
private:
- std::unique_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_;
+ std::unique_ptr<sync_preferences::TestingPrefServiceSyncable> pref_service_;
DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest);
};
@@ -176,11 +150,11 @@ TEST_F(DefaultSearchManagerTest, ReadAndWritePref) {
data.alternate_urls.push_back("http://foo1/alt");
data.favicon_url = GURL("http://icon1");
data.safe_for_autoreplace = true;
- data.show_in_default_list = true;
data.input_encodings = base::SplitString(
"UTF-8;UTF-16", ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
data.date_created = base::Time();
data.last_modified = base::Time();
+ data.last_modified = base::Time();
manager.SetUserSelectedDefaultSearchEngine(data);
TemplateURLData* read_data = manager.GetDefaultSearchEngine(NULL);
diff --git a/chromium/components/search_engines/default_search_policy_handler.cc b/chromium/components/search_engines/default_search_policy_handler.cc
index 7c742da5903..35f85cc0bbd 100644
--- a/chromium/components/search_engines/default_search_policy_handler.cc
+++ b/chromium/components/search_engines/default_search_policy_handler.cc
@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
@@ -59,141 +58,46 @@ void SetStringInPref(const PolicyMap& policies,
// List of policy types to preference names, for policies affecting the default
// search provider.
-const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[] = {
- { key::kDefaultSearchProviderEnabled,
- prefs::kDefaultSearchProviderEnabled,
- base::Value::TYPE_BOOLEAN },
- { key::kDefaultSearchProviderName,
- prefs::kDefaultSearchProviderName,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderKeyword,
- prefs::kDefaultSearchProviderKeyword,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderSearchURL,
- prefs::kDefaultSearchProviderSearchURL,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderSuggestURL,
- prefs::kDefaultSearchProviderSuggestURL,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderInstantURL,
- prefs::kDefaultSearchProviderInstantURL,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderIconURL,
- prefs::kDefaultSearchProviderIconURL,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderEncodings,
- prefs::kDefaultSearchProviderEncodings,
- base::Value::TYPE_LIST },
- { key::kDefaultSearchProviderAlternateURLs,
- prefs::kDefaultSearchProviderAlternateURLs,
- base::Value::TYPE_LIST },
- { key::kDefaultSearchProviderSearchTermsReplacementKey,
- prefs::kDefaultSearchProviderSearchTermsReplacementKey,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderImageURL,
- prefs::kDefaultSearchProviderImageURL,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderNewTabURL,
- prefs::kDefaultSearchProviderNewTabURL,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderSearchURLPostParams,
- prefs::kDefaultSearchProviderSearchURLPostParams,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderSuggestURLPostParams,
- prefs::kDefaultSearchProviderSuggestURLPostParams,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderInstantURLPostParams,
- prefs::kDefaultSearchProviderInstantURLPostParams,
- base::Value::TYPE_STRING },
- { key::kDefaultSearchProviderImageURLPostParams,
- prefs::kDefaultSearchProviderImageURLPostParams,
- base::Value::TYPE_STRING },
-};
-
-// List of policy types to preference names, for policies affecting the default
-// search provider.
const PolicyToPreferenceMapEntry kDefaultSearchPolicyDataMap[] = {
+ {key::kDefaultSearchProviderEnabled, prefs::kDefaultSearchProviderEnabled,
+ base::Value::Type::BOOLEAN},
{key::kDefaultSearchProviderName, DefaultSearchManager::kShortName,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderKeyword, DefaultSearchManager::kKeyword,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderSearchURL, DefaultSearchManager::kURL,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderSuggestURL,
- DefaultSearchManager::kSuggestionsURL, base::Value::TYPE_STRING},
+ DefaultSearchManager::kSuggestionsURL, base::Value::Type::STRING},
{key::kDefaultSearchProviderInstantURL, DefaultSearchManager::kInstantURL,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderIconURL, DefaultSearchManager::kFaviconURL,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderEncodings,
- DefaultSearchManager::kInputEncodings, base::Value::TYPE_LIST},
+ DefaultSearchManager::kInputEncodings, base::Value::Type::LIST},
{key::kDefaultSearchProviderAlternateURLs,
- DefaultSearchManager::kAlternateURLs, base::Value::TYPE_LIST},
+ DefaultSearchManager::kAlternateURLs, base::Value::Type::LIST},
{key::kDefaultSearchProviderSearchTermsReplacementKey,
DefaultSearchManager::kSearchTermsReplacementKey,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderImageURL, DefaultSearchManager::kImageURL,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderNewTabURL, DefaultSearchManager::kNewTabURL,
- base::Value::TYPE_STRING},
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderSearchURLPostParams,
- DefaultSearchManager::kSearchURLPostParams, base::Value::TYPE_STRING},
+ DefaultSearchManager::kSearchURLPostParams, base::Value::Type::STRING},
{key::kDefaultSearchProviderSuggestURLPostParams,
- DefaultSearchManager::kSuggestionsURLPostParams, base::Value::TYPE_STRING},
+ DefaultSearchManager::kSuggestionsURLPostParams,
+ base::Value::Type::STRING},
{key::kDefaultSearchProviderInstantURLPostParams,
- DefaultSearchManager::kInstantURLPostParams, base::Value::TYPE_STRING},
+ DefaultSearchManager::kInstantURLPostParams, base::Value::Type::STRING},
{key::kDefaultSearchProviderImageURLPostParams,
- DefaultSearchManager::kImageURLPostParams, base::Value::TYPE_STRING},
+ DefaultSearchManager::kImageURLPostParams, base::Value::Type::STRING},
};
-// DefaultSearchEncodingsPolicyHandler implementation --------------------------
-
-DefaultSearchEncodingsPolicyHandler::DefaultSearchEncodingsPolicyHandler()
- : TypeCheckingPolicyHandler(key::kDefaultSearchProviderEncodings,
- base::Value::TYPE_LIST) {}
-
-DefaultSearchEncodingsPolicyHandler::~DefaultSearchEncodingsPolicyHandler() {
-}
-
-void DefaultSearchEncodingsPolicyHandler::ApplyPolicySettings(
- const PolicyMap& policies, PrefValueMap* prefs) {
- // The DefaultSearchProviderEncodings policy has type list, but the related
- // preference has type string. Convert one into the other here, using
- // ';' as a separator.
- const base::Value* value = policies.GetValue(policy_name());
- const base::ListValue* list;
- if (!value || !value->GetAsList(&list))
- return;
-
- base::ListValue::const_iterator iter(list->begin());
- base::ListValue::const_iterator end(list->end());
- std::vector<std::string> string_parts;
- for (; iter != end; ++iter) {
- std::string s;
- if ((*iter)->GetAsString(&s)) {
- string_parts.push_back(s);
- }
- }
- std::string encodings = base::JoinString(string_parts, ";");
- prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings);
-}
-
-
// DefaultSearchPolicyHandler implementation -----------------------------------
-DefaultSearchPolicyHandler::DefaultSearchPolicyHandler() {
- for (size_t i = 0; i < arraysize(kDefaultSearchPolicyMap); ++i) {
- const char* policy_name = kDefaultSearchPolicyMap[i].policy_name;
- if (policy_name == key::kDefaultSearchProviderEncodings) {
- handlers_.push_back(
- base::MakeUnique<DefaultSearchEncodingsPolicyHandler>());
- } else {
- handlers_.push_back(base::MakeUnique<SimplePolicyHandler>(
- policy_name, kDefaultSearchPolicyMap[i].preference_path,
- kDefaultSearchPolicyMap[i].value_type));
- }
- }
-}
+DefaultSearchPolicyHandler::DefaultSearchPolicyHandler() {}
DefaultSearchPolicyHandler::~DefaultSearchPolicyHandler() {}
@@ -206,8 +110,8 @@ bool DefaultSearchPolicyHandler::CheckPolicySettings(const PolicyMap& policies,
// Add an error for all specified default search policies except
// DefaultSearchProviderEnabled.
- for (const auto& handler : handlers_) {
- const char* policy_name = handler->policy_name();
+ for (const auto& policy_map_entry : kDefaultSearchPolicyDataMap) {
+ const char* policy_name = policy_map_entry.policy_name;
if (policy_name != key::kDefaultSearchProviderEnabled &&
HasDefaultSearchPolicy(policies, policy_name)) {
errors->AddError(policy_name, IDS_POLICY_DEFAULT_SEARCH_DISABLED);
@@ -246,14 +150,18 @@ void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap& policies,
std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
for (size_t i = 0; i < arraysize(kDefaultSearchPolicyDataMap); ++i) {
const char* policy_name = kDefaultSearchPolicyDataMap[i].policy_name;
+ // kDefaultSearchProviderEnabled has already been handled.
+ if (policy_name == key::kDefaultSearchProviderEnabled)
+ continue;
+
switch (kDefaultSearchPolicyDataMap[i].value_type) {
- case base::Value::TYPE_STRING:
+ case base::Value::Type::STRING:
SetStringInPref(policies,
policy_name,
kDefaultSearchPolicyDataMap[i].preference_path,
dict.get());
break;
- case base::Value::TYPE_LIST:
+ case base::Value::Type::LIST:
SetListInPref(policies,
policy_name,
kDefaultSearchPolicyDataMap[i].preference_path,
@@ -302,10 +210,15 @@ bool DefaultSearchPolicyHandler::CheckIndividualPolicies(
const PolicyMap& policies,
PolicyErrorMap* errors) {
bool all_ok = true;
- for (const auto& handler : handlers_) {
- // It's important to call CheckPolicySettings() on all handlers and not just
- // exit on the first error, so we report all policy errors.
- all_ok &= handler->CheckPolicySettings(policies, errors);
+ for (const auto& policy_map_entry : kDefaultSearchPolicyDataMap) {
+ // It's important to check policy type for all policies and not just exit on
+ // the first error, so we report all policy errors.
+ const base::Value* value = policies.GetValue(policy_map_entry.policy_name);
+ if (value && !value->IsType(policy_map_entry.value_type)) {
+ errors->AddError(policy_map_entry.policy_name, IDS_POLICY_TYPE_ERROR,
+ base::Value::GetTypeName(policy_map_entry.value_type));
+ all_ok = false;
+ }
}
return all_ok;
}
@@ -318,8 +231,8 @@ bool DefaultSearchPolicyHandler::HasDefaultSearchPolicy(
bool DefaultSearchPolicyHandler::AnyDefaultSearchPoliciesSpecified(
const PolicyMap& policies) {
- for (const auto& handler : handlers_) {
- if (policies.Get(handler->policy_name()))
+ for (const auto& policy_map_entry : kDefaultSearchPolicyDataMap) {
+ if (policies.Get(policy_map_entry.policy_name))
return true;
}
return false;
diff --git a/chromium/components/search_engines/default_search_policy_handler.h b/chromium/components/search_engines/default_search_policy_handler.h
index 499d5a4f0bc..9eea0cd26a0 100644
--- a/chromium/components/search_engines/default_search_policy_handler.h
+++ b/chromium/components/search_engines/default_search_policy_handler.h
@@ -13,21 +13,6 @@
namespace policy {
-// ConfigurationPolicyHandler for the DefaultSearchEncodings policy.
-class DefaultSearchEncodingsPolicyHandler
- : public TypeCheckingPolicyHandler {
- public:
- DefaultSearchEncodingsPolicyHandler();
- ~DefaultSearchEncodingsPolicyHandler() override;
-
- // ConfigurationPolicyHandler methods:
- void ApplyPolicySettings(const PolicyMap& policies,
- PrefValueMap* prefs) override;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler);
-};
-
// ConfigurationPolicyHandler for the default search policies.
class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
public:
@@ -41,8 +26,8 @@ class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
PrefValueMap* prefs) override;
private:
- // Calls |CheckPolicySettings()| on each of the handlers in |handlers_|
- // and returns whether all of the calls succeeded.
+ // Checks that value type is valid for each policy and returns whether all of
+ // the policies are valid.
bool CheckIndividualPolicies(const PolicyMap& policies,
PolicyErrorMap* errors);
@@ -70,9 +55,6 @@ class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler {
// not, set it to an empty list.
void EnsureListPrefExists(PrefValueMap* prefs, const std::string& path);
- // The ConfigurationPolicyHandler handlers for each default search policy.
- std::vector<std::unique_ptr<TypeCheckingPolicyHandler>> handlers_;
-
DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler);
};
diff --git a/chromium/components/search_engines/default_search_policy_handler_unittest.cc b/chromium/components/search_engines/default_search_policy_handler_unittest.cc
index fece4e7a298..93f7eaff2ff 100644
--- a/chromium/components/search_engines/default_search_policy_handler_unittest.cc
+++ b/chromium/components/search_engines/default_search_policy_handler_unittest.cc
@@ -14,13 +14,6 @@
#include "components/search_engines/default_search_manager.h"
#include "components/search_engines/search_engines_pref_names.h"
-namespace {
-// TODO(caitkp): Should we find a way to route this through DefaultSearchManager
-// to avoid hardcoding this here?
-const char kDefaultSearchProviderData[] =
- "default_search_provider_data.template_url_data";
-} // namespace
-
namespace policy {
class DefaultSearchPolicyHandlerTest
@@ -133,7 +126,8 @@ TEST_F(DefaultSearchPolicyHandlerTest, MissingUrl) {
UpdateProviderPolicy(policy);
const base::Value* temp = nullptr;
- EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ EXPECT_FALSE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
}
// Checks that if the default search policy is invalid, that no elements of the
@@ -148,7 +142,54 @@ TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
UpdateProviderPolicy(policy);
const base::Value* temp = nullptr;
- EXPECT_FALSE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ EXPECT_FALSE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
+}
+
+// Checks that if the default search policy has invalid type for elements,
+// that no elements of the default search policy will be present in prefs.
+TEST_F(DefaultSearchPolicyHandlerTest, InvalidType) {
+ // List of policies defined in test policy.
+ const char* kPolicyNamesToCheck[] = {
+ key::kDefaultSearchProviderEnabled,
+ key::kDefaultSearchProviderName,
+ key::kDefaultSearchProviderKeyword,
+ key::kDefaultSearchProviderSearchURL,
+ key::kDefaultSearchProviderSuggestURL,
+ key::kDefaultSearchProviderIconURL,
+ key::kDefaultSearchProviderEncodings,
+ key::kDefaultSearchProviderAlternateURLs,
+ key::kDefaultSearchProviderSearchTermsReplacementKey,
+ key::kDefaultSearchProviderImageURL,
+ key::kDefaultSearchProviderNewTabURL,
+ key::kDefaultSearchProviderImageURLPostParams};
+
+ PolicyMap policy;
+ BuildDefaultSearchPolicy(&policy);
+
+ for (auto policy_name : kPolicyNamesToCheck) {
+ // Check that policy can be successfully applied first.
+ UpdateProviderPolicy(policy);
+ const base::Value* temp = nullptr;
+ EXPECT_TRUE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
+
+ auto old_value = base::WrapUnique(policy.GetValue(policy_name)->DeepCopy());
+ // BinaryValue is not supported in any current default search policy params.
+ // Try changing policy param to BinaryValue and check that policy becomes
+ // invalid.
+ policy.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ POLICY_SOURCE_CLOUD, base::WrapUnique(new base::BinaryValue()),
+ nullptr);
+ UpdateProviderPolicy(policy);
+
+ EXPECT_FALSE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp))
+ << "Policy type check failed " << policy_name;
+ // Return old value to policy map.
+ policy.Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
+ POLICY_SOURCE_CLOUD, std::move(old_value), nullptr);
+ }
}
// Checks that for a fully defined search policy, all elements have been
@@ -162,7 +203,8 @@ TEST_F(DefaultSearchPolicyHandlerTest, FullyDefined) {
const base::DictionaryValue* dictionary;
std::string value;
const base::ListValue* list_value;
- EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ EXPECT_TRUE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
temp->GetAsDictionary(&dictionary);
EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
@@ -224,7 +266,8 @@ TEST_F(DefaultSearchPolicyHandlerTest, Disabled) {
UpdateProviderPolicy(policy);
const base::Value* temp = NULL;
const base::DictionaryValue* dictionary;
- EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ EXPECT_TRUE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
temp->GetAsDictionary(&dictionary);
bool disabled = false;
EXPECT_TRUE(dictionary->GetBoolean(DefaultSearchManager::kDisabledByPolicy,
@@ -248,7 +291,8 @@ TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
const base::DictionaryValue* dictionary;
std::string value;
const base::ListValue* list_value;
- EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ EXPECT_TRUE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
temp->GetAsDictionary(&dictionary);
// Name and keyword should be derived from host.
@@ -306,7 +350,8 @@ TEST_F(DefaultSearchPolicyHandlerTest, FileURL) {
const base::DictionaryValue* dictionary;
std::string value;
- EXPECT_TRUE(store_->GetValue(kDefaultSearchProviderData, &temp));
+ EXPECT_TRUE(store_->GetValue(
+ DefaultSearchManager::kDefaultSearchProviderDataPrefName, &temp));
temp->GetAsDictionary(&dictionary);
EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kURL, &value));
@@ -316,4 +361,5 @@ TEST_F(DefaultSearchPolicyHandlerTest, FileURL) {
EXPECT_TRUE(dictionary->GetString(DefaultSearchManager::kKeyword, &value));
EXPECT_EQ("_", value);
}
+
} // namespace policy
diff --git a/chromium/components/search_engines/default_search_pref_migration.cc b/chromium/components/search_engines/default_search_pref_migration.cc
deleted file mode 100644
index 5912275f3b7..00000000000
--- a/chromium/components/search_engines/default_search_pref_migration.cc
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/search_engines/default_search_pref_migration.h"
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <memory>
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/logging.h"
-#include "base/metrics/histogram_macros.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/prefs/pref_service.h"
-#include "components/search_engines/default_search_manager.h"
-#include "components/search_engines/search_engines_pref_names.h"
-#include "components/search_engines/template_url_data.h"
-#include "components/search_engines/template_url_service.h"
-#include "url/gurl.h"
-
-namespace {
-
-// Loads the user-selected DSE (if there is one) from legacy preferences.
-std::unique_ptr<TemplateURLData> LoadDefaultSearchProviderFromLegacyPrefs(
- PrefService* prefs) {
- if (!prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL) ||
- !prefs->HasPrefPath(prefs::kDefaultSearchProviderKeyword))
- return std::unique_ptr<TemplateURLData>();
-
- const PrefService::Preference* pref =
- prefs->FindPreference(prefs::kDefaultSearchProviderSearchURL);
- DCHECK(pref);
- if (pref->IsManaged())
- return std::unique_ptr<TemplateURLData>();
-
- base::string16 keyword =
- base::UTF8ToUTF16(prefs->GetString(prefs::kDefaultSearchProviderKeyword));
- std::string search_url =
- prefs->GetString(prefs::kDefaultSearchProviderSearchURL);
- if (keyword.empty() || search_url.empty())
- return std::unique_ptr<TemplateURLData>();
-
- std::unique_ptr<TemplateURLData> default_provider_data(new TemplateURLData);
- default_provider_data->SetShortName(
- base::UTF8ToUTF16(prefs->GetString(prefs::kDefaultSearchProviderName)));
- default_provider_data->SetKeyword(keyword);
- default_provider_data->SetURL(search_url);
- default_provider_data->suggestions_url =
- prefs->GetString(prefs::kDefaultSearchProviderSuggestURL);
- default_provider_data->instant_url =
- prefs->GetString(prefs::kDefaultSearchProviderInstantURL);
- default_provider_data->image_url =
- prefs->GetString(prefs::kDefaultSearchProviderImageURL);
- default_provider_data->new_tab_url =
- prefs->GetString(prefs::kDefaultSearchProviderNewTabURL);
- default_provider_data->search_url_post_params =
- prefs->GetString(prefs::kDefaultSearchProviderSearchURLPostParams);
- default_provider_data->suggestions_url_post_params =
- prefs->GetString(prefs::kDefaultSearchProviderSuggestURLPostParams);
- default_provider_data->instant_url_post_params =
- prefs->GetString(prefs::kDefaultSearchProviderInstantURLPostParams);
- default_provider_data->image_url_post_params =
- prefs->GetString(prefs::kDefaultSearchProviderImageURLPostParams);
- default_provider_data->favicon_url =
- GURL(prefs->GetString(prefs::kDefaultSearchProviderIconURL));
- default_provider_data->show_in_default_list = true;
- default_provider_data->search_terms_replacement_key =
- prefs->GetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey);
- default_provider_data->input_encodings = base::SplitString(
- prefs->GetString(prefs::kDefaultSearchProviderEncodings),
- ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
-
- default_provider_data->alternate_urls.clear();
- const base::ListValue* alternate_urls =
- prefs->GetList(prefs::kDefaultSearchProviderAlternateURLs);
- for (size_t i = 0; i < alternate_urls->GetSize(); ++i) {
- std::string alternate_url;
- if (alternate_urls->GetString(i, &alternate_url))
- default_provider_data->alternate_urls.push_back(alternate_url);
- }
-
- std::string id_string = prefs->GetString(prefs::kDefaultSearchProviderID);
- if (!id_string.empty()) {
- int64_t value;
- base::StringToInt64(id_string, &value);
- default_provider_data->id = value;
- }
-
- std::string prepopulate_id =
- prefs->GetString(prefs::kDefaultSearchProviderPrepopulateID);
- if (!prepopulate_id.empty()) {
- int value;
- base::StringToInt(prepopulate_id, &value);
- default_provider_data->prepopulate_id = value;
- }
-
- return default_provider_data;
-}
-
-void ClearDefaultSearchProviderFromLegacyPrefs(PrefService* prefs) {
- prefs->ClearPref(prefs::kDefaultSearchProviderName);
- prefs->ClearPref(prefs::kDefaultSearchProviderKeyword);
- prefs->ClearPref(prefs::kDefaultSearchProviderSearchURL);
- prefs->ClearPref(prefs::kDefaultSearchProviderSuggestURL);
- prefs->ClearPref(prefs::kDefaultSearchProviderInstantURL);
- prefs->ClearPref(prefs::kDefaultSearchProviderImageURL);
- prefs->ClearPref(prefs::kDefaultSearchProviderNewTabURL);
- prefs->ClearPref(prefs::kDefaultSearchProviderSearchURLPostParams);
- prefs->ClearPref(prefs::kDefaultSearchProviderSuggestURLPostParams);
- prefs->ClearPref(prefs::kDefaultSearchProviderInstantURLPostParams);
- prefs->ClearPref(prefs::kDefaultSearchProviderImageURLPostParams);
- prefs->ClearPref(prefs::kDefaultSearchProviderIconURL);
- prefs->ClearPref(prefs::kDefaultSearchProviderEncodings);
- prefs->ClearPref(prefs::kDefaultSearchProviderPrepopulateID);
- prefs->ClearPref(prefs::kDefaultSearchProviderAlternateURLs);
- prefs->ClearPref(prefs::kDefaultSearchProviderSearchTermsReplacementKey);
-}
-
-void MigrateDefaultSearchPref(PrefService* pref_service) {
- DCHECK(pref_service);
-
- std::unique_ptr<TemplateURLData> legacy_dse_from_prefs =
- LoadDefaultSearchProviderFromLegacyPrefs(pref_service);
- if (!legacy_dse_from_prefs)
- return;
-
- DefaultSearchManager default_search_manager(
- pref_service, DefaultSearchManager::ObserverCallback());
- DefaultSearchManager::Source modern_source;
- TemplateURLData* modern_value =
- default_search_manager.GetDefaultSearchEngine(&modern_source);
- if (modern_source == DefaultSearchManager::FROM_FALLBACK) {
- // |modern_value| is the prepopulated default. If it matches the legacy DSE
- // we assume it is not a user-selected value.
- if (!modern_value ||
- legacy_dse_from_prefs->prepopulate_id != modern_value->prepopulate_id) {
- // This looks like a user-selected value, so let's migrate it.
- // TODO(erikwright): Remove this migration logic when this stat approaches
- // zero.
- UMA_HISTOGRAM_BOOLEAN("Search.MigratedPrefToDictionaryValue", true);
- default_search_manager.SetUserSelectedDefaultSearchEngine(
- *legacy_dse_from_prefs);
- }
- }
-
- ClearDefaultSearchProviderFromLegacyPrefs(pref_service);
-}
-
-void OnPrefsInitialized(PrefService* pref_service,
- bool pref_service_initialization_success) {
- MigrateDefaultSearchPref(pref_service);
-}
-
-} // namespace
-
-void ConfigureDefaultSearchPrefMigrationToDictionaryValue(
- PrefService* pref_service) {
- if (pref_service->GetInitializationStatus() ==
- PrefService::INITIALIZATION_STATUS_WAITING) {
- pref_service->AddPrefInitObserver(
- base::Bind(&OnPrefsInitialized, base::Unretained(pref_service)));
- } else {
- MigrateDefaultSearchPref(pref_service);
- }
-}
diff --git a/chromium/components/search_engines/default_search_pref_migration.h b/chromium/components/search_engines/default_search_pref_migration.h
deleted file mode 100644
index b2fd0c443fc..00000000000
--- a/chromium/components/search_engines/default_search_pref_migration.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_MIGRATION_H_
-#define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_MIGRATION_H_
-
-class PrefService;
-
-// Migrates a DSE value stored in separate String/List/..Value preferences by
-// M35 or earlier to the new single DictionaryValue used in M36.
-// Operates immediately if |pref_service| is fully initialized. Otherwise, waits
-// for the PrefService to load using an observer.
-void ConfigureDefaultSearchPrefMigrationToDictionaryValue(
- PrefService* pref_service);
-
-#endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_MIGRATION_H_
diff --git a/chromium/components/search_engines/default_search_pref_migration_unittest.cc b/chromium/components/search_engines/default_search_pref_migration_unittest.cc
deleted file mode 100644
index 5de070b2910..00000000000
--- a/chromium/components/search_engines/default_search_pref_migration_unittest.cc
+++ /dev/null
@@ -1,234 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/search_engines/default_search_pref_migration.h"
-
-#include <stddef.h>
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/files/scoped_temp_dir.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/strings/string16.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "components/pref_registry/testing_pref_service_syncable.h"
-#include "components/search_engines/default_search_manager.h"
-#include "components/search_engines/search_engines_pref_names.h"
-#include "components/search_engines/template_url.h"
-#include "components/search_engines/template_url_prepopulate_data.h"
-#include "components/search_engines/template_url_service.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-class DefaultSearchPrefMigrationTest : public testing::Test {
- public:
- DefaultSearchPrefMigrationTest();
-
- void SaveDefaultSearchProviderToLegacyPrefs(const TemplateURL* t_url);
-
- std::unique_ptr<TemplateURL> CreateKeyword(const std::string& short_name,
- const std::string& keyword,
- const std::string& url);
-
- DefaultSearchManager* default_search_manager() {
- return default_search_manager_.get();
- }
-
- PrefService* pref_service() { return &prefs_; }
-
- private:
- user_prefs::TestingPrefServiceSyncable prefs_;
- std::unique_ptr<DefaultSearchManager> default_search_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(DefaultSearchPrefMigrationTest);
-};
-
-DefaultSearchPrefMigrationTest::DefaultSearchPrefMigrationTest() {
- DefaultSearchManager::RegisterProfilePrefs(prefs_.registry());
- TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry());
- TemplateURLService::RegisterProfilePrefs(prefs_.registry());
- default_search_manager_.reset(new DefaultSearchManager(
- pref_service(), DefaultSearchManager::ObserverCallback()));
-}
-
-void DefaultSearchPrefMigrationTest::SaveDefaultSearchProviderToLegacyPrefs(
- const TemplateURL* t_url) {
- PrefService* prefs = pref_service();
-
- bool enabled = false;
- std::string search_url;
- std::string suggest_url;
- std::string instant_url;
- std::string image_url;
- std::string new_tab_url;
- std::string search_url_post_params;
- std::string suggest_url_post_params;
- std::string instant_url_post_params;
- std::string image_url_post_params;
- std::string icon_url;
- std::string encodings;
- std::string short_name;
- std::string keyword;
- std::string id_string;
- std::string prepopulate_id;
- base::ListValue alternate_urls;
- std::string search_terms_replacement_key;
- if (t_url) {
- DCHECK_EQ(TemplateURL::NORMAL, t_url->type());
- enabled = true;
- search_url = t_url->url();
- suggest_url = t_url->suggestions_url();
- instant_url = t_url->instant_url();
- image_url = t_url->image_url();
- new_tab_url = t_url->new_tab_url();
- search_url_post_params = t_url->search_url_post_params();
- suggest_url_post_params = t_url->suggestions_url_post_params();
- instant_url_post_params = t_url->instant_url_post_params();
- image_url_post_params = t_url->image_url_post_params();
- GURL icon_gurl = t_url->favicon_url();
- if (!icon_gurl.is_empty())
- icon_url = icon_gurl.spec();
- encodings = base::JoinString(t_url->input_encodings(), ";");
- short_name = base::UTF16ToUTF8(t_url->short_name());
- keyword = base::UTF16ToUTF8(t_url->keyword());
- id_string = base::Int64ToString(t_url->id());
- prepopulate_id = base::Int64ToString(t_url->prepopulate_id());
- for (size_t i = 0; i < t_url->alternate_urls().size(); ++i)
- alternate_urls.AppendString(t_url->alternate_urls()[i]);
- search_terms_replacement_key = t_url->search_terms_replacement_key();
- }
- prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, enabled);
- prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url);
- prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url);
- prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url);
- prefs->SetString(prefs::kDefaultSearchProviderImageURL, image_url);
- prefs->SetString(prefs::kDefaultSearchProviderNewTabURL, new_tab_url);
- prefs->SetString(prefs::kDefaultSearchProviderSearchURLPostParams,
- search_url_post_params);
- prefs->SetString(prefs::kDefaultSearchProviderSuggestURLPostParams,
- suggest_url_post_params);
- prefs->SetString(prefs::kDefaultSearchProviderInstantURLPostParams,
- instant_url_post_params);
- prefs->SetString(prefs::kDefaultSearchProviderImageURLPostParams,
- image_url_post_params);
- prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url);
- prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings);
- prefs->SetString(prefs::kDefaultSearchProviderName, short_name);
- prefs->SetString(prefs::kDefaultSearchProviderKeyword, keyword);
- prefs->SetString(prefs::kDefaultSearchProviderID, id_string);
- prefs->SetString(prefs::kDefaultSearchProviderPrepopulateID, prepopulate_id);
- prefs->Set(prefs::kDefaultSearchProviderAlternateURLs, alternate_urls);
- prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey,
- search_terms_replacement_key);
-}
-
-std::unique_ptr<TemplateURL> DefaultSearchPrefMigrationTest::CreateKeyword(
- const std::string& short_name,
- const std::string& keyword,
- const std::string& url) {
- TemplateURLData data;
- data.SetShortName(base::ASCIIToUTF16(short_name));
- data.SetKeyword(base::ASCIIToUTF16(keyword));
- data.SetURL(url);
- std::unique_ptr<TemplateURL> t_url(new TemplateURL(data));
- return t_url;
-}
-
-TEST_F(DefaultSearchPrefMigrationTest, MigrateUserSelectedValue) {
- std::unique_ptr<TemplateURL> t_url(
- CreateKeyword("name1", "key1", "http://foo1/{searchTerms}"));
- // Store a value in the legacy location.
- SaveDefaultSearchProviderToLegacyPrefs(t_url.get());
-
- // Run the migration.
- ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service());
-
- // Test that it was migrated.
- DefaultSearchManager::Source source;
- const TemplateURLData* modern_default =
- default_search_manager()->GetDefaultSearchEngine(&source);
- ASSERT_TRUE(modern_default);
- EXPECT_EQ(DefaultSearchManager::FROM_USER, source);
- EXPECT_EQ(t_url->short_name(), modern_default->short_name());
- EXPECT_EQ(t_url->keyword(), modern_default->keyword());
- EXPECT_EQ(t_url->url(), modern_default->url());
-}
-
-TEST_F(DefaultSearchPrefMigrationTest, MigrateOnlyOnce) {
- std::unique_ptr<TemplateURL> t_url(
- CreateKeyword("name1", "key1", "http://foo1/{searchTerms}"));
- // Store a value in the legacy location.
- SaveDefaultSearchProviderToLegacyPrefs(t_url.get());
-
- // Run the migration.
- ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service());
-
- // Test that it was migrated.
- DefaultSearchManager::Source source;
- const TemplateURLData* modern_default =
- default_search_manager()->GetDefaultSearchEngine(&source);
- ASSERT_TRUE(modern_default);
- EXPECT_EQ(DefaultSearchManager::FROM_USER, source);
- EXPECT_EQ(t_url->short_name(), modern_default->short_name());
- EXPECT_EQ(t_url->keyword(), modern_default->keyword());
- EXPECT_EQ(t_url->url(), modern_default->url());
- default_search_manager()->ClearUserSelectedDefaultSearchEngine();
-
- // Run the migration.
- ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service());
-
- // Test that it was NOT migrated.
- modern_default = default_search_manager()->GetDefaultSearchEngine(&source);
- ASSERT_TRUE(modern_default);
- EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source);
-}
-
-TEST_F(DefaultSearchPrefMigrationTest, ModernValuePresent) {
- std::unique_ptr<TemplateURL> t_url(
- CreateKeyword("name1", "key1", "http://foo1/{searchTerms}"));
- std::unique_ptr<TemplateURL> t_url2(
- CreateKeyword("name2", "key2", "http://foo2/{searchTerms}"));
- // Store a value in the legacy location.
- SaveDefaultSearchProviderToLegacyPrefs(t_url.get());
-
- // Store another value in the modern location.
- default_search_manager()->SetUserSelectedDefaultSearchEngine(t_url2->data());
-
- // Run the migration.
- ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service());
-
- // Test that no migration occurred. The modern value is left intact.
- DefaultSearchManager::Source source;
- const TemplateURLData* modern_default =
- default_search_manager()->GetDefaultSearchEngine(&source);
- ASSERT_TRUE(modern_default);
- EXPECT_EQ(DefaultSearchManager::FROM_USER, source);
- EXPECT_EQ(t_url2->short_name(), modern_default->short_name());
- EXPECT_EQ(t_url2->keyword(), modern_default->keyword());
- EXPECT_EQ(t_url2->url(), modern_default->url());
-}
-
-TEST_F(DefaultSearchPrefMigrationTest,
- AutomaticallySelectedValueIsNotMigrated) {
- DefaultSearchManager::Source source;
- TemplateURLData prepopulated_default(
- *default_search_manager()->GetDefaultSearchEngine(&source));
- EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source);
-
- TemplateURL prepopulated_turl(prepopulated_default);
-
- // Store a value in the legacy location.
- SaveDefaultSearchProviderToLegacyPrefs(&prepopulated_turl);
-
- // Run the migration.
- ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service());
-
- // Test that the legacy value is not migrated, as it is not user-selected.
- default_search_manager()->GetDefaultSearchEngine(&source);
- EXPECT_EQ(DefaultSearchManager::FROM_FALLBACK, source);
-}
diff --git a/chromium/components/search_engines/default_search_pref_test_util.cc b/chromium/components/search_engines/default_search_pref_test_util.cc
deleted file mode 100644
index 193ab8f1452..00000000000
--- a/chromium/components/search_engines/default_search_pref_test_util.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/search_engines/default_search_pref_test_util.h"
-
-#include "base/strings/string_split.h"
-#include "components/search_engines/default_search_manager.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-// static
-std::unique_ptr<base::DictionaryValue>
-DefaultSearchPrefTestUtil::CreateDefaultSearchPreferenceValue(
- bool enabled,
- const std::string& name,
- const std::string& keyword,
- const std::string& search_url,
- const std::string& suggest_url,
- const std::string& icon_url,
- const std::string& encodings,
- const std::string& alternate_url,
- const std::string& search_terms_replacement_key) {
- std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
- if (!enabled) {
- value->SetBoolean(DefaultSearchManager::kDisabledByPolicy, true);
- return value;
- }
-
- EXPECT_FALSE(keyword.empty());
- EXPECT_FALSE(search_url.empty());
- value->Set(DefaultSearchManager::kShortName,
- new base::StringValue(name));
- value->Set(DefaultSearchManager::kKeyword,
- new base::StringValue(keyword));
- value->Set(DefaultSearchManager::kURL,
- new base::StringValue(search_url));
- value->Set(DefaultSearchManager::kSuggestionsURL,
- new base::StringValue(suggest_url));
- value->Set(DefaultSearchManager::kFaviconURL,
- new base::StringValue(icon_url));
- value->Set(DefaultSearchManager::kSearchTermsReplacementKey,
- new base::StringValue(search_terms_replacement_key));
-
- std::unique_ptr<base::ListValue> encodings_list(new base::ListValue);
- for (const std::string& term : base::SplitString(
- encodings, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL))
- encodings_list->AppendString(term);
- value->Set(DefaultSearchManager::kInputEncodings, encodings_list.release());
-
- std::unique_ptr<base::ListValue> alternate_url_list(new base::ListValue());
- if (!alternate_url.empty())
- alternate_url_list->AppendString(alternate_url);
- value->Set(DefaultSearchManager::kAlternateURLs,
- alternate_url_list.release());
- return value;
-}
diff --git a/chromium/components/search_engines/default_search_pref_test_util.h b/chromium/components/search_engines/default_search_pref_test_util.h
deleted file mode 100644
index 1732119b3bb..00000000000
--- a/chromium/components/search_engines/default_search_pref_test_util.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
-#define COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
-
-#include <memory>
-#include <string>
-
-#include "base/values.h"
-#include "components/search_engines/default_search_manager.h"
-
-class DefaultSearchPrefTestUtil {
- public:
- // Creates a DictionaryValue which can be used as a
- // kDefaultSearchProviderDataPrefName preference value.
- static std::unique_ptr<base::DictionaryValue>
- CreateDefaultSearchPreferenceValue(
- bool enabled,
- const std::string& name,
- const std::string& keyword,
- const std::string& search_url,
- const std::string& suggest_url,
- const std::string& icon_url,
- const std::string& encodings,
- const std::string& alternate_url,
- const std::string& search_terms_replacement_key);
-
- // Set the managed preferences for the default search provider and trigger
- // notification. If |alternate_url| is empty, uses an empty list of alternate
- // URLs, otherwise use a list containing a single entry.
- template<typename TestingPrefService>
- static void SetManagedPref(TestingPrefService* pref_service,
- bool enabled,
- const std::string& name,
- const std::string& keyword,
- const std::string& search_url,
- const std::string& suggest_url,
- const std::string& icon_url,
- const std::string& encodings,
- const std::string& alternate_url,
- const std::string& search_terms_replacement_key) {
- pref_service->SetManagedPref(
- DefaultSearchManager::kDefaultSearchProviderDataPrefName,
- CreateDefaultSearchPreferenceValue(
- enabled, name, keyword, search_url, suggest_url, icon_url,
- encodings, alternate_url, search_terms_replacement_key).release());
- }
-
- // Remove all the managed preferences for the default search provider and
- // trigger notification.
- template<typename TestingPrefService>
- static void RemoveManagedPref(TestingPrefService* pref_service) {
- pref_service->RemoveManagedPref(
- DefaultSearchManager::kDefaultSearchProviderDataPrefName);
- }
-};
-
-#endif // COMPONENTS_SEARCH_ENGINES_DEFAULT_SEARCH_PREF_TEST_UTIL_H_
diff --git a/chromium/components/search_engines/keyword_table.cc b/chromium/components/search_engines/keyword_table.cc
index eee2ac8273e..8ca529c1fb1 100644
--- a/chromium/components/search_engines/keyword_table.cc
+++ b/chromium/components/search_engines/keyword_table.cc
@@ -49,7 +49,10 @@ const std::string ColumnsForVersion(int version, bool concatenated) {
columns.push_back("date_created");
columns.push_back("usage_count");
columns.push_back("input_encodings");
- columns.push_back("show_in_default_list");
+ if (version <= 67) {
+ // Column removed after version 67.
+ columns.push_back("show_in_default_list");
+ }
columns.push_back("suggest_url");
columns.push_back("prepopulate_id");
if (version <= 44) {
@@ -81,6 +84,10 @@ const std::string ColumnsForVersion(int version, bool concatenated) {
// Column added in version 53.
columns.push_back("new_tab_url");
}
+ if (version >= 69) {
+ // Column added in version 69.
+ columns.push_back("last_visited");
+ }
return base::JoinString(columns, std::string(concatenated ? " || " : ", "));
}
@@ -119,21 +126,21 @@ void BindURLToStatement(const TemplateURLData& data,
s->BindInt(starting_column + 7, data.usage_count);
s->BindString(starting_column + 8,
base::JoinString(data.input_encodings, ";"));
- s->BindBool(starting_column + 9, data.show_in_default_list);
- s->BindString(starting_column + 10, data.suggestions_url);
- s->BindInt(starting_column + 11, data.prepopulate_id);
- s->BindBool(starting_column + 12, data.created_by_policy);
- s->BindString(starting_column + 13, data.instant_url);
- s->BindInt64(starting_column + 14, data.last_modified.ToTimeT());
- s->BindString(starting_column + 15, data.sync_guid);
- s->BindString(starting_column + 16, alternate_urls);
- s->BindString(starting_column + 17, data.search_terms_replacement_key);
- s->BindString(starting_column + 18, data.image_url);
- s->BindString(starting_column + 19, data.search_url_post_params);
- s->BindString(starting_column + 20, data.suggestions_url_post_params);
- s->BindString(starting_column + 21, data.instant_url_post_params);
- s->BindString(starting_column + 22, data.image_url_post_params);
- s->BindString(starting_column + 23, data.new_tab_url);
+ s->BindString(starting_column + 9, data.suggestions_url);
+ s->BindInt(starting_column + 10, data.prepopulate_id);
+ s->BindBool(starting_column + 11, data.created_by_policy);
+ s->BindString(starting_column + 12, data.instant_url);
+ s->BindInt64(starting_column + 13, data.last_modified.ToTimeT());
+ s->BindString(starting_column + 14, data.sync_guid);
+ s->BindString(starting_column + 15, alternate_urls);
+ s->BindString(starting_column + 16, data.search_terms_replacement_key);
+ s->BindString(starting_column + 17, data.image_url);
+ s->BindString(starting_column + 18, data.search_url_post_params);
+ s->BindString(starting_column + 19, data.suggestions_url_post_params);
+ s->BindString(starting_column + 20, data.instant_url_post_params);
+ s->BindString(starting_column + 21, data.image_url_post_params);
+ s->BindString(starting_column + 22, data.new_tab_url);
+ s->BindInt64(starting_column + 23, data.last_visited.ToTimeT());
}
WebDatabaseTable::TypeKey GetKey() {
@@ -161,31 +168,31 @@ WebDatabaseTable::TypeKey KeywordTable::GetTypeKey() const {
bool KeywordTable::CreateTablesIfNecessary() {
return db_->DoesTableExist("keywords") ||
db_->Execute("CREATE TABLE keywords ("
- "id INTEGER PRIMARY KEY,"
- "short_name VARCHAR NOT NULL,"
- "keyword VARCHAR NOT NULL,"
- "favicon_url VARCHAR NOT NULL,"
- "url VARCHAR NOT NULL,"
- "safe_for_autoreplace INTEGER,"
- "originating_url VARCHAR,"
- "date_created INTEGER DEFAULT 0,"
- "usage_count INTEGER DEFAULT 0,"
- "input_encodings VARCHAR,"
- "show_in_default_list INTEGER,"
- "suggest_url VARCHAR,"
- "prepopulate_id INTEGER DEFAULT 0,"
- "created_by_policy INTEGER DEFAULT 0,"
- "instant_url VARCHAR,"
- "last_modified INTEGER DEFAULT 0,"
- "sync_guid VARCHAR,"
- "alternate_urls VARCHAR,"
- "search_terms_replacement_key VARCHAR,"
- "image_url VARCHAR,"
- "search_url_post_params VARCHAR,"
- "suggest_url_post_params VARCHAR,"
- "instant_url_post_params VARCHAR,"
- "image_url_post_params VARCHAR,"
- "new_tab_url VARCHAR)");
+ "id INTEGER PRIMARY KEY,"
+ "short_name VARCHAR NOT NULL,"
+ "keyword VARCHAR NOT NULL,"
+ "favicon_url VARCHAR NOT NULL,"
+ "url VARCHAR NOT NULL,"
+ "safe_for_autoreplace INTEGER,"
+ "originating_url VARCHAR,"
+ "date_created INTEGER DEFAULT 0,"
+ "usage_count INTEGER DEFAULT 0,"
+ "input_encodings VARCHAR,"
+ "suggest_url VARCHAR,"
+ "prepopulate_id INTEGER DEFAULT 0,"
+ "created_by_policy INTEGER DEFAULT 0,"
+ "instant_url VARCHAR,"
+ "last_modified INTEGER DEFAULT 0,"
+ "sync_guid VARCHAR,"
+ "alternate_urls VARCHAR,"
+ "search_terms_replacement_key VARCHAR,"
+ "image_url VARCHAR,"
+ "search_url_post_params VARCHAR,"
+ "suggest_url_post_params VARCHAR,"
+ "instant_url_post_params VARCHAR,"
+ "image_url_post_params VARCHAR,"
+ "new_tab_url VARCHAR,"
+ " last_visited INTEGER DEFAULT 0)");
}
bool KeywordTable::IsSyncable() {
@@ -202,6 +209,11 @@ bool KeywordTable::MigrateToVersion(int version,
case 59:
*update_compatible_version = true;
return MigrateToVersion59RemoveExtensionKeywords();
+ case 68:
+ *update_compatible_version = true;
+ return MigrateToVersion68RemoveShowInDefaultListColumn();
+ case 69:
+ return MigrateToVersion69AddLastVisitedColumn();
}
return true;
@@ -289,6 +301,53 @@ bool KeywordTable::MigrateToVersion59RemoveExtensionKeywords() {
"WHERE url LIKE 'chrome-extension://%'");
}
+// SQLite does not support DROP COLUMN operation. So A new table is created
+// without the show_in_default_list column. Data from all but the dropped column
+// of the old table is copied into it. After that, the old table is dropped and
+// the new table is renamed to it.
+bool KeywordTable::MigrateToVersion68RemoveShowInDefaultListColumn() {
+ sql::Transaction transaction(db_);
+ std::string query_str =
+ std::string("INSERT INTO temp_keywords SELECT " +
+ ColumnsForVersion(68, false) + " FROM keywords");
+ const char* clone_query = query_str.c_str();
+ return transaction.Begin() &&
+ db_->Execute(
+ "CREATE TABLE temp_keywords ("
+ "id INTEGER PRIMARY KEY,"
+ "short_name VARCHAR NOT NULL,"
+ "keyword VARCHAR NOT NULL,"
+ "favicon_url VARCHAR NOT NULL,"
+ "url VARCHAR NOT NULL,"
+ "safe_for_autoreplace INTEGER,"
+ "originating_url VARCHAR,"
+ "date_created INTEGER DEFAULT 0,"
+ "usage_count INTEGER DEFAULT 0,"
+ "input_encodings VARCHAR,"
+ "suggest_url VARCHAR,"
+ "prepopulate_id INTEGER DEFAULT 0,"
+ "created_by_policy INTEGER DEFAULT 0,"
+ "instant_url VARCHAR,"
+ "last_modified INTEGER DEFAULT 0,"
+ "sync_guid VARCHAR,"
+ "alternate_urls VARCHAR,"
+ "search_terms_replacement_key VARCHAR,"
+ "image_url VARCHAR,"
+ "search_url_post_params VARCHAR,"
+ "suggest_url_post_params VARCHAR,"
+ "instant_url_post_params VARCHAR,"
+ "image_url_post_params VARCHAR,"
+ "new_tab_url VARCHAR)") &&
+ db_->Execute(clone_query) && db_->Execute("DROP TABLE keywords") &&
+ db_->Execute("ALTER TABLE temp_keywords RENAME TO keywords") &&
+ transaction.Commit();
+}
+
+bool KeywordTable::MigrateToVersion69AddLastVisitedColumn() {
+ return db_->Execute("ALTER TABLE keywords ADD COLUMN last_visited "
+ "INTEGER DEFAULT 0");
+}
+
// static
bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
TemplateURLData* data) {
@@ -303,32 +362,31 @@ bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
if (s.ColumnString(4).empty())
return false;
data->SetURL(s.ColumnString(4));
- data->suggestions_url = s.ColumnString(11);
- data->instant_url = s.ColumnString(14);
- data->image_url = s.ColumnString(19);
- data->new_tab_url = s.ColumnString(24);
- data->search_url_post_params = s.ColumnString(20);
- data->suggestions_url_post_params = s.ColumnString(21);
- data->instant_url_post_params = s.ColumnString(22);
- data->image_url_post_params = s.ColumnString(23);
+ data->suggestions_url = s.ColumnString(10);
+ data->instant_url = s.ColumnString(13);
+ data->image_url = s.ColumnString(18);
+ data->new_tab_url = s.ColumnString(23);
+ data->search_url_post_params = s.ColumnString(19);
+ data->suggestions_url_post_params = s.ColumnString(20);
+ data->instant_url_post_params = s.ColumnString(21);
+ data->image_url_post_params = s.ColumnString(22);
data->favicon_url = GURL(s.ColumnString(3));
data->originating_url = GURL(s.ColumnString(6));
- data->show_in_default_list = s.ColumnBool(10);
data->safe_for_autoreplace = s.ColumnBool(5);
data->input_encodings = base::SplitString(
s.ColumnString(9), ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
data->id = s.ColumnInt64(0);
data->date_created = Time::FromTimeT(s.ColumnInt64(7));
- data->last_modified = Time::FromTimeT(s.ColumnInt64(15));
- data->created_by_policy = s.ColumnBool(13);
+ data->last_modified = Time::FromTimeT(s.ColumnInt64(14));
+ data->created_by_policy = s.ColumnBool(12);
data->usage_count = s.ColumnInt(8);
- data->prepopulate_id = s.ColumnInt(12);
- data->sync_guid = s.ColumnString(16);
+ data->prepopulate_id = s.ColumnInt(11);
+ data->sync_guid = s.ColumnString(15);
data->alternate_urls.clear();
base::JSONReader json_reader;
std::unique_ptr<base::Value> value(
- json_reader.ReadToValue(s.ColumnString(17)));
+ json_reader.ReadToValue(s.ColumnString(16)));
base::ListValue* alternate_urls_value;
if (value.get() && value->GetAsList(&alternate_urls_value)) {
std::string alternate_url;
@@ -338,7 +396,8 @@ bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
}
}
- data->search_terms_replacement_key = s.ColumnString(18);
+ data->search_terms_replacement_key = s.ColumnString(17);
+ data->last_visited = Time::FromTimeT(s.ColumnInt64(24));
return true;
}
@@ -346,8 +405,8 @@ bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s,
bool KeywordTable::AddKeyword(const TemplateURLData& data) {
DCHECK(data.id);
std::string query("INSERT INTO keywords (" + GetKeywordColumns() + ") "
- "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
- " ?)");
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
+ " ?,?)");
sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, query.c_str()));
BindURLToStatement(data, &s, 0, 1);
@@ -369,12 +428,12 @@ bool KeywordTable::UpdateKeyword(const TemplateURLData& data) {
SQL_FROM_HERE,
"UPDATE keywords SET short_name=?, keyword=?, favicon_url=?, url=?, "
"safe_for_autoreplace=?, originating_url=?, date_created=?, "
- "usage_count=?, input_encodings=?, show_in_default_list=?, "
- "suggest_url=?, prepopulate_id=?, created_by_policy=?, instant_url=?, "
+ "usage_count=?, input_encodings=?, suggest_url=?, "
+ "prepopulate_id=?, created_by_policy=?, instant_url=?, "
"last_modified=?, sync_guid=?, alternate_urls=?, "
"search_terms_replacement_key=?, image_url=?, search_url_post_params=?, "
"suggest_url_post_params=?, instant_url_post_params=?, "
- "image_url_post_params=?, new_tab_url=? WHERE id=?"));
+ "image_url_post_params=?, new_tab_url=?, last_visited=? WHERE id=?"));
BindURLToStatement(data, &s, 24, 0); // "24" binds id() as the last item.
return s.Run();
@@ -401,87 +460,3 @@ bool KeywordTable::GetKeywordAsString(TemplateURLID id,
*result = s.ColumnString(0);
return true;
}
-
-bool KeywordTable::MigrateKeywordsTableForVersion45(const std::string& name) {
- // Create a new table without the columns we're dropping.
- if (!db_->Execute("CREATE TABLE keywords_temp ("
- "id INTEGER PRIMARY KEY,"
- "short_name VARCHAR NOT NULL,"
- "keyword VARCHAR NOT NULL,"
- "favicon_url VARCHAR NOT NULL,"
- "url VARCHAR NOT NULL,"
- "safe_for_autoreplace INTEGER,"
- "originating_url VARCHAR,"
- "date_created INTEGER DEFAULT 0,"
- "usage_count INTEGER DEFAULT 0,"
- "input_encodings VARCHAR,"
- "show_in_default_list INTEGER,"
- "suggest_url VARCHAR,"
- "prepopulate_id INTEGER DEFAULT 0,"
- "created_by_policy INTEGER DEFAULT 0,"
- "instant_url VARCHAR,"
- "last_modified INTEGER DEFAULT 0,"
- "sync_guid VARCHAR)"))
- return false;
- std::string sql("INSERT INTO keywords_temp SELECT " +
- ColumnsForVersion(46, false) + " FROM " + name);
- if (!db_->Execute(sql.c_str()))
- return false;
-
- // NOTE: The ORDER BY here ensures that the uniquing process for keywords will
- // happen identically on both the normal and backup tables.
- sql = "SELECT id, keyword, url, autogenerate_keyword FROM " + name +
- " ORDER BY id ASC";
- sql::Statement s(db_->GetUniqueStatement(sql.c_str()));
- base::string16 placeholder_keyword(base::ASCIIToUTF16("dummy"));
- std::set<base::string16> keywords;
- while (s.Step()) {
- base::string16 keyword(s.ColumnString16(1));
- bool generate_keyword = keyword.empty() || s.ColumnBool(3);
- if (generate_keyword)
- keyword = placeholder_keyword;
- TemplateURLData data;
- data.SetKeyword(keyword);
- data.SetURL(s.ColumnString(2));
- TemplateURL turl(data);
- // Don't persist extension keywords to disk. These will get added to the
- // TemplateURLService as the extensions are loaded.
- bool delete_entry = turl.type() == TemplateURL::OMNIBOX_API_EXTENSION;
- if (!delete_entry && generate_keyword) {
- // Explicitly generate keywords for all rows with the autogenerate bit set
- // or where the keyword is empty.
- SearchTermsData terms_data;
- GURL url(turl.GenerateSearchURL(terms_data));
- if (!url.is_valid()) {
- delete_entry = true;
- } else {
- // Ensure autogenerated keywords are unique.
- keyword = TemplateURL::GenerateKeyword(url);
- while (keywords.count(keyword))
- keyword.append(base::ASCIIToUTF16("_"));
- sql::Statement u(db_->GetUniqueStatement(
- "UPDATE keywords_temp SET keyword=? WHERE id=?"));
- u.BindString16(0, keyword);
- u.BindInt64(1, s.ColumnInt64(0));
- if (!u.Run())
- return false;
- }
- }
- if (delete_entry) {
- sql::Statement u(db_->GetUniqueStatement(
- "DELETE FROM keywords_temp WHERE id=?"));
- u.BindInt64(0, s.ColumnInt64(0));
- if (!u.Run())
- return false;
- } else {
- keywords.insert(keyword);
- }
- }
-
- // Replace the old table with the new one.
- sql = "DROP TABLE " + name;
- if (!db_->Execute(sql.c_str()))
- return false;
- sql = "ALTER TABLE keywords_temp RENAME TO " + name;
- return db_->Execute(sql.c_str());
-}
diff --git a/chromium/components/search_engines/keyword_table.h b/chromium/components/search_engines/keyword_table.h
index 2ac8695fca5..90a42573fa9 100644
--- a/chromium/components/search_engines/keyword_table.h
+++ b/chromium/components/search_engines/keyword_table.h
@@ -36,7 +36,6 @@ class Statement;
// keyword
// favicon_url
// url
-// show_in_default_list
// safe_for_autoreplace
// originating_url
// date_created This column was added after we allowed keywords.
@@ -131,6 +130,8 @@ class KeywordTable : public WebDatabaseTable {
// Table migration functions.
bool MigrateToVersion53AddNewTabURLColumn();
bool MigrateToVersion59RemoveExtensionKeywords();
+ bool MigrateToVersion68RemoveShowInDefaultListColumn();
+ bool MigrateToVersion69AddLastVisitedColumn();
private:
friend class KeywordTableTest;
@@ -165,10 +166,6 @@ class KeywordTable : public WebDatabaseTable {
const std::string& table_name,
std::string* result);
- // Migrates table |name| (which should be either "keywords" or
- // "keywords_backup") from version 44 to version 45.
- bool MigrateKeywordsTableForVersion45(const std::string& name);
-
DISALLOW_COPY_AND_ASSIGN(KeywordTable);
};
diff --git a/chromium/components/search_engines/keyword_table_unittest.cc b/chromium/components/search_engines/keyword_table_unittest.cc
index 0e4503aaee8..e0de66ab705 100644
--- a/chromium/components/search_engines/keyword_table_unittest.cc
+++ b/chromium/components/search_engines/keyword_table_unittest.cc
@@ -53,13 +53,13 @@ class KeywordTableTest : public testing::Test {
keyword.image_url_post_params = "name=1,value=2";
keyword.favicon_url = GURL("http://favicon.url/");
keyword.originating_url = GURL("http://google.com/");
- keyword.show_in_default_list = true;
keyword.safe_for_autoreplace = true;
keyword.input_encodings.push_back("UTF-8");
keyword.input_encodings.push_back("UTF-16");
keyword.id = 1;
keyword.date_created = base::Time::UnixEpoch();
keyword.last_modified = base::Time::UnixEpoch();
+ keyword.last_visited = base::Time::UnixEpoch();
keyword.created_by_policy = true;
keyword.usage_count = 32;
keyword.prepopulate_id = 10;
@@ -124,8 +124,6 @@ TEST_F(KeywordTableTest, Keywords) {
EXPECT_EQ(keyword.instant_url, restored_keyword.instant_url);
EXPECT_EQ(keyword.favicon_url, restored_keyword.favicon_url);
EXPECT_EQ(keyword.originating_url, restored_keyword.originating_url);
- EXPECT_EQ(keyword.show_in_default_list,
- restored_keyword.show_in_default_list);
EXPECT_EQ(keyword.safe_for_autoreplace,
restored_keyword.safe_for_autoreplace);
EXPECT_EQ(keyword.input_encodings, restored_keyword.input_encodings);
@@ -135,6 +133,8 @@ TEST_F(KeywordTableTest, Keywords) {
restored_keyword.date_created.ToTimeT());
EXPECT_EQ(keyword.last_modified.ToTimeT(),
restored_keyword.last_modified.ToTimeT());
+ EXPECT_EQ(keyword.last_visited.ToTimeT(),
+ restored_keyword.last_visited.ToTimeT());
EXPECT_EQ(keyword.created_by_policy, restored_keyword.created_by_policy);
EXPECT_EQ(keyword.usage_count, restored_keyword.usage_count);
EXPECT_EQ(keyword.prepopulate_id, restored_keyword.prepopulate_id);
@@ -168,8 +168,6 @@ TEST_F(KeywordTableTest, UpdateKeyword) {
EXPECT_EQ(keyword.instant_url, restored_keyword.instant_url);
EXPECT_EQ(keyword.favicon_url, restored_keyword.favicon_url);
EXPECT_EQ(keyword.originating_url, restored_keyword.originating_url);
- EXPECT_EQ(keyword.show_in_default_list,
- restored_keyword.show_in_default_list);
EXPECT_EQ(keyword.safe_for_autoreplace,
restored_keyword.safe_for_autoreplace);
EXPECT_EQ(keyword.input_encodings, restored_keyword.input_encodings);
diff --git a/chromium/components/search_engines/prepopulated_engines.json b/chromium/components/search_engines/prepopulated_engines.json
index 97dad3e51dc..3409ecc4a77 100644
--- a/chromium/components/search_engines/prepopulated_engines.json
+++ b/chromium/components/search_engines/prepopulated_engines.json
@@ -30,7 +30,7 @@
// Increment this if you change the data in ways that mean users with
// existing data should get a new version.
- "kCurrentDataVersion": 96
+ "kCurrentDataVersion": 97
},
// The following engines are included in country lists and are added to the
@@ -164,7 +164,7 @@
"name": "\ub124\uc774\ubc84",
"keyword": "naver.com",
"favicon_url": "https://ssl.pstatic.net/sstatic/search/favicon/favicon_140327.ico",
- "search_url": "https://search.naver.com/search.naver?ie={inputEncoding}&query={searchTerms}",
+ "search_url": "https://search.naver.com/search.naver?ie={inputEncoding}&query={searchTerms}&sm=chr_hty",
"suggest_url": "https://ac.search.naver.com/nx/ac?of=os&ie={inputEncoding}&q={searchTerms}&oe={outputEncoding}",
"type": "SEARCH_ENGINE_NAVER",
"id": 67
diff --git a/chromium/components/search_engines/search_engine_data_type_controller.cc b/chromium/components/search_engines/search_engine_data_type_controller.cc
index 536f38703ac..1796368fb89 100644
--- a/chromium/components/search_engines/search_engine_data_type_controller.cc
+++ b/chromium/components/search_engines/search_engine_data_type_controller.cc
@@ -4,13 +4,19 @@
#include "components/search_engines/search_engine_data_type_controller.h"
+#include "base/threading/thread_task_runner_handle.h"
+
namespace browser_sync {
SearchEngineDataTypeController::SearchEngineDataTypeController(
const base::Closure& dump_stack,
syncer::SyncClient* sync_client,
TemplateURLService* template_url_service)
- : UIDataTypeController(syncer::SEARCH_ENGINES, dump_stack, sync_client),
+ : AsyncDirectoryTypeController(syncer::SEARCH_ENGINES,
+ dump_stack,
+ sync_client,
+ syncer::GROUP_UI,
+ base::ThreadTaskRunnerHandle::Get()),
template_url_service_(template_url_service) {}
TemplateURLService::Subscription*
@@ -47,7 +53,7 @@ void SearchEngineDataTypeController::StopModels() {
void SearchEngineDataTypeController::OnTemplateURLServiceLoaded() {
DCHECK(CalledOnValidThread());
- DCHECK_EQ(MODEL_STARTING, state_);
+ DCHECK_EQ(MODEL_STARTING, state());
template_url_subscription_.reset();
OnModelLoaded();
}
diff --git a/chromium/components/search_engines/search_engine_data_type_controller.h b/chromium/components/search_engines/search_engine_data_type_controller.h
index 0a6e1dc1ca4..a7925b5c893 100644
--- a/chromium/components/search_engines/search_engine_data_type_controller.h
+++ b/chromium/components/search_engines/search_engine_data_type_controller.h
@@ -10,16 +10,15 @@
#include "base/macros.h"
#include "components/search_engines/template_url_service.h"
-#include "components/sync/driver/ui_data_type_controller.h"
-
-class Profile;
+#include "components/sync/driver/async_directory_type_controller.h"
namespace browser_sync {
// Controller for the SEARCH_ENGINES sync data type. This class tells sync
// how to load the model for this data type, and the superclasses manage
// controlling the rest of the state of the datatype with regards to sync.
-class SearchEngineDataTypeController : public syncer::UIDataTypeController {
+class SearchEngineDataTypeController
+ : public syncer::AsyncDirectoryTypeController {
public:
// |dump_stack| is called when an unrecoverable error occurs.
SearchEngineDataTypeController(const base::Closure& dump_stack,
@@ -30,7 +29,7 @@ class SearchEngineDataTypeController : public syncer::UIDataTypeController {
TemplateURLService::Subscription* GetSubscriptionForTesting();
private:
- // FrontendDataTypeController:
+ // AsyncDirectoryTypeController:
bool StartModels() override;
void StopModels() override;
diff --git a/chromium/components/search_engines/search_engine_data_type_controller_unittest.cc b/chromium/components/search_engines/search_engine_data_type_controller_unittest.cc
index 4f308855c21..a9c07218644 100644
--- a/chromium/components/search_engines/search_engine_data_type_controller_unittest.cc
+++ b/chromium/components/search_engines/search_engine_data_type_controller_unittest.cc
@@ -157,6 +157,9 @@ TEST_F(SyncSearchEngineDataTypeControllerTest, Stop) {
search_engine_dtc_.Stop();
EXPECT_EQ(syncer::DataTypeController::NOT_RUNNING,
search_engine_dtc_.state());
+ // AsyncDirectoryTypeController::Stop posts call to StopLocalService to model
+ // thread. We run message loop for this call to take effect.
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(syncable_service_.syncing());
}
diff --git a/chromium/components/search_engines/search_engines_pref_names.cc b/chromium/components/search_engines/search_engines_pref_names.cc
index 0a0d51f392b..a65cff338a8 100644
--- a/chromium/components/search_engines/search_engines_pref_names.cc
+++ b/chromium/components/search_engines/search_engines_pref_names.cc
@@ -18,82 +18,6 @@ const char kSyncedDefaultSearchProviderGUID[] =
const char kDefaultSearchProviderEnabled[] =
"default_search_provider.enabled";
-// The URL (as understood by TemplateURLRef) the default search provider uses
-// for searches.
-const char kDefaultSearchProviderSearchURL[] =
- "default_search_provider.search_url";
-
-// The URL (as understood by TemplateURLRef) the default search provider uses
-// for suggestions.
-const char kDefaultSearchProviderSuggestURL[] =
- "default_search_provider.suggest_url";
-
-// The URL (as understood by TemplateURLRef) the default search provider uses
-// for instant results.
-const char kDefaultSearchProviderInstantURL[] =
- "default_search_provider.instant_url";
-
-// The URL (as understood by TemplateURLRef) the default search provider uses
-// for image search results.
-const char kDefaultSearchProviderImageURL[] =
- "default_search_provider.image_url";
-
-// The URL (as understood by TemplateURLRef) the default search provider uses
-// for the new tab page.
-const char kDefaultSearchProviderNewTabURL[] =
- "default_search_provider.new_tab_url";
-
-// The string of post parameters (as understood by TemplateURLRef) the default
-// search provider uses for searches by using POST.
-const char kDefaultSearchProviderSearchURLPostParams[] =
- "default_search_provider.search_url_post_params";
-
-// The string of post parameters (as understood by TemplateURLRef) the default
-// search provider uses for suggestions by using POST.
-const char kDefaultSearchProviderSuggestURLPostParams[] =
- "default_search_provider.suggest_url_post_params";
-
-// The string of post parameters (as understood by TemplateURLRef) the default
-// search provider uses for instant results by using POST.
-const char kDefaultSearchProviderInstantURLPostParams[] =
- "default_search_provider.instant_url_post_params";
-
-// The string of post parameters (as understood by TemplateURLRef) the default
-// search provider uses for image search results by using POST.
-const char kDefaultSearchProviderImageURLPostParams[] =
- "default_search_provider.image_url_post_params";
-
-// The Favicon URL (as understood by TemplateURLRef) of the default search
-// provider.
-const char kDefaultSearchProviderIconURL[] =
- "default_search_provider.icon_url";
-
-// The input encoding (as understood by TemplateURLRef) supported by the default
-// search provider. The various encodings are separated by ';'
-const char kDefaultSearchProviderEncodings[] =
- "default_search_provider.encodings";
-
-// The name of the default search provider.
-const char kDefaultSearchProviderName[] = "default_search_provider.name";
-
-// The keyword of the default search provider.
-const char kDefaultSearchProviderKeyword[] = "default_search_provider.keyword";
-
-// The id of the default search provider.
-const char kDefaultSearchProviderID[] = "default_search_provider.id";
-
-// The prepopulate id of the default search provider.
-const char kDefaultSearchProviderPrepopulateID[] =
- "default_search_provider.prepopulate_id";
-
-// The alternate urls of the default search provider.
-const char kDefaultSearchProviderAlternateURLs[] =
- "default_search_provider.alternate_urls";
-
-// Search term placement query parameter for the default search provider.
-const char kDefaultSearchProviderSearchTermsReplacementKey[] =
- "default_search_provider.search_terms_replacement_key";
-
// The dictionary key used when the default search providers are given
// in the preferences file. Normally they are copied from the master
// preferences file.
diff --git a/chromium/components/search_engines/search_engines_pref_names.h b/chromium/components/search_engines/search_engines_pref_names.h
index 22f7e81bfad..0f07d015814 100644
--- a/chromium/components/search_engines/search_engines_pref_names.h
+++ b/chromium/components/search_engines/search_engines_pref_names.h
@@ -9,23 +9,6 @@ namespace prefs {
extern const char kSyncedDefaultSearchProviderGUID[];
extern const char kDefaultSearchProviderEnabled[];
-extern const char kDefaultSearchProviderSearchURL[];
-extern const char kDefaultSearchProviderSuggestURL[];
-extern const char kDefaultSearchProviderInstantURL[];
-extern const char kDefaultSearchProviderImageURL[];
-extern const char kDefaultSearchProviderNewTabURL[];
-extern const char kDefaultSearchProviderSearchURLPostParams[];
-extern const char kDefaultSearchProviderSuggestURLPostParams[];
-extern const char kDefaultSearchProviderInstantURLPostParams[];
-extern const char kDefaultSearchProviderImageURLPostParams[];
-extern const char kDefaultSearchProviderIconURL[];
-extern const char kDefaultSearchProviderEncodings[];
-extern const char kDefaultSearchProviderName[];
-extern const char kDefaultSearchProviderKeyword[];
-extern const char kDefaultSearchProviderID[];
-extern const char kDefaultSearchProviderPrepopulateID[];
-extern const char kDefaultSearchProviderAlternateURLs[];
-extern const char kDefaultSearchProviderSearchTermsReplacementKey[];
extern const char kSearchProviderOverrides[];
extern const char kSearchProviderOverridesVersion[];
extern const char kCountryIDAtInstall[];
diff --git a/chromium/components/search_engines/search_terms_data.cc b/chromium/components/search_engines/search_terms_data.cc
index 6de540664d0..f0ef783c6ec 100644
--- a/chromium/components/search_engines/search_terms_data.cc
+++ b/chromium/components/search_engines/search_terms_data.cc
@@ -54,8 +54,7 @@ std::string SearchTermsData::GetSuggestRequestIdentifier() const {
return std::string();
}
-std::string SearchTermsData::InstantExtendedEnabledParam(
- bool for_search) const {
+std::string SearchTermsData::InstantExtendedEnabledParam() const {
return std::string();
}
diff --git a/chromium/components/search_engines/search_terms_data.h b/chromium/components/search_engines/search_terms_data.h
index c91745e8a50..50f7ed2eb93 100644
--- a/chromium/components/search_engines/search_terms_data.h
+++ b/chromium/components/search_engines/search_terms_data.h
@@ -49,8 +49,9 @@ class SearchTermsData {
// This implementation returns the empty string.
virtual std::string GetSuggestRequestIdentifier() const;
- // Returns a string indicating whether InstantExtended is enabled.
- virtual std::string InstantExtendedEnabledParam(bool for_search) const;
+ // Returns a string indicating whether InstantExtended is enabled, suitable
+ // for adding as a query string param to the homepage or search requests.
+ virtual std::string InstantExtendedEnabledParam() const;
// Returns a string that will cause the search results page to update
// incrementally.
diff --git a/chromium/components/search_engines/template_url.cc b/chromium/components/search_engines/template_url.cc
index 89029652922..0a457d1632c 100644
--- a/chromium/components/search_engines/template_url.cc
+++ b/chromium/components/search_engines/template_url.cc
@@ -186,39 +186,15 @@ TemplateURLRef::SearchTermsArgs::~SearchTermsArgs() {
TemplateURLRef::SearchTermsArgs::ContextualSearchParams::
ContextualSearchParams()
: version(-1),
- start(base::string16::npos),
- end(base::string16::npos),
contextual_cards_version(0) {}
TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams(
int version,
- const std::string& selection,
- const std::string& base_page_url,
- int contextual_cards_version)
+ int contextual_cards_version,
+ const std::string& home_country)
: version(version),
- start(base::string16::npos),
- end(base::string16::npos),
- selection(selection),
- base_page_url(base_page_url),
- contextual_cards_version(contextual_cards_version) {}
-
-TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams(
- int version,
- size_t start,
- size_t end,
- const std::string& selection,
- const std::string& content,
- const std::string& base_page_url,
- const std::string& encoding,
- int contextual_cards_version)
- : version(version),
- start(start),
- end(end),
- selection(selection),
- content(content),
- base_page_url(base_page_url),
- encoding(encoding),
- contextual_cards_version(contextual_cards_version) {}
+ contextual_cards_version(contextual_cards_version),
+ home_country(home_country) {}
TemplateURLRef::SearchTermsArgs::ContextualSearchParams::ContextualSearchParams(
const ContextualSearchParams& other) = default;
@@ -967,11 +943,13 @@ std::string TemplateURLRef::HandleReplacements(
case GOOGLE_INSTANT_EXTENDED_ENABLED:
DCHECK(!i->is_post_param);
+ // Regular search requests don't use Instant, so only add the param for
+ // other types.
HandleReplacement(std::string(),
- search_terms_data.InstantExtendedEnabledParam(
- type_ == SEARCH),
- *i,
- &url);
+ type_ == SEARCH
+ ? std::string()
+ : search_terms_data.InstantExtendedEnabledParam(),
+ *i, &url);
break;
case GOOGLE_CONTEXTUAL_SEARCH_VERSION:
@@ -992,24 +970,12 @@ std::string TemplateURLRef::HandleReplacements(
search_terms_args.contextual_search_params;
std::vector<std::string> args;
- if (params.start != std::string::npos)
- args.push_back("ctxs_start=" + base::SizeTToString(params.start));
- if (params.end != std::string::npos)
- args.push_back("ctxs_end=" + base::SizeTToString(params.end));
-
- if (!params.selection.empty())
- args.push_back("q=" + params.selection);
- if (!params.content.empty())
- args.push_back("ctxs_content=" + params.content);
- if (!params.base_page_url.empty())
- args.push_back("ctxsl_url=" + params.base_page_url);
- if (!params.encoding.empty())
- args.push_back("ctxs_encoding=" + params.encoding);
-
if (params.contextual_cards_version > 0) {
args.push_back("ctxsl_coca=" +
base::IntToString(params.contextual_cards_version));
}
+ if (!params.home_country.empty())
+ args.push_back("ctxs_hc=" + params.home_country);
HandleReplacement(std::string(), base::JoinString(args, "&"), *i, &url);
break;
@@ -1253,7 +1219,6 @@ bool TemplateURL::MatchesData(const TemplateURL* t_url,
(t_url->image_url_post_params() == data->image_url_post_params) &&
(t_url->favicon_url() == data->favicon_url) &&
(t_url->safe_for_autoreplace() == data->safe_for_autoreplace) &&
- (t_url->show_in_default_list() == data->show_in_default_list) &&
(t_url->input_encodings() == data->input_encodings) &&
(t_url->alternate_urls() == data->alternate_urls) &&
(t_url->search_terms_replacement_key() ==
@@ -1266,12 +1231,6 @@ base::string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
return bidi_safe_short_name;
}
-bool TemplateURL::ShowInDefaultList(
- const SearchTermsData& search_terms_data) const {
- return data_.show_in_default_list &&
- url_ref_->SupportsReplacement(search_terms_data);
-}
-
bool TemplateURL::SupportsReplacement(
const SearchTermsData& search_terms_data) const {
return url_ref_->SupportsReplacement(search_terms_data);
diff --git a/chromium/components/search_engines/template_url.h b/chromium/components/search_engines/template_url.h
index e931a0ae6b1..d57aed22627 100644
--- a/chromium/components/search_engines/template_url.h
+++ b/chromium/components/search_engines/template_url.h
@@ -79,51 +79,28 @@ class TemplateURLRef {
struct ContextualSearchParams {
ContextualSearchParams();
- // Used when the content is sent in the HTTP header instead of as CGI
- // parameters.
- // TODO(donnd): Remove base_page_url and selection parameters once
- // they are logged from the HTTP header.
+ // Modern constructor, used when the content is sent in the HTTP header
+ // instead of as CGI parameters.
+ // The |home_country| is an ISO country code for the country that the user
+ // considers their permanent home (which may be different from the country
+ // they are currently visiting). Pass an empty string if none available.
ContextualSearchParams(int version,
- const std::string& selection,
- const std::string& base_page_url,
- int contextual_cards_version);
- // TODO(donnd): Delete constructor once Clank, iOS, and tests no
- // longer depend on it.
- ContextualSearchParams(int version,
- size_t start,
- size_t end,
- const std::string& selection,
- const std::string& content,
- const std::string& base_page_url,
- const std::string& encoding,
- int contextual_cards_version);
+ int contextual_cards_version,
+ const std::string& home_country);
ContextualSearchParams(const ContextualSearchParams& other);
~ContextualSearchParams();
// The version of contextual search.
int version;
- // Offset into the page content of the start of the user selection.
- size_t start;
-
- // Offset into the page content of the end of the user selection.
- size_t end;
-
- // The user selection.
- std::string selection;
-
- // The text including and surrounding the user selection.
- std::string content;
-
- // The URL of the page containing the user selection.
- std::string base_page_url;
-
- // The encoding of content.
- std::string encoding;
-
// The version of Contextual Cards data to request.
// A value of 0 indicates no data needed.
int contextual_cards_version;
+
+ // The locale of the user's home country in an ISO country code format,
+ // or an empty string if not available. This indicates where the user
+ // resides, not where they currently are.
+ std::string home_country;
};
// The search terms (query).
@@ -571,11 +548,6 @@ class TemplateURL {
const GURL& originating_url() const { return data_.originating_url; }
- bool show_in_default_list() const { return data_.show_in_default_list; }
- // Returns true if show_in_default_list() is true and this TemplateURL has a
- // TemplateURLRef that supports replacement.
- bool ShowInDefaultList(const SearchTermsData& search_terms_data) const;
-
bool safe_for_autoreplace() const { return data_.safe_for_autoreplace; }
const std::vector<std::string>& input_encodings() const {
@@ -586,6 +558,7 @@ class TemplateURL {
base::Time date_created() const { return data_.date_created; }
base::Time last_modified() const { return data_.last_modified; }
+ base::Time last_visited() const { return data_.last_visited; }
bool created_by_policy() const { return data_.created_by_policy; }
diff --git a/chromium/components/search_engines/template_url_data.cc b/chromium/components/search_engines/template_url_data.cc
index f415c7719fc..187d0a277c6 100644
--- a/chromium/components/search_engines/template_url_data.cc
+++ b/chromium/components/search_engines/template_url_data.cc
@@ -9,23 +9,71 @@
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
TemplateURLData::TemplateURLData()
- : show_in_default_list(false),
- safe_for_autoreplace(false),
+ : safe_for_autoreplace(false),
id(0),
date_created(base::Time::Now()),
last_modified(base::Time::Now()),
+ last_visited(base::Time()),
created_by_policy(false),
usage_count(0),
prepopulate_id(0),
sync_guid(base::GenerateGUID()),
keyword_(base::ASCIIToUTF16("dummy")),
- url_("x") {
-}
+ url_("x") {}
TemplateURLData::TemplateURLData(const TemplateURLData& other) = default;
+TemplateURLData::TemplateURLData(const base::string16& name,
+ const base::string16& keyword,
+ base::StringPiece search_url,
+ base::StringPiece suggest_url,
+ base::StringPiece instant_url,
+ base::StringPiece image_url,
+ base::StringPiece new_tab_url,
+ base::StringPiece contextual_search_url,
+ base::StringPiece search_url_post_params,
+ base::StringPiece suggest_url_post_params,
+ base::StringPiece instant_url_post_params,
+ base::StringPiece image_url_post_params,
+ base::StringPiece favicon_url,
+ base::StringPiece encoding,
+ const base::ListValue& alternate_urls_list,
+ base::StringPiece search_terms_replacement_key,
+ int prepopulate_id)
+ : suggestions_url(suggest_url.as_string()),
+ instant_url(instant_url.as_string()),
+ image_url(image_url.as_string()),
+ new_tab_url(new_tab_url.as_string()),
+ contextual_search_url(contextual_search_url.as_string()),
+ search_url_post_params(search_url_post_params.as_string()),
+ suggestions_url_post_params(suggest_url_post_params.as_string()),
+ instant_url_post_params(instant_url_post_params.as_string()),
+ image_url_post_params(image_url_post_params.as_string()),
+ favicon_url(GURL(favicon_url)),
+ safe_for_autoreplace(true),
+ id(0),
+ date_created(base::Time()),
+ last_modified(base::Time()),
+ created_by_policy(false),
+ usage_count(0),
+ prepopulate_id(prepopulate_id),
+ sync_guid(base::GenerateGUID()),
+ search_terms_replacement_key(search_terms_replacement_key.as_string()) {
+ SetShortName(name);
+ SetKeyword(keyword);
+ SetURL(search_url.as_string());
+ input_encodings.push_back(encoding.as_string());
+ for (size_t i = 0; i < alternate_urls_list.GetSize(); ++i) {
+ std::string alternate_url;
+ alternate_urls_list.GetString(i, &alternate_url);
+ DCHECK(!alternate_url.empty());
+ alternate_urls.push_back(alternate_url);
+ }
+}
+
TemplateURLData::~TemplateURLData() {
}
diff --git a/chromium/components/search_engines/template_url_data.h b/chromium/components/search_engines/template_url_data.h
index 11943b0ce67..93088a8dbdf 100644
--- a/chromium/components/search_engines/template_url_data.h
+++ b/chromium/components/search_engines/template_url_data.h
@@ -13,12 +13,40 @@
#include "components/search_engines/template_url_id.h"
#include "url/gurl.h"
+namespace base {
+class ListValue;
+}
+
// The data for the TemplateURL. Separating this into its own class allows most
// users to do SSA-style usage of TemplateURL: construct a TemplateURLData with
// whatever fields are desired, then create an immutable TemplateURL from it.
struct TemplateURLData {
TemplateURLData();
TemplateURLData(const TemplateURLData& other);
+ // Creates a TemplateURLData suitable for prepopulated engines.
+ // Note that unlike in the default constructor, |safe_for_autoreplace| will
+ // be set to true. date_created and last_modified will be set to null time
+ // value, instead of current time.
+ // StringPiece in arguments is used to pass const char* pointer members
+ // of PrepopulatedEngine structure which can be nullptr.
+ TemplateURLData(const base::string16& name,
+ const base::string16& keyword,
+ base::StringPiece search_url,
+ base::StringPiece suggest_url,
+ base::StringPiece instant_url,
+ base::StringPiece image_url,
+ base::StringPiece new_tab_url,
+ base::StringPiece contextual_search_url,
+ base::StringPiece search_url_post_params,
+ base::StringPiece suggest_url_post_params,
+ base::StringPiece instant_url_post_params,
+ base::StringPiece image_url_post_params,
+ base::StringPiece favicon_url,
+ base::StringPiece encoding,
+ const base::ListValue& alternate_urls_list,
+ base::StringPiece search_terms_replacement_key,
+ int prepopulate_id);
+
~TemplateURLData();
// A short description of the template. This is the name we show to the user
@@ -56,12 +84,6 @@ struct TemplateURLData {
// URL to the OSD file this came from. May be empty.
GURL originating_url;
- // Whether this TemplateURL is shown in the default list of search providers.
- // This is just a property and does not indicate whether the TemplateURL has a
- // TemplateURLRef that supports replacement. Use
- // TemplateURL::ShowInDefaultList() to test both.
- bool show_in_default_list;
-
// Whether it's safe for auto-modification code (the autogenerator and the
// code that imports data from other browsers) to replace the TemplateURL.
// This should be set to false for any TemplateURL the user edits, or any
@@ -88,6 +110,11 @@ struct TemplateURLData {
// NOTE: Like date_created above, this may be 0.
base::Time last_modified;
+ // Date when this TemplateURL was last visited.
+ //
+ // NOTE: This might be 0 if the TemplateURL has never been visited.
+ base::Time last_visited;
+
// True if this TemplateURL was automatically created by the administrator via
// group policy.
bool created_by_policy;
diff --git a/chromium/components/search_engines/template_url_data_util.cc b/chromium/components/search_engines/template_url_data_util.cc
new file mode 100644
index 00000000000..ab76c92ab57
--- /dev/null
+++ b/chromium/components/search_engines/template_url_data_util.cc
@@ -0,0 +1,244 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/search_engines/template_url_data_util.h"
+
+#include <string>
+
+#include "base/memory/ptr_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "components/search_engines/default_search_manager.h"
+#include "components/search_engines/prepopulated_engines.h"
+#include "components/search_engines/template_url_data.h"
+#include "url/gurl.h"
+
+std::unique_ptr<TemplateURLData> TemplateURLDataFromDictionary(
+ const base::DictionaryValue& dict) {
+ std::string search_url;
+ base::string16 keyword;
+ base::string16 short_name;
+ dict.GetString(DefaultSearchManager::kURL, &search_url);
+ dict.GetString(DefaultSearchManager::kKeyword, &keyword);
+ dict.GetString(DefaultSearchManager::kShortName, &short_name);
+ // Check required TemplateURLData fields first.
+ if (search_url.empty() || keyword.empty() || short_name.empty())
+ return std::unique_ptr<TemplateURLData>();
+
+ auto result = base::MakeUnique<TemplateURLData>();
+ result->SetKeyword(keyword);
+ result->SetURL(search_url);
+
+ std::string id;
+ dict.GetString(DefaultSearchManager::kID, &id);
+ base::StringToInt64(id, &result->id);
+
+ result->SetShortName(short_name);
+ dict.GetInteger(DefaultSearchManager::kPrepopulateID,
+ &result->prepopulate_id);
+ dict.GetString(DefaultSearchManager::kSyncGUID, &result->sync_guid);
+ dict.GetString(DefaultSearchManager::kSuggestionsURL,
+ &result->suggestions_url);
+
+ dict.GetString(DefaultSearchManager::kInstantURL, &result->instant_url);
+ dict.GetString(DefaultSearchManager::kImageURL, &result->image_url);
+ dict.GetString(DefaultSearchManager::kNewTabURL, &result->new_tab_url);
+ dict.GetString(DefaultSearchManager::kContextualSearchURL,
+ &result->contextual_search_url);
+ std::string favicon_url;
+ std::string originating_url;
+ dict.GetString(DefaultSearchManager::kFaviconURL, &favicon_url);
+ dict.GetString(DefaultSearchManager::kOriginatingURL, &originating_url);
+ result->favicon_url = GURL(favicon_url);
+ result->originating_url = GURL(originating_url);
+
+ dict.GetString(DefaultSearchManager::kSearchURLPostParams,
+ &result->search_url_post_params);
+ dict.GetString(DefaultSearchManager::kSuggestionsURLPostParams,
+ &result->suggestions_url_post_params);
+ dict.GetString(DefaultSearchManager::kInstantURLPostParams,
+ &result->instant_url_post_params);
+ dict.GetString(DefaultSearchManager::kImageURLPostParams,
+ &result->image_url_post_params);
+ dict.GetBoolean(DefaultSearchManager::kSafeForAutoReplace,
+ &result->safe_for_autoreplace);
+
+ std::string date_created_str;
+ std::string last_modified_str;
+ std::string last_visited_str;
+ dict.GetString(DefaultSearchManager::kDateCreated, &date_created_str);
+ dict.GetString(DefaultSearchManager::kLastModified, &last_modified_str);
+ dict.GetString(DefaultSearchManager::kLastVisited, &last_visited_str);
+
+ int64_t date_created = 0;
+ if (base::StringToInt64(date_created_str, &date_created))
+ result->date_created = base::Time::FromInternalValue(date_created);
+
+ int64_t last_modified = 0;
+ if (base::StringToInt64(last_modified_str, &last_modified))
+ result->last_modified = base::Time::FromInternalValue(last_modified);
+
+ int64_t last_visited = 0;
+ if (base::StringToInt64(last_visited_str, &last_visited))
+ result->last_visited = base::Time::FromInternalValue(last_visited);
+
+ dict.GetInteger(DefaultSearchManager::kUsageCount, &result->usage_count);
+
+ const base::ListValue* alternate_urls = nullptr;
+ if (dict.GetList(DefaultSearchManager::kAlternateURLs, &alternate_urls)) {
+ for (const auto& it : *alternate_urls) {
+ std::string alternate_url;
+ if (it->GetAsString(&alternate_url))
+ result->alternate_urls.push_back(std::move(alternate_url));
+ }
+ }
+
+ const base::ListValue* encodings = nullptr;
+ if (dict.GetList(DefaultSearchManager::kInputEncodings, &encodings)) {
+ for (const auto& it : *encodings) {
+ std::string encoding;
+ if (it->GetAsString(&encoding))
+ result->input_encodings.push_back(std::move(encoding));
+ }
+ }
+
+ dict.GetString(DefaultSearchManager::kSearchTermsReplacementKey,
+ &result->search_terms_replacement_key);
+ dict.GetBoolean(DefaultSearchManager::kCreatedByPolicy,
+ &result->created_by_policy);
+ return result;
+}
+
+std::unique_ptr<base::DictionaryValue> TemplateURLDataToDictionary(
+ const TemplateURLData& data) {
+ auto url_dict = base::MakeUnique<base::DictionaryValue>();
+ url_dict->SetString(DefaultSearchManager::kID, base::Int64ToString(data.id));
+ url_dict->SetString(DefaultSearchManager::kShortName, data.short_name());
+ url_dict->SetString(DefaultSearchManager::kKeyword, data.keyword());
+ url_dict->SetInteger(DefaultSearchManager::kPrepopulateID,
+ data.prepopulate_id);
+ url_dict->SetString(DefaultSearchManager::kSyncGUID, data.sync_guid);
+
+ url_dict->SetString(DefaultSearchManager::kURL, data.url());
+ url_dict->SetString(DefaultSearchManager::kSuggestionsURL,
+ data.suggestions_url);
+ url_dict->SetString(DefaultSearchManager::kInstantURL, data.instant_url);
+ url_dict->SetString(DefaultSearchManager::kImageURL, data.image_url);
+ url_dict->SetString(DefaultSearchManager::kNewTabURL, data.new_tab_url);
+ url_dict->SetString(DefaultSearchManager::kContextualSearchURL,
+ data.contextual_search_url);
+ url_dict->SetString(DefaultSearchManager::kFaviconURL,
+ data.favicon_url.spec());
+ url_dict->SetString(DefaultSearchManager::kOriginatingURL,
+ data.originating_url.spec());
+
+ url_dict->SetString(DefaultSearchManager::kSearchURLPostParams,
+ data.search_url_post_params);
+ url_dict->SetString(DefaultSearchManager::kSuggestionsURLPostParams,
+ data.suggestions_url_post_params);
+ url_dict->SetString(DefaultSearchManager::kInstantURLPostParams,
+ data.instant_url_post_params);
+ url_dict->SetString(DefaultSearchManager::kImageURLPostParams,
+ data.image_url_post_params);
+
+ url_dict->SetBoolean(DefaultSearchManager::kSafeForAutoReplace,
+ data.safe_for_autoreplace);
+
+ url_dict->SetString(DefaultSearchManager::kDateCreated,
+ base::Int64ToString(data.date_created.ToInternalValue()));
+ url_dict->SetString(
+ DefaultSearchManager::kLastModified,
+ base::Int64ToString(data.last_modified.ToInternalValue()));
+ url_dict->SetString(
+ DefaultSearchManager::kLastVisited,
+ base::Int64ToString(data.last_visited.ToInternalValue()));
+ url_dict->SetInteger(DefaultSearchManager::kUsageCount, data.usage_count);
+
+ auto alternate_urls = base::MakeUnique<base::ListValue>();
+ for (const auto& alternate_url : data.alternate_urls)
+ alternate_urls->AppendString(alternate_url);
+
+ url_dict->Set(DefaultSearchManager::kAlternateURLs,
+ std::move(alternate_urls));
+
+ auto encodings = base::MakeUnique<base::ListValue>();
+ for (const auto& input_encoding : data.input_encodings)
+ encodings->AppendString(input_encoding);
+ url_dict->Set(DefaultSearchManager::kInputEncodings, std::move(encodings));
+
+ url_dict->SetString(DefaultSearchManager::kSearchTermsReplacementKey,
+ data.search_terms_replacement_key);
+ url_dict->SetBoolean(DefaultSearchManager::kCreatedByPolicy,
+ data.created_by_policy);
+ return url_dict;
+}
+
+std::unique_ptr<TemplateURLData> TemplateURLDataFromPrepopulatedEngine(
+ const TemplateURLPrepopulateData::PrepopulatedEngine& engine) {
+ base::ListValue alternate_urls;
+ if (engine.alternate_urls) {
+ for (size_t i = 0; i < engine.alternate_urls_size; ++i)
+ alternate_urls.AppendString(std::string(engine.alternate_urls[i]));
+ }
+
+ return base::MakeUnique<TemplateURLData>(
+ base::WideToUTF16(engine.name), base::WideToUTF16(engine.keyword),
+ engine.search_url, engine.suggest_url, engine.instant_url,
+ engine.image_url, engine.new_tab_url, engine.contextual_search_url,
+ engine.search_url_post_params, engine.suggest_url_post_params,
+ engine.instant_url_post_params, engine.image_url_post_params,
+ engine.favicon_url, engine.encoding, alternate_urls,
+ engine.search_terms_replacement_key, engine.id);
+}
+
+std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary(
+ const base::DictionaryValue& engine) {
+ base::string16 name;
+ base::string16 keyword;
+ std::string search_url;
+ std::string favicon_url;
+ std::string encoding;
+ int id = -1;
+ // The following fields are required for each search engine configuration.
+ if (engine.GetString("name", &name) && !name.empty() &&
+ engine.GetString("keyword", &keyword) && !keyword.empty() &&
+ engine.GetString("search_url", &search_url) && !search_url.empty() &&
+ engine.GetString("favicon_url", &favicon_url) && !favicon_url.empty() &&
+ engine.GetString("encoding", &encoding) && !encoding.empty() &&
+ engine.GetInteger("id", &id)) {
+ // These fields are optional.
+ std::string suggest_url;
+ std::string instant_url;
+ std::string image_url;
+ std::string new_tab_url;
+ std::string contextual_search_url;
+ std::string search_url_post_params;
+ std::string suggest_url_post_params;
+ std::string instant_url_post_params;
+ std::string image_url_post_params;
+ base::ListValue empty_list;
+ const base::ListValue* alternate_urls = &empty_list;
+ std::string search_terms_replacement_key;
+ engine.GetString("suggest_url", &suggest_url);
+ engine.GetString("instant_url", &instant_url);
+ engine.GetString("image_url", &image_url);
+ engine.GetString("new_tab_url", &new_tab_url);
+ engine.GetString("contextual_search_url", &contextual_search_url);
+ engine.GetString("search_url_post_params", &search_url_post_params);
+ engine.GetString("suggest_url_post_params", &suggest_url_post_params);
+ engine.GetString("instant_url_post_params", &instant_url_post_params);
+ engine.GetString("image_url_post_params", &image_url_post_params);
+ engine.GetList("alternate_urls", &alternate_urls);
+ engine.GetString("search_terms_replacement_key",
+ &search_terms_replacement_key);
+ return base::MakeUnique<TemplateURLData>(
+ name, keyword, search_url, suggest_url, instant_url, image_url,
+ new_tab_url, contextual_search_url, search_url_post_params,
+ suggest_url_post_params, instant_url_post_params, image_url_post_params,
+ favicon_url, encoding, *alternate_urls, search_terms_replacement_key,
+ id);
+ }
+ return std::unique_ptr<TemplateURLData>();
+}
diff --git a/chromium/components/search_engines/template_url_data_util.h b/chromium/components/search_engines/template_url_data_util.h
new file mode 100644
index 00000000000..f99ae052cd9
--- /dev/null
+++ b/chromium/components/search_engines/template_url_data_util.h
@@ -0,0 +1,39 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_UTIL_H_
+#define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_UTIL_H_
+
+#include <memory>
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace TemplateURLPrepopulateData {
+struct PrepopulatedEngine;
+}
+
+struct TemplateURLData;
+
+// Deserializes a TemplateURLData from |dict|.
+std::unique_ptr<TemplateURLData> TemplateURLDataFromDictionary(
+ const base::DictionaryValue& dict);
+
+// Serializes a TemplateURLData to |dict|.
+std::unique_ptr<base::DictionaryValue> TemplateURLDataToDictionary(
+ const TemplateURLData& turl_data);
+
+// Create TemplateURLData structure from PrepopulatedEngine structure.
+std::unique_ptr<TemplateURLData> TemplateURLDataFromPrepopulatedEngine(
+ const TemplateURLPrepopulateData::PrepopulatedEngine& engine);
+
+// Deserializes a TemplateURLData from |dict| as stored in
+// kSearchProviderOverrides pref. The field names in |dict| differ from those
+// used in the To/FromDictionary functions above for historical reasons.
+// TODO(a-v-y) Migrate to single TemplateURLData serialization format.
+std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary(
+ const base::DictionaryValue& engine);
+
+#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_UTIL_H_
diff --git a/chromium/components/search_engines/template_url_fetcher.cc b/chromium/components/search_engines/template_url_fetcher.cc
index 6274531e2c5..cf972d0eeb9 100644
--- a/chromium/components/search_engines/template_url_fetcher.cc
+++ b/chromium/components/search_engines/template_url_fetcher.cc
@@ -112,7 +112,7 @@ void TemplateURLFetcher::RequestDelegate::OnURLFetchComplete(
}
template_url_ = TemplateURLParser::Parse(
- fetcher_->template_url_service_->search_terms_data(), false, data.data(),
+ fetcher_->template_url_service_->search_terms_data(), data.data(),
data.length(), nullptr);
if (!template_url_.get() ||
!template_url_->url_ref().SupportsReplacement(
diff --git a/chromium/components/search_engines/template_url_parser.cc b/chromium/components/search_engines/template_url_parser.cc
index e3eec92f67d..9d051056be5 100644
--- a/chromium/components/search_engines/template_url_parser.cc
+++ b/chromium/components/search_engines/template_url_parser.cc
@@ -146,8 +146,7 @@ class TemplateURLParsingContext {
// the resulting URL was not HTTP[S], a name wasn't supplied, a resulting
// TemplateURLRef was invalid, etc.).
std::unique_ptr<TemplateURL> GetTemplateURL(
- const SearchTermsData& search_terms_data,
- bool show_in_default_list);
+ const SearchTermsData& search_terms_data);
private:
// Key is UTF8 encoded.
@@ -302,8 +301,7 @@ void TemplateURLParsingContext::CharactersImpl(void* ctx,
}
std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL(
- const SearchTermsData& search_terms_data,
- bool show_in_default_list) {
+ const SearchTermsData& search_terms_data) {
// TODO(jcampan): Support engines that use POST; see http://crbug.com/18107
if (method_ == TemplateURLParsingContext::POST ||
data_.short_name().empty() || !IsHTTPRef(data_.url()) ||
@@ -323,8 +321,6 @@ std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL(
if (!has_custom_keyword_)
data_.SetKeyword(TemplateURL::GenerateKeyword(search_url));
- data_.show_in_default_list = show_in_default_list;
-
// Bail if the search URL is empty or if either TemplateURLRef is invalid.
std::unique_ptr<TemplateURL> template_url =
base::MakeUnique<TemplateURL>(data_);
@@ -495,7 +491,6 @@ TemplateURLParsingContext::ElementType
// static
std::unique_ptr<TemplateURL> TemplateURLParser::Parse(
const SearchTermsData& search_terms_data,
- bool show_in_default_list,
const char* data,
size_t length,
TemplateURLParser::ParameterFilter* param_filter) {
@@ -514,6 +509,5 @@ std::unique_ptr<TemplateURL> TemplateURLParser::Parse(
static_cast<int>(length));
xmlSubstituteEntitiesDefault(last_sub_entities_value);
- return error ? nullptr : context.GetTemplateURL(search_terms_data,
- show_in_default_list);
+ return error ? nullptr : context.GetTemplateURL(search_terms_data);
}
diff --git a/chromium/components/search_engines/template_url_parser.h b/chromium/components/search_engines/template_url_parser.h
index a878cc95dd3..c381f7a02cd 100644
--- a/chromium/components/search_engines/template_url_parser.h
+++ b/chromium/components/search_engines/template_url_parser.h
@@ -40,7 +40,6 @@ class TemplateURLParser {
// the URL is not modified.
static std::unique_ptr<TemplateURL> Parse(
const SearchTermsData& search_terms_data,
- bool show_in_default_list,
const char* data,
size_t length,
ParameterFilter* parameter_filter);
diff --git a/chromium/components/search_engines/template_url_prepopulate_data.cc b/chromium/components/search_engines/template_url_prepopulate_data.cc
index 72574064b75..40604f5f8a4 100644
--- a/chromium/components/search_engines/template_url_prepopulate_data.cc
+++ b/chromium/components/search_engines/template_url_prepopulate_data.cc
@@ -21,6 +21,7 @@
#include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/template_url_data.h"
+#include "components/search_engines/template_url_data_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
@@ -536,12 +537,16 @@ int CountryCharsToCountryIDWithUpdate(char c1, char c2) {
return CountryCharsToCountryID(c1, c2);
}
+#if !defined(OS_WIN) && !defined(OS_MACOSX)
+
int CountryStringToCountryID(const std::string& country) {
return (country.length() == 2)
? CountryCharsToCountryIDWithUpdate(country[0], country[1])
: kCountryIDUnknown;
}
+#endif
+
#if defined(OS_WIN)
// For reference, a list of GeoIDs can be found at
@@ -972,59 +977,10 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
std::vector<std::unique_ptr<TemplateURLData>> t_urls;
for (size_t i = 0; i < num_engines; ++i)
- t_urls.push_back(MakeTemplateURLDataFromPrepopulatedEngine(*engines[i]));
+ t_urls.push_back(TemplateURLDataFromPrepopulatedEngine(*engines[i]));
return t_urls;
}
-std::unique_ptr<TemplateURLData> MakePrepopulatedTemplateURLData(
- const base::string16& name,
- const base::string16& keyword,
- const base::StringPiece& search_url,
- const base::StringPiece& suggest_url,
- const base::StringPiece& instant_url,
- const base::StringPiece& image_url,
- const base::StringPiece& new_tab_url,
- const base::StringPiece& contextual_search_url,
- const base::StringPiece& search_url_post_params,
- const base::StringPiece& suggest_url_post_params,
- const base::StringPiece& instant_url_post_params,
- const base::StringPiece& image_url_post_params,
- const base::StringPiece& favicon_url,
- const base::StringPiece& encoding,
- const base::ListValue& alternate_urls,
- const base::StringPiece& search_terms_replacement_key,
- int id) {
- std::unique_ptr<TemplateURLData> data(new TemplateURLData);
-
- data->SetShortName(name);
- data->SetKeyword(keyword);
- data->SetURL(search_url.as_string());
- data->suggestions_url = suggest_url.as_string();
- data->instant_url = instant_url.as_string();
- data->image_url = image_url.as_string();
- data->new_tab_url = new_tab_url.as_string();
- data->contextual_search_url = contextual_search_url.as_string();
- data->search_url_post_params = search_url_post_params.as_string();
- data->suggestions_url_post_params = suggest_url_post_params.as_string();
- data->instant_url_post_params = instant_url_post_params.as_string();
- data->image_url_post_params = image_url_post_params.as_string();
- data->favicon_url = GURL(favicon_url);
- data->show_in_default_list = true;
- data->safe_for_autoreplace = true;
- data->input_encodings.push_back(encoding.as_string());
- data->date_created = base::Time();
- data->last_modified = base::Time();
- data->prepopulate_id = id;
- for (size_t i = 0; i < alternate_urls.GetSize(); ++i) {
- std::string alternate_url;
- alternate_urls.GetString(i, &alternate_url);
- DCHECK(!alternate_url.empty());
- data->alternate_urls.push_back(alternate_url);
- }
- data->search_terms_replacement_key = search_terms_replacement_key.as_string();
- return data;
-}
-
std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
PrefService* prefs) {
std::vector<std::unique_ptr<TemplateURLData>> t_urls;
@@ -1038,52 +994,10 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedTemplateURLData(
size_t num_engines = list->GetSize();
for (size_t i = 0; i != num_engines; ++i) {
const base::DictionaryValue* engine;
- base::string16 name;
- base::string16 keyword;
- std::string search_url;
- std::string favicon_url;
- std::string encoding;
- int id = -1;
- // The following fields are required for each search engine configuration.
- if (list->GetDictionary(i, &engine) &&
- engine->GetString("name", &name) && !name.empty() &&
- engine->GetString("keyword", &keyword) && !keyword.empty() &&
- engine->GetString("search_url", &search_url) && !search_url.empty() &&
- engine->GetString("favicon_url", &favicon_url) &&
- !favicon_url.empty() &&
- engine->GetString("encoding", &encoding) && !encoding.empty() &&
- engine->GetInteger("id", &id)) {
- // These fields are optional.
- std::string suggest_url;
- std::string instant_url;
- std::string image_url;
- std::string new_tab_url;
- std::string contextual_search_url;
- std::string search_url_post_params;
- std::string suggest_url_post_params;
- std::string instant_url_post_params;
- std::string image_url_post_params;
- base::ListValue empty_list;
- const base::ListValue* alternate_urls = &empty_list;
- std::string search_terms_replacement_key;
- engine->GetString("suggest_url", &suggest_url);
- engine->GetString("instant_url", &instant_url);
- engine->GetString("image_url", &image_url);
- engine->GetString("new_tab_url", &new_tab_url);
- engine->GetString("contextual_search_url", &contextual_search_url);
- engine->GetString("search_url_post_params", &search_url_post_params);
- engine->GetString("suggest_url_post_params", &suggest_url_post_params);
- engine->GetString("instant_url_post_params", &instant_url_post_params);
- engine->GetString("image_url_post_params", &image_url_post_params);
- engine->GetList("alternate_urls", &alternate_urls);
- engine->GetString("search_terms_replacement_key",
- &search_terms_replacement_key);
- t_urls.push_back(MakePrepopulatedTemplateURLData(
- name, keyword, search_url, suggest_url, instant_url, image_url,
- new_tab_url, contextual_search_url, search_url_post_params,
- suggest_url_post_params, instant_url_post_params,
- image_url_post_params, favicon_url, encoding, *alternate_urls,
- search_terms_replacement_key, id));
+ if (list->GetDictionary(i, &engine)) {
+ auto t_url = TemplateURLDataFromOverrideDictionary(*engine);
+ if (t_url)
+ t_urls.push_back(std::move(t_url));
}
}
return t_urls;
@@ -1118,7 +1032,8 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
size_t* default_search_provider_index) {
// If there is a set of search engines in the preferences file, it overrides
// the built-in set.
- *default_search_provider_index = 0;
+ if (default_search_provider_index)
+ *default_search_provider_index = 0;
std::vector<std::unique_ptr<TemplateURLData>> t_urls =
GetPrepopulatedTemplateURLData(prefs);
if (!t_urls.empty())
@@ -1128,6 +1043,7 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
}
#if defined(OS_ANDROID)
+
std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
const std::string& locale,
PrefService* prefs) {
@@ -1139,6 +1055,7 @@ std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
return GetPrepopulationSetFromCountryID(country_id);
}
+
#endif
std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
@@ -1146,24 +1063,6 @@ std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines() {
std::end(kAllEngines));
}
-std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine(
- const PrepopulatedEngine& engine) {
- base::ListValue alternate_urls;
- if (engine.alternate_urls) {
- for (size_t i = 0; i < engine.alternate_urls_size; ++i)
- alternate_urls.AppendString(std::string(engine.alternate_urls[i]));
- }
-
- return MakePrepopulatedTemplateURLData(
- base::WideToUTF16(engine.name), base::WideToUTF16(engine.keyword),
- engine.search_url, engine.suggest_url, engine.instant_url,
- engine.image_url, engine.new_tab_url, engine.contextual_search_url,
- engine.search_url_post_params, engine.suggest_url_post_params,
- engine.instant_url_post_params, engine.image_url_post_params,
- engine.favicon_url, engine.encoding, alternate_urls,
- engine.search_terms_replacement_key, engine.id);
-}
-
void ClearPrepopulatedEnginesInPrefs(PrefService* prefs) {
if (!prefs)
return;
diff --git a/chromium/components/search_engines/template_url_prepopulate_data.h b/chromium/components/search_engines/template_url_prepopulate_data.h
index 4a218f73f1f..17c81cd9ff4 100644
--- a/chromium/components/search_engines/template_url_prepopulate_data.h
+++ b/chromium/components/search_engines/template_url_prepopulate_data.h
@@ -36,8 +36,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
int GetDataVersion(PrefService* prefs);
// Returns the prepopulated URLs for the current country.
-// |default_search_provider_index| is set to the index of the default search
-// provider within the returned vector.
+// If |default_search_provider_index| is non-null, it is set to the index of the
+// default search provider within the returned vector.
std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulatedEngines(
PrefService* prefs,
size_t* default_search_provider_index);
@@ -55,10 +55,6 @@ std::vector<std::unique_ptr<TemplateURLData>> GetLocalPrepopulatedEngines(
// Returns all prepopulated engines for all locales. Used only by tests.
std::vector<const PrepopulatedEngine*> GetAllPrepopulatedEngines();
-// Returns a TemplateURLData for the specified prepopulated engine.
-std::unique_ptr<TemplateURLData> MakeTemplateURLDataFromPrepopulatedEngine(
- const PrepopulatedEngine& engine);
-
// Removes prepopulated engines and their version stored in user prefs.
void ClearPrepopulatedEnginesInPrefs(PrefService* prefs);
diff --git a/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc b/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc
index e57a940cf89..de612204469 100644
--- a/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc
+++ b/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc
@@ -14,12 +14,13 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "components/google/core/browser/google_switches.h"
-#include "components/pref_registry/testing_pref_service_syncable.h"
#include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_data_util.h"
#include "components/search_engines/template_url_service.h"
+#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
@@ -45,7 +46,7 @@ class TemplateURLPrepopulateDataTest : public testing::Test {
}
protected:
- user_prefs::TestingPrefServiceSyncable prefs_;
+ sync_preferences::TestingPrefServiceSyncable prefs_;
};
// Verifies the set of prepopulate data doesn't contain entries with duplicate
@@ -104,10 +105,8 @@ TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) {
for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
prefs_.SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]);
- size_t default_index;
std::vector<std::unique_ptr<TemplateURLData>> urls =
- TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
- &default_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, nullptr);
std::set<int> unique_ids;
for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id) ==
@@ -153,6 +152,9 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
EXPECT_TRUE(t_urls[0]->instant_url.empty());
EXPECT_EQ(0u, t_urls[0]->alternate_urls.size());
EXPECT_TRUE(t_urls[0]->search_terms_replacement_key.empty());
+ EXPECT_TRUE(t_urls[0]->safe_for_autoreplace);
+ EXPECT_TRUE(t_urls[0]->date_created.is_null());
+ EXPECT_TRUE(t_urls[0]->last_modified.is_null());
// Test the optional settings too.
entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}");
@@ -272,6 +274,9 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
ASSERT_FALSE(GetHostFromTemplateURLData(*t_urls[i]).empty());
ASSERT_FALSE(t_urls[i]->input_encodings.empty());
EXPECT_GT(t_urls[i]->prepopulate_id, 0);
+ EXPECT_TRUE(t_urls[0]->safe_for_autoreplace);
+ EXPECT_TRUE(t_urls[0]->date_created.is_null());
+ EXPECT_TRUE(t_urls[0]->last_modified.is_null());
}
// Ensures the default URL is Google and has the optional fields filled.
@@ -357,8 +362,7 @@ TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) {
TemplateURLPrepopulateData::GetAllPrepopulatedEngines();
for (const PrepopulatedEngine* engine : all_engines) {
std::unique_ptr<TemplateURLData> data =
- TemplateURLPrepopulateData::MakeTemplateURLDataFromPrepopulatedEngine(
- *engine);
+ TemplateURLDataFromPrepopulatedEngine(*engine);
EXPECT_EQ(engine->type,
TemplateURL(*data).GetEngineType(SearchTermsData()));
}
diff --git a/chromium/components/search_engines/template_url_service.cc b/chromium/components/search_engines/template_url_service.cc
index e3bc412c2b4..0e77d27379f 100644
--- a/chromium/components/search_engines/template_url_service.cc
+++ b/chromium/components/search_engines/template_url_service.cc
@@ -24,7 +24,7 @@
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
-#include "components/rappor/rappor_service.h"
+#include "components/rappor/rappor_service_impl.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/search_host_to_urls_map.h"
#include "components/search_engines/search_terms_data.h"
@@ -230,7 +230,7 @@ TemplateURLService::TemplateURLService(
const scoped_refptr<KeywordWebDataService>& web_data_service,
std::unique_ptr<TemplateURLServiceClient> client,
GoogleURLTracker* google_url_tracker,
- rappor::RapporService* rappor_service,
+ rappor::RapporServiceImpl* rappor_service,
const base::Closure& dsp_change_callback)
: prefs_(prefs),
search_terms_data_(std::move(search_terms_data)),
@@ -300,38 +300,6 @@ void TemplateURLService::RegisterProfilePrefs(
std::string(),
flags);
registry->RegisterBooleanPref(prefs::kDefaultSearchProviderEnabled, true);
- registry->RegisterStringPref(prefs::kDefaultSearchProviderName,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderID, std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderPrepopulateID,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderSuggestURL,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderSearchURL,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderInstantURL,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderImageURL,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderNewTabURL,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderSearchURLPostParams,
- std::string());
- registry->RegisterStringPref(
- prefs::kDefaultSearchProviderSuggestURLPostParams, std::string());
- registry->RegisterStringPref(
- prefs::kDefaultSearchProviderInstantURLPostParams, std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderImageURLPostParams,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderKeyword,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderIconURL,
- std::string());
- registry->RegisterStringPref(prefs::kDefaultSearchProviderEncodings,
- std::string());
- registry->RegisterListPref(prefs::kDefaultSearchProviderAlternateURLs);
- registry->RegisterStringPref(
- prefs::kDefaultSearchProviderSearchTermsReplacementKey, std::string());
}
// static
@@ -395,6 +363,17 @@ bool TemplateURLService::CanAddAutogeneratedKeyword(
CanAddAutogeneratedKeywordForHost(url.host());
}
+bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy(
+ const TemplateURL* t_url) {
+ return (t_url->prepopulate_id() > 0 || t_url->created_by_policy()) &&
+ t_url->SupportsReplacement(search_terms_data());
+}
+
+bool TemplateURLService::ShowInDefaultList(const TemplateURL* t_url) {
+ return t_url == default_search_provider_ ||
+ IsPrepopulatedOrCreatedByPolicy(t_url);
+}
+
void TemplateURLService::AddMatchingKeywords(
const base::string16& prefix,
bool supports_replacement_only,
@@ -478,8 +457,6 @@ TemplateURL* TemplateURLService::AddExtensionControlledTURL(
DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
DCHECK(info);
DCHECK_NE(TemplateURL::NORMAL, template_url->type());
- DCHECK_EQ(info->wants_to_be_default_engine,
- template_url->show_in_default_list());
DCHECK(
!FindTemplateURLForExtension(info->extension_id, template_url->type()));
template_url->extension_info_.swap(info);
@@ -670,10 +647,8 @@ void TemplateURLService::RepairPrepopulatedSearchEngines() {
default_search_provider_ = nullptr;
}
- size_t default_search_provider_index = 0;
std::vector<std::unique_ptr<TemplateURLData>> prepopulated_urls =
- TemplateURLPrepopulateData::GetPrepopulatedEngines(
- prefs_, &default_search_provider_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs_, nullptr);
DCHECK(!prepopulated_urls.empty());
ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData(
&prepopulated_urls, template_urls_, default_search_provider_));
@@ -855,9 +830,8 @@ void TemplateURLService::OnWebDataServiceRequestDone(
SEARCH_ENGINE_MAX);
if (rappor_service_) {
- rappor_service_->RecordSample(
- "Search.DefaultSearchProvider",
- rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
+ rappor_service_->RecordSampleString(
+ "Search.DefaultSearchProvider", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
net::registry_controlled_domains::GetDomainAndRegistry(
default_search_provider_->url_ref().GetHost(search_terms_data()),
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
@@ -990,8 +964,7 @@ syncer::SyncError TemplateURLService::ProcessSyncChanges(
TemplateURLData data(existing_turl->data());
data.SetKeyword(updated_keyword);
TemplateURL new_turl(data);
- if (UpdateNoNotify(existing_turl, new_turl))
- NotifyObservers();
+ Update(existing_turl, new_turl);
syncer::SyncData sync_data = CreateSyncDataFromTemplateURL(new_turl);
new_changes.push_back(syncer::SyncChange(FROM_HERE,
@@ -1039,10 +1012,8 @@ syncer::SyncError TemplateURLService::ProcessSyncChanges(
ResolveSyncKeywordConflict(turl.get(), existing_keyword_turl,
&new_changes);
}
- if (UpdateNoNotify(existing_turl, *turl)) {
- NotifyObservers();
+ if (Update(existing_turl, *turl))
MaybeUpdateDSEAfterSync(existing_turl);
- }
} else {
// We've unexpectedly received an ACTION_INVALID.
error = sync_error_factory_->CreateAndUploadError(
@@ -1139,8 +1110,7 @@ syncer::SyncMergeResult TemplateURLService::MergeDataAndStartSyncing(
// TemplateURLID and the TemplateURL may have to be reparsed. This
// also makes the local data's last_modified timestamp equal to Sync's,
// avoiding an Update on the next MergeData call.
- if (UpdateNoNotify(local_turl, *sync_turl))
- NotifyObservers();
+ Update(local_turl, *sync_turl);
merge_result.set_num_items_modified(
merge_result.num_items_modified() + 1);
} else if (sync_turl->last_modified() < local_turl->last_modified()) {
@@ -1245,7 +1215,6 @@ syncer::SyncData TemplateURLService::CreateSyncDataFromTemplateURL(
se_specifics->set_date_created(turl.date_created().ToInternalValue());
se_specifics->set_input_encodings(
base::JoinString(turl.input_encodings(), ";"));
- se_specifics->set_show_in_default_list(turl.show_in_default_list());
se_specifics->set_suggestions_url(turl.suggestions_url());
se_specifics->set_prepopulate_id(turl.prepopulate_id());
se_specifics->set_instant_url(turl.instant_url());
@@ -1325,7 +1294,6 @@ TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData(
data.instant_url_post_params = specifics.instant_url_post_params();
data.image_url_post_params = specifics.image_url_post_params();
data.favicon_url = GURL(specifics.favicon_url());
- data.show_in_default_list = specifics.show_in_default_list();
data.safe_for_autoreplace = specifics.safe_for_autoreplace();
data.input_encodings = base::SplitString(
specifics.input_encodings(), ";",
@@ -1642,8 +1610,7 @@ bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
}
bool TemplateURLService::CanReplace(const TemplateURL* t_url) {
- return (t_url != default_search_provider_ && !t_url->show_in_default_list() &&
- t_url->safe_for_autoreplace());
+ return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
}
TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
@@ -1736,6 +1703,14 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
return true;
}
+bool TemplateURLService::Update(TemplateURL* existing_turl,
+ const TemplateURL& new_values) {
+ const bool updated = UpdateNoNotify(existing_turl, new_values);
+ if (updated)
+ NotifyObservers();
+ return updated;
+}
+
// static
void TemplateURLService::UpdateTemplateURLIfPrepopulated(
TemplateURL* template_url,
@@ -1744,10 +1719,8 @@ void TemplateURLService::UpdateTemplateURLIfPrepopulated(
if (template_url->prepopulate_id() == 0)
return;
- size_t default_search_index;
std::vector<std::unique_ptr<TemplateURLData>> prepopulated_urls =
- TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs,
- &default_search_index);
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, nullptr);
for (const auto& url : prepopulated_urls) {
if (url->prepopulate_id == prepopulate_id) {
@@ -1776,6 +1749,7 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL(
if (!urls_for_host)
return;
+ TemplateURL* visited_url = nullptr;
for (TemplateURLSet::const_iterator i = urls_for_host->begin();
i != urls_for_host->end(); ++i) {
base::string16 search_terms;
@@ -1792,8 +1766,21 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL(
client_->SetKeywordSearchTermsForURL(
details.url, (*i)->id(), search_terms);
}
+ // Caches the matched TemplateURL so its last_visited could be updated
+ // later after iteration.
+ // Note: UpdateNoNotify() will replace the entry from the container of
+ // this iterator, so update here directly will cause an error about it.
+ visited_url = *i;
}
}
+ if (visited_url)
+ UpdateTemplateURLVisitTime(visited_url);
+}
+
+void TemplateURLService::UpdateTemplateURLVisitTime(TemplateURL* url) {
+ TemplateURLData data(url->data());
+ data.last_visited = clock_->Now();
+ Update(url, TemplateURL(data));
}
void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) {
@@ -1986,7 +1973,6 @@ bool TemplateURLService::ApplyDefaultSearchChangeNoMetrics(
FindPrepopulatedTemplateURL(data->prepopulate_id);
}
TemplateURLData new_data(*data);
- new_data.show_in_default_list = true;
if (default_search_provider_) {
UpdateNoNotify(default_search_provider_, TemplateURL(new_data));
} else {
@@ -2268,8 +2254,7 @@ void TemplateURLService::ResolveSyncKeywordConflict(
// Update |applied_sync_turl| in the local model with the new keyword.
TemplateURLData data(applied_sync_turl->data());
data.SetKeyword(new_keyword);
- if (UpdateNoNotify(applied_sync_turl, TemplateURL(data)))
- NotifyObservers();
+ Update(applied_sync_turl, TemplateURL(data));
}
// The losing TemplateURL should have their keyword updated. Send a change to
// the server to reflect this change.
diff --git a/chromium/components/search_engines/template_url_service.h b/chromium/components/search_engines/template_url_service.h
index da7c5169a0f..a0368a31078 100644
--- a/chromium/components/search_engines/template_url_service.h
+++ b/chromium/components/search_engines/template_url_service.h
@@ -41,7 +41,7 @@ class TemplateURLServiceObserver;
struct TemplateURLData;
namespace rappor {
-class RapporService;
+class RapporServiceImpl;
}
namespace syncer {
@@ -109,7 +109,7 @@ class TemplateURLService : public WebDataServiceConsumer,
const scoped_refptr<KeywordWebDataService>& web_data_service,
std::unique_ptr<TemplateURLServiceClient> client,
GoogleURLTracker* google_url_tracker,
- rappor::RapporService* rappor_service,
+ rappor::RapporServiceImpl* rappor_service,
const base::Closure& dsp_change_callback);
// The following is for testing.
TemplateURLService(const Initializer* initializers, const int count);
@@ -133,6 +133,17 @@ class TemplateURLService : public WebDataServiceConsumer,
const GURL& url,
TemplateURL** template_url_to_replace);
+ // Returns whether the engine is a "pre-existing" engine, either from the
+ // prepopulate list or created by policy.
+ bool IsPrepopulatedOrCreatedByPolicy(const TemplateURL* template_url);
+
+ // Returns whether |template_url| should be shown in the list of engines
+ // most likely to be selected as a default engine. This is meant to highlight
+ // the current default, as well as the other most likely choices of default
+ // engine, separately from a full list of all TemplateURLs (which might be
+ // very long).
+ bool ShowInDefaultList(const TemplateURL* template_url);
+
// Adds to |matches| all TemplateURLs whose keywords begin with |prefix|,
// sorted shortest-keyword-first. If |supports_replacement_only| is true, only
// TemplateURLs that support replacement are returned.
@@ -403,6 +414,7 @@ class TemplateURLService : public WebDataServiceConsumer,
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, ChangeGoogleBaseValue);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, MergeDeletesUnusedProviders);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, AddExtensionKeyword);
+ FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceTest, LastVisitedTimeUpdate);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest, UniquifyKeyword);
FRIEND_TEST_ALL_PREFIXES(TemplateURLServiceSyncTest,
IsLocalTemplateURLBetter);
@@ -414,6 +426,7 @@ class TemplateURLService : public WebDataServiceConsumer,
friend class InstantUnitTestBase;
friend class TemplateURLServiceTestUtil;
+ friend class TemplateUrlServiceAndroid;
using GUIDToTURL = std::map<std::string, TemplateURL*>;
@@ -537,6 +550,10 @@ class TemplateURLService : public WebDataServiceConsumer,
bool UpdateNoNotify(TemplateURL* existing_turl,
const TemplateURL& new_values);
+ // Calls UpdateNoNotify() and NotifyObservers() if update succeeds.
+ // Returns the result of UpdateNoNotify().
+ bool Update(TemplateURL* existing_turl, const TemplateURL& new_values);
+
// If the TemplateURL comes from a prepopulated URL available in the current
// country, update all its fields save for the keyword, short name and id so
// that they match the internal prepopulated URL. TemplateURLs not coming from
@@ -554,6 +571,9 @@ class TemplateURLService : public WebDataServiceConsumer,
// SetKeywordSearchTermsForURL is invoked.
void UpdateKeywordSearchTermsForURL(const URLVisitedDetails& details);
+ // Updates the last_visited time of |url| to the current time.
+ void UpdateTemplateURLVisitTime(TemplateURL* url);
+
// If necessary, generates a visit for the site http:// + t_url.keyword().
void AddTabToSearchVisit(const TemplateURL& t_url);
@@ -710,7 +730,7 @@ class TemplateURLService : public WebDataServiceConsumer,
GoogleURLTracker* google_url_tracker_;
// ---------- Metrics related members ---------------------------------------
- rappor::RapporService* rappor_service_;
+ rappor::RapporServiceImpl* rappor_service_;
// This closure is run when the default search provider is set to Google.
base::Closure dsp_change_callback_;
diff --git a/chromium/components/search_engines/template_url_unittest.cc b/chromium/components/search_engines/template_url_unittest.cc
index de0a54a263f..47630f34892 100644
--- a/chromium/components/search_engines/template_url_unittest.cc
+++ b/chromium/components/search_engines/template_url_unittest.cc
@@ -54,7 +54,6 @@ void TemplateURLTest::ExpectPostParamIs(const TemplateURLRef::PostParam& param,
TEST_F(TemplateURLTest, Defaults) {
TemplateURLData data;
- EXPECT_FALSE(data.show_in_default_list);
EXPECT_FALSE(data.safe_for_autoreplace);
EXPECT_EQ(0, data.prepopulate_id);
}
@@ -1692,34 +1691,29 @@ TEST_F(TemplateURLTest, ContextualSearchParameters) {
search_terms_data_);
EXPECT_EQ("http://bar/_/contextualsearch?", result);
- TemplateURLRef::SearchTermsArgs::ContextualSearchParams params(
- 1, 6, 11, "allen", "woody+allen+movies", "www.wikipedia.org", "utf-8", 1);
+ // Test the current common case, which uses no home country.
+ TemplateURLRef::SearchTermsArgs::ContextualSearchParams params(2, 1,
+ std::string());
search_terms_args.contextual_search_params = params;
result = url.url_ref().ReplaceSearchTerms(search_terms_args,
search_terms_data_);
EXPECT_EQ(
"http://bar/_/contextualsearch?"
- "ctxs=1&"
- "ctxs_start=6&"
- "ctxs_end=11&"
- "q=allen&"
- "ctxs_content=woody+allen+movies&"
- "ctxsl_url=www.wikipedia.org&"
- "ctxs_encoding=utf-8&"
+ "ctxs=2&"
"ctxsl_coca=1",
result);
- // Test the current common case, which uses the shorter constructor.
+ // Test the home country case.
search_terms_args.contextual_search_params =
- TemplateURLRef::SearchTermsArgs::ContextualSearchParams(2, "allen",
- std::string(), 0);
+ TemplateURLRef::SearchTermsArgs::ContextualSearchParams(2, 2, "CH");
result =
url.url_ref().ReplaceSearchTerms(search_terms_args, search_terms_data_);
EXPECT_EQ(
"http://bar/_/contextualsearch?"
"ctxs=2&"
- "q=allen",
+ "ctxsl_coca=2&"
+ "ctxs_hc=CH",
result);
}