diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-11 06:25:25 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-11 06:25:25 +0000 |
commit | fa817b17e3198710708050cd11533a3436533b8e (patch) | |
tree | 517c4c7e45dc5b39b6f27dd93bdcdfdb386c0449 /components/search_engines | |
parent | 44beb038b6ed734bae5c4d8101847eb56dc498fe (diff) | |
download | chromium_src-fa817b17e3198710708050cd11533a3436533b8e.zip chromium_src-fa817b17e3198710708050cd11533a3436533b8e.tar.gz chromium_src-fa817b17e3198710708050cd11533a3436533b8e.tar.bz2 |
Craete a new component search_engines
Move template_url_id.h from chrome/browser/search_engines to components/search_engines.
Split TemplateURLData from template_url.h to a separate file, move it to components/search_engines.
BUG=371535
TEST=git cl try
Review URL: https://codereview.chromium.org/315983002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/search_engines')
-rw-r--r-- | components/search_engines/OWNERS | 2 | ||||
-rw-r--r-- | components/search_engines/template_url_data.cc | 40 | ||||
-rw-r--r-- | components/search_engines/template_url_data.h | 121 | ||||
-rw-r--r-- | components/search_engines/template_url_id.h | 14 |
4 files changed, 177 insertions, 0 deletions
diff --git a/components/search_engines/OWNERS b/components/search_engines/OWNERS new file mode 100644 index 0000000..c19e61b --- /dev/null +++ b/components/search_engines/OWNERS @@ -0,0 +1,2 @@ +pkasting@chromium.org +stevet@chromium.org diff --git a/components/search_engines/template_url_data.cc b/components/search_engines/template_url_data.cc new file mode 100644 index 0000000..fdbec7d --- /dev/null +++ b/components/search_engines/template_url_data.cc @@ -0,0 +1,40 @@ +// 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/template_url_data.h" + +#include "base/guid.h" +#include "base/i18n/case_conversion.h" +#include "base/logging.h" +#include "base/strings/utf_string_conversions.h" + +TemplateURLData::TemplateURLData() + : show_in_default_list(false), + safe_for_autoreplace(false), + id(0), + date_created(base::Time::Now()), + last_modified(base::Time::Now()), + created_by_policy(false), + usage_count(0), + prepopulate_id(0), + sync_guid(base::GenerateGUID()), + keyword_(base::ASCIIToUTF16("dummy")), + url_("x") { +} + +TemplateURLData::~TemplateURLData() { +} + +void TemplateURLData::SetKeyword(const base::string16& keyword) { + DCHECK(!keyword.empty()); + + // Case sensitive keyword matching is confusing. As such, we force all + // keywords to be lower case. + keyword_ = base::i18n::ToLower(keyword); +} + +void TemplateURLData::SetURL(const std::string& url) { + DCHECK(!url.empty()); + url_ = url; +} diff --git a/components/search_engines/template_url_data.h b/components/search_engines/template_url_data.h new file mode 100644 index 0000000..4479e84 --- /dev/null +++ b/components/search_engines/template_url_data.h @@ -0,0 +1,121 @@ +// 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_TEMPLATE_URL_DATA_H_ +#define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_ + +#include <string> +#include <vector> + +#include "base/strings/string16.h" +#include "base/time/time.h" +#include "components/search_engines/template_url_id.h" +#include "url/gurl.h" + +// 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(); + + // A short description of the template. This is the name we show to the user + // in various places that use TemplateURLs. For example, the location bar + // shows this when the user selects a substituting match. + base::string16 short_name; + + // The shortcut for this TemplateURL. |keyword| must be non-empty. + void SetKeyword(const base::string16& keyword); + const base::string16& keyword() const { return keyword_; } + + // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because + // it requires substitutions first). This must be non-empty. + void SetURL(const std::string& url); + const std::string& url() const { return url_; } + + // Optional additional raw URLs. + std::string suggestions_url; + std::string instant_url; + std::string image_url; + std::string new_tab_url; + + // The following post_params are comma-separated lists used to specify the + // post parameters for the corresponding URL. + std::string search_url_post_params; + std::string suggestions_url_post_params; + std::string instant_url_post_params; + std::string image_url_post_params; + + // Optional favicon for the TemplateURL. + GURL favicon_url; + + // 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 + // TemplateURL that the user clearly manually edited in the past, like a + // bookmark keyword from another browser. + bool safe_for_autoreplace; + + // The list of supported encodings for the search terms. This may be empty, + // which indicates the terms should be encoded with UTF-8. + std::vector<std::string> input_encodings; + + // Unique identifier of this TemplateURL. The unique ID is set by the + // TemplateURLService when the TemplateURL is added to it. + TemplateURLID id; + + // Date this TemplateURL was created. + // + // NOTE: this may be 0, which indicates the TemplateURL was created before we + // started tracking creation time. + base::Time date_created; + + // The last time this TemplateURL was modified by a user, since creation. + // + // NOTE: Like date_created above, this may be 0. + base::Time last_modified; + + // True if this TemplateURL was automatically created by the administrator via + // group policy. + bool created_by_policy; + + // Number of times this TemplateURL has been explicitly used to load a URL. + // We don't increment this for uses as the "default search engine" since + // that's not really "explicit" usage and incrementing would result in pinning + // the user's default search engine(s) to the top of the list of searches on + // the New Tab page, de-emphasizing the omnibox as "where you go to search". + int usage_count; + + // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0. + int prepopulate_id; + + // The primary unique identifier for Sync. This set on all TemplateURLs + // regardless of whether they have been associated with Sync. + std::string sync_guid; + + // A list of URL patterns that can be used, in addition to |url_|, to extract + // search terms from a URL. + std::vector<std::string> alternate_urls; + + // A parameter that, if present in the query or ref parameters of a search_url + // or instant_url, causes Chrome to replace the URL with the search term. + std::string search_terms_replacement_key; + + private: + // Private so we can enforce using the setters and thus enforce that these + // fields are never empty. + base::string16 keyword_; + std::string url_; +}; + +#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_ diff --git a/components/search_engines/template_url_id.h b/components/search_engines/template_url_id.h new file mode 100644 index 0000000..d16f5b8 --- /dev/null +++ b/components/search_engines/template_url_id.h @@ -0,0 +1,14 @@ +// 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_TEMPLATE_URL_ID_H_ +#define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_ID_H_ + +#include "base/basictypes.h" + +typedef int64 TemplateURLID; + +const TemplateURLID kInvalidTemplateURLID = 0; + +#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_ID_H_ |