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