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

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

Issue 2497853002: Create TemplateUrlData to base::Dictionary utility functions (Closed)
Patch Set: Fixed android compilation Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/search_engines/template_url_data.h" 5 #include "components/search_engines/template_url_data.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h"
12 13
13 TemplateURLData::TemplateURLData() 14 TemplateURLData::TemplateURLData()
14 : safe_for_autoreplace(false), 15 : safe_for_autoreplace(false),
15 id(0), 16 id(0),
16 date_created(base::Time::Now()), 17 date_created(base::Time::Now()),
17 last_modified(base::Time::Now()), 18 last_modified(base::Time::Now()),
18 created_by_policy(false), 19 created_by_policy(false),
19 usage_count(0), 20 usage_count(0),
20 prepopulate_id(0), 21 prepopulate_id(0),
21 sync_guid(base::GenerateGUID()), 22 sync_guid(base::GenerateGUID()),
22 keyword_(base::ASCIIToUTF16("dummy")), 23 keyword_(base::ASCIIToUTF16("dummy")),
23 url_("x") {} 24 url_("x") {}
24 25
25 TemplateURLData::TemplateURLData(const TemplateURLData& other) = default; 26 TemplateURLData::TemplateURLData(const TemplateURLData& other) = default;
26 27
28 TemplateURLData::TemplateURLData(const base::string16& name,
29 const base::string16& keyword,
30 base::StringPiece search_url,
31 base::StringPiece suggest_url,
32 base::StringPiece instant_url,
33 base::StringPiece image_url,
34 base::StringPiece new_tab_url,
35 base::StringPiece contextual_search_url,
36 base::StringPiece search_url_post_params,
37 base::StringPiece suggest_url_post_params,
38 base::StringPiece instant_url_post_params,
39 base::StringPiece image_url_post_params,
40 base::StringPiece favicon_url,
41 base::StringPiece encoding,
42 const base::ListValue& alternate_urls_list,
43 base::StringPiece search_terms_replacement_key,
44 int prepopulate_id)
45 : suggestions_url(suggest_url.as_string()),
46 instant_url(instant_url.as_string()),
47 image_url(image_url.as_string()),
48 new_tab_url(new_tab_url.as_string()),
49 contextual_search_url(contextual_search_url.as_string()),
50 search_url_post_params(search_url_post_params.as_string()),
51 suggestions_url_post_params(suggest_url_post_params.as_string()),
52 instant_url_post_params(instant_url_post_params.as_string()),
53 image_url_post_params(image_url_post_params.as_string()),
54 favicon_url(GURL(favicon_url)),
55 safe_for_autoreplace(true),
56 id(0),
57 date_created(base::Time()),
58 last_modified(base::Time()),
59 created_by_policy(false),
60 usage_count(0),
61 prepopulate_id(prepopulate_id),
62 sync_guid(base::GenerateGUID()),
63 search_terms_replacement_key(search_terms_replacement_key.as_string()) {
64 SetShortName(name);
65 SetKeyword(keyword);
66 SetURL(search_url.as_string());
67 input_encodings.push_back(encoding.as_string());
68 for (size_t i = 0; i < alternate_urls_list.GetSize(); ++i) {
69 std::string alternate_url;
70 alternate_urls_list.GetString(i, &alternate_url);
71 DCHECK(!alternate_url.empty());
72 alternate_urls.push_back(alternate_url);
73 }
74 }
75
27 TemplateURLData::~TemplateURLData() { 76 TemplateURLData::~TemplateURLData() {
28 } 77 }
29 78
30 void TemplateURLData::SetShortName(const base::string16& short_name) { 79 void TemplateURLData::SetShortName(const base::string16& short_name) {
31 DCHECK(!short_name.empty()); 80 DCHECK(!short_name.empty());
32 81
33 // Remove tabs, carriage returns, and the like, as they can corrupt 82 // Remove tabs, carriage returns, and the like, as they can corrupt
34 // how the short name is displayed. 83 // how the short name is displayed.
35 short_name_ = base::CollapseWhitespace(short_name, true); 84 short_name_ = base::CollapseWhitespace(short_name, true);
36 } 85 }
37 86
38 void TemplateURLData::SetKeyword(const base::string16& keyword) { 87 void TemplateURLData::SetKeyword(const base::string16& keyword) {
39 DCHECK(!keyword.empty()); 88 DCHECK(!keyword.empty());
40 89
41 // Case sensitive keyword matching is confusing. As such, we force all 90 // Case sensitive keyword matching is confusing. As such, we force all
42 // keywords to be lower case. 91 // keywords to be lower case.
43 keyword_ = base::i18n::ToLower(keyword); 92 keyword_ = base::i18n::ToLower(keyword);
44 } 93 }
45 94
46 void TemplateURLData::SetURL(const std::string& url) { 95 void TemplateURLData::SetURL(const std::string& url) {
47 DCHECK(!url.empty()); 96 DCHECK(!url.empty());
48 url_ = url; 97 url_ = url;
49 } 98 }
OLDNEW
« no previous file with comments | « components/search_engines/template_url_data.h ('k') | components/search_engines/template_url_data_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698