Chromium Code Reviews| 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_provider.h" | 5 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 10 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "googleurl/src/url_util.h" | 18 #include "googleurl/src/url_util.h" |
| 19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 const size_t AutocompleteProvider::kMaxMatches = 3; | 22 const size_t AutocompleteProvider::kMaxMatches = 3; |
| 23 | 23 |
| 24 // static | |
| 25 const char* AutocompleteProvider::TypeToString(Type type) { | |
| 26 switch (type) { | |
| 27 case TYPE_BUILTIN: | |
| 28 return "Builtin"; | |
| 29 case TYPE_EXTENSION_APP: | |
| 30 return "ExtensionApps"; | |
| 31 case TYPE_HISTORY_CONTENTS: | |
| 32 return "HistoryContents"; | |
| 33 case TYPE_HISTORY_QUICK: | |
| 34 return "HistoryQuick"; | |
| 35 case TYPE_HISTORY_URL: | |
| 36 return "HistoryURL"; | |
| 37 case TYPE_KEYWORD: | |
| 38 return "Keyword"; | |
| 39 case TYPE_SEARCH: | |
| 40 return "Search"; | |
| 41 case TYPE_SHORTCUTS: | |
| 42 return "Shortcuts"; | |
| 43 case TYPE_ZERO_SUGGEST: | |
| 44 return "ZeroSuggest"; | |
| 45 default: | |
| 46 NOTREACHED() << "Unhandled AutocompleteProvider::Type " << type; | |
| 47 return "Unknown"; | |
| 48 } | |
| 49 } | |
| 50 | |
| 24 AutocompleteProvider::AutocompleteProvider( | 51 AutocompleteProvider::AutocompleteProvider( |
| 25 AutocompleteProviderListener* listener, | 52 AutocompleteProviderListener* listener, |
| 26 Profile* profile, | 53 Profile* profile, |
| 27 const char* name) | 54 Type type) |
| 28 : profile_(profile), | 55 : profile_(profile), |
| 29 listener_(listener), | 56 listener_(listener), |
| 30 done_(true), | 57 done_(true), |
| 31 name_(name) { | 58 type_(type) { |
| 32 } | 59 } |
| 33 | 60 |
| 34 void AutocompleteProvider::Stop(bool clear_cached_results) { | 61 void AutocompleteProvider::Stop(bool clear_cached_results) { |
| 35 done_ = true; | 62 done_ = true; |
| 36 } | 63 } |
| 37 | 64 |
| 38 metrics::OmniboxEventProto_ProviderType AutocompleteProvider:: | 65 metrics::OmniboxEventProto_ProviderType AutocompleteProvider:: |
| 39 AsOmniboxEventProviderType() const { | 66 AsOmniboxEventProviderType() const { |
|
Peter Kasting
2012/09/07 23:23:02
Nit: Can this function at least move to the metric
Daniel Erat
2012/09/08 16:37:36
SearchProvider::AddProviderInfo() is calling it, t
Mark P
2012/09/08 22:31:07
I don't think there's simplification we can do to
| |
| 40 if (name_ == "HistoryURL") | 67 switch (type_) { |
| 41 return metrics::OmniboxEventProto::HISTORY_URL; | 68 case TYPE_BUILTIN: |
| 42 if (name_ == "HistoryContents") | 69 return metrics::OmniboxEventProto::BUILTIN; |
| 43 return metrics::OmniboxEventProto::HISTORY_CONTENTS; | 70 case TYPE_EXTENSION_APP: |
| 44 if (name_ == "HistoryQuick") | 71 return metrics::OmniboxEventProto::EXTENSION_APPS; |
| 45 return metrics::OmniboxEventProto::HISTORY_QUICK; | 72 case TYPE_HISTORY_CONTENTS: |
| 46 if (name_ == "Search") | 73 return metrics::OmniboxEventProto::HISTORY_CONTENTS; |
| 47 return metrics::OmniboxEventProto::SEARCH; | 74 case TYPE_HISTORY_QUICK: |
| 48 if (name_ == "Keyword") | 75 return metrics::OmniboxEventProto::HISTORY_QUICK; |
| 49 return metrics::OmniboxEventProto::KEYWORD; | 76 case TYPE_HISTORY_URL: |
| 50 if (name_ == "Builtin") | 77 return metrics::OmniboxEventProto::HISTORY_URL; |
| 51 return metrics::OmniboxEventProto::BUILTIN; | 78 case TYPE_KEYWORD: |
| 52 if (name_ == "Shortcuts") | 79 return metrics::OmniboxEventProto::KEYWORD; |
| 53 return metrics::OmniboxEventProto::SHORTCUTS; | 80 case TYPE_SEARCH: |
| 54 if (name_ == "ExtensionApps") | 81 return metrics::OmniboxEventProto::SEARCH; |
| 55 return metrics::OmniboxEventProto::EXTENSION_APPS; | 82 case TYPE_SHORTCUTS: |
| 56 | 83 return metrics::OmniboxEventProto::SHORTCUTS; |
| 57 NOTREACHED(); | 84 case TYPE_ZERO_SUGGEST: |
| 58 return metrics::OmniboxEventProto::UNKNOWN_PROVIDER; | 85 // TODO: Add to OmniboxEventProto::ProviderType. |
| 86 default: | |
| 87 NOTREACHED() << "Unhandled AutocompleteProvider::Type " << type_; | |
| 88 return metrics::OmniboxEventProto::UNKNOWN_PROVIDER; | |
| 89 } | |
| 59 } | 90 } |
| 60 | 91 |
| 61 void AutocompleteProvider::DeleteMatch(const AutocompleteMatch& match) { | 92 void AutocompleteProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 62 DLOG(WARNING) << "The AutocompleteProvider '" << name_ | 93 DLOG(WARNING) << "The AutocompleteProvider '" << name() |
| 63 << "' has not implemented DeleteMatch."; | 94 << "' has not implemented DeleteMatch."; |
| 64 } | 95 } |
| 65 | 96 |
| 66 void AutocompleteProvider::AddProviderInfo(ProvidersInfo* provider_info) const { | 97 void AutocompleteProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
| 67 } | 98 } |
| 68 | 99 |
| 69 string16 AutocompleteProvider::StringForURLDisplay(const GURL& url, | 100 string16 AutocompleteProvider::StringForURLDisplay(const GURL& url, |
| 70 bool check_accept_lang, | 101 bool check_accept_lang, |
| 71 bool trim_http) const { | 102 bool trim_http) const { |
| 72 std::string languages = (check_accept_lang && profile_) ? | 103 std::string languages = (check_accept_lang && profile_) ? |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 97 if (!profile_) | 128 if (!profile_) |
| 98 return; | 129 return; |
| 99 | 130 |
| 100 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); | 131 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
| 101 if (!bookmark_model || !bookmark_model->IsLoaded()) | 132 if (!bookmark_model || !bookmark_model->IsLoaded()) |
| 102 return; | 133 return; |
| 103 | 134 |
| 104 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) | 135 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) |
| 105 i->starred = bookmark_model->IsBookmarked(i->destination_url); | 136 i->starred = bookmark_model->IsBookmarked(i->destination_url); |
| 106 } | 137 } |
| OLD | NEW |