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

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

Issue 2497853002: Create TemplateUrlData to base::Dictionary utility functions (Closed)
Patch Set: Another round of review, mostly cosmetic changes Created 4 years 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(
29 const base::string16& name,
30 const base::string16& keyword,
31 const base::StringPiece& search_url,
32 const base::StringPiece& suggest_url,
33 const base::StringPiece& instant_url,
34 const base::StringPiece& image_url,
35 const base::StringPiece& new_tab_url,
36 const base::StringPiece& contextual_search_url,
37 const base::StringPiece& search_url_post_params,
38 const base::StringPiece& suggest_url_post_params,
39 const base::StringPiece& instant_url_post_params,
40 const base::StringPiece& image_url_post_params,
41 const base::StringPiece& favicon_url,
42 const base::StringPiece& encoding,
43 const base::ListValue& alternate_urls_list,
44 const base::StringPiece& search_terms_replacement_key,
45 int prepopulate_id)
46 : suggestions_url(suggest_url.as_string()),
47 instant_url(instant_url.as_string()),
48 image_url(image_url.as_string()),
49 new_tab_url(new_tab_url.as_string()),
50 contextual_search_url(contextual_search_url.as_string()),
51 search_url_post_params(search_url_post_params.as_string()),
52 suggestions_url_post_params(suggest_url_post_params.as_string()),
53 instant_url_post_params(instant_url_post_params.as_string()),
54 image_url_post_params(image_url_post_params.as_string()),
55 favicon_url(GURL(favicon_url)),
56 safe_for_autoreplace(true),
57 date_created(base::Time()),
58 last_modified(base::Time()),
59 prepopulate_id(prepopulate_id),
60 search_terms_replacement_key(search_terms_replacement_key.as_string()) {
61 SetShortName(name);
62 SetKeyword(keyword);
63 SetURL(search_url.as_string());
64 input_encodings.push_back(encoding.as_string());
65 for (size_t i = 0; i < alternate_urls_list.GetSize(); ++i) {
66 std::string alternate_url;
67 alternate_urls_list.GetString(i, &alternate_url);
68 DCHECK(!alternate_url.empty());
69 alternate_urls.push_back(alternate_url);
70 }
71 }
72
27 TemplateURLData::~TemplateURLData() { 73 TemplateURLData::~TemplateURLData() {
28 } 74 }
29 75
30 void TemplateURLData::SetShortName(const base::string16& short_name) { 76 void TemplateURLData::SetShortName(const base::string16& short_name) {
31 DCHECK(!short_name.empty()); 77 DCHECK(!short_name.empty());
32 78
33 // Remove tabs, carriage returns, and the like, as they can corrupt 79 // Remove tabs, carriage returns, and the like, as they can corrupt
34 // how the short name is displayed. 80 // how the short name is displayed.
35 short_name_ = base::CollapseWhitespace(short_name, true); 81 short_name_ = base::CollapseWhitespace(short_name, true);
36 } 82 }
37 83
38 void TemplateURLData::SetKeyword(const base::string16& keyword) { 84 void TemplateURLData::SetKeyword(const base::string16& keyword) {
39 DCHECK(!keyword.empty()); 85 DCHECK(!keyword.empty());
40 86
41 // Case sensitive keyword matching is confusing. As such, we force all 87 // Case sensitive keyword matching is confusing. As such, we force all
42 // keywords to be lower case. 88 // keywords to be lower case.
43 keyword_ = base::i18n::ToLower(keyword); 89 keyword_ = base::i18n::ToLower(keyword);
44 } 90 }
45 91
46 void TemplateURLData::SetURL(const std::string& url) { 92 void TemplateURLData::SetURL(const std::string& url) {
47 DCHECK(!url.empty()); 93 DCHECK(!url.empty());
48 url_ = url; 94 url_ = url;
49 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698