OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/autocomplete_match.h" | 5 #include "chrome/browser/autocomplete/autocomplete_match.h" |
6 | 6 |
| 7 #include "base/i18n/time_formatting.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/string16.h" |
| 12 #include "base/stringprintf.h" |
| 13 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 15 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
11 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
12 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
14 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
15 #include "grit/theme_resources_standard.h" | 20 #include "grit/theme_resources_standard.h" |
16 | 21 |
17 // AutocompleteMatch ---------------------------------------------------------- | 22 // AutocompleteMatch ---------------------------------------------------------- |
18 | 23 |
19 // static | 24 // static |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 transition(match.transition), | 74 transition(match.transition), |
70 is_history_what_you_typed_match(match.is_history_what_you_typed_match), | 75 is_history_what_you_typed_match(match.is_history_what_you_typed_match), |
71 type(match.type), | 76 type(match.type), |
72 associated_keyword(match.associated_keyword.get() ? | 77 associated_keyword(match.associated_keyword.get() ? |
73 new AutocompleteMatch(*match.associated_keyword) : NULL), | 78 new AutocompleteMatch(*match.associated_keyword) : NULL), |
74 keyword(match.keyword), | 79 keyword(match.keyword), |
75 starred(match.starred), | 80 starred(match.starred), |
76 from_previous(match.from_previous), | 81 from_previous(match.from_previous), |
77 search_terms_args(match.search_terms_args.get() ? | 82 search_terms_args(match.search_terms_args.get() ? |
78 new TemplateURLRef::SearchTermsArgs(*match.search_terms_args) : | 83 new TemplateURLRef::SearchTermsArgs(*match.search_terms_args) : |
79 NULL) { | 84 NULL), |
| 85 info_log(match.info_log) { |
80 } | 86 } |
81 | 87 |
82 AutocompleteMatch::~AutocompleteMatch() { | 88 AutocompleteMatch::~AutocompleteMatch() { |
83 } | 89 } |
84 | 90 |
85 AutocompleteMatch& AutocompleteMatch::operator=( | 91 AutocompleteMatch& AutocompleteMatch::operator=( |
86 const AutocompleteMatch& match) { | 92 const AutocompleteMatch& match) { |
87 if (this == &match) | 93 if (this == &match) |
88 return *this; | 94 return *this; |
89 | 95 |
(...skipping 12 matching lines...) Expand all Loading... |
102 transition = match.transition; | 108 transition = match.transition; |
103 is_history_what_you_typed_match = match.is_history_what_you_typed_match; | 109 is_history_what_you_typed_match = match.is_history_what_you_typed_match; |
104 type = match.type; | 110 type = match.type; |
105 associated_keyword.reset(match.associated_keyword.get() ? | 111 associated_keyword.reset(match.associated_keyword.get() ? |
106 new AutocompleteMatch(*match.associated_keyword) : NULL); | 112 new AutocompleteMatch(*match.associated_keyword) : NULL); |
107 keyword = match.keyword; | 113 keyword = match.keyword; |
108 starred = match.starred; | 114 starred = match.starred; |
109 from_previous = match.from_previous; | 115 from_previous = match.from_previous; |
110 search_terms_args.reset(match.search_terms_args.get() ? | 116 search_terms_args.reset(match.search_terms_args.get() ? |
111 new TemplateURLRef::SearchTermsArgs(*match.search_terms_args) : NULL); | 117 new TemplateURLRef::SearchTermsArgs(*match.search_terms_args) : NULL); |
| 118 info_log = match.info_log; |
112 return *this; | 119 return *this; |
113 } | 120 } |
114 | 121 |
115 // static | 122 // static |
116 std::string AutocompleteMatch::TypeToString(Type type) { | 123 std::string AutocompleteMatch::TypeToString(Type type) { |
117 const char* strings[] = { | 124 const char* strings[] = { |
118 "url-what-you-typed", | 125 "url-what-you-typed", |
119 "history-url", | 126 "history-url", |
120 "history-title", | 127 "history-title", |
121 "history-body", | 128 "history-body", |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return (t_url && t_url->SupportsReplacement()) ? keyword : string16(); | 320 return (t_url && t_url->SupportsReplacement()) ? keyword : string16(); |
314 } | 321 } |
315 | 322 |
316 TemplateURL* AutocompleteMatch::GetTemplateURL(Profile* profile) const { | 323 TemplateURL* AutocompleteMatch::GetTemplateURL(Profile* profile) const { |
317 DCHECK(profile); | 324 DCHECK(profile); |
318 return keyword.empty() ? NULL : | 325 return keyword.empty() ? NULL : |
319 TemplateURLServiceFactory::GetForProfile(profile)-> | 326 TemplateURLServiceFactory::GetForProfile(profile)-> |
320 GetTemplateURLForKeyword(keyword); | 327 GetTemplateURLForKeyword(keyword); |
321 } | 328 } |
322 | 329 |
| 330 void AutocompleteMatch::LogInfo(const std::string& title, |
| 331 const std::string& value) { |
| 332 DCHECK(title.size()); |
| 333 DCHECK(value.size()); |
| 334 info_log[title] = value; |
| 335 } |
| 336 |
| 337 void AutocompleteMatch::LogInfo(const std::string& title, int value) { |
| 338 LogInfo(title, StringPrintf("%d", value)); |
| 339 } |
| 340 |
| 341 void AutocompleteMatch::LogInfo(const std::string& title, |
| 342 const base::Time& value) { |
| 343 LogInfo(title, UTF16ToUTF8(base::TimeFormatShortDateAndTime(value))); |
| 344 } |
| 345 |
323 #ifndef NDEBUG | 346 #ifndef NDEBUG |
324 void AutocompleteMatch::Validate() const { | 347 void AutocompleteMatch::Validate() const { |
325 ValidateClassifications(contents, contents_class); | 348 ValidateClassifications(contents, contents_class); |
326 ValidateClassifications(description, description_class); | 349 ValidateClassifications(description, description_class); |
327 } | 350 } |
328 | 351 |
329 void AutocompleteMatch::ValidateClassifications( | 352 void AutocompleteMatch::ValidateClassifications( |
330 const string16& text, | 353 const string16& text, |
331 const ACMatchClassifications& classifications) const { | 354 const ACMatchClassifications& classifications) const { |
332 if (text.empty()) { | 355 if (text.empty()) { |
(...skipping 17 matching lines...) Expand all Loading... |
350 << " is unsorted in relation to last offset of " << last_offset | 373 << " is unsorted in relation to last offset of " << last_offset |
351 << ". Provider: " << (provider ? provider->name() : "None") << "."; | 374 << ". Provider: " << (provider ? provider->name() : "None") << "."; |
352 DCHECK_LT(i->offset, text.length()) | 375 DCHECK_LT(i->offset, text.length()) |
353 << " Classification of [" << i->offset << "," << text.length() | 376 << " Classification of [" << i->offset << "," << text.length() |
354 << "] is out of bounds for \"" << text << "\". Provider: " | 377 << "] is out of bounds for \"" << text << "\". Provider: " |
355 << (provider ? provider->name() : "None") << "."; | 378 << (provider ? provider->name() : "None") << "."; |
356 last_offset = i->offset; | 379 last_offset = i->offset; |
357 } | 380 } |
358 } | 381 } |
359 #endif | 382 #endif |
OLD | NEW |