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/ui/webui/omnibox/omnibox_ui_handler.h" | 5 #include "chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | |
9 #include <string> | 8 #include <string> |
| 9 #include <utility> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
(...skipping 22 matching lines...) Expand all Loading... |
42 AutocompleteMatch::AdditionalInfo> { | 42 AutocompleteMatch::AdditionalInfo> { |
43 static mojo::Array<AutocompleteAdditionalInfoPtr> Convert( | 43 static mojo::Array<AutocompleteAdditionalInfoPtr> Convert( |
44 const AutocompleteMatch::AdditionalInfo& input) { | 44 const AutocompleteMatch::AdditionalInfo& input) { |
45 mojo::Array<AutocompleteAdditionalInfoPtr> array(input.size()); | 45 mojo::Array<AutocompleteAdditionalInfoPtr> array(input.size()); |
46 size_t index = 0; | 46 size_t index = 0; |
47 for (AutocompleteMatch::AdditionalInfo::const_iterator i = input.begin(); | 47 for (AutocompleteMatch::AdditionalInfo::const_iterator i = input.begin(); |
48 i != input.end(); ++i, index++) { | 48 i != input.end(); ++i, index++) { |
49 AutocompleteAdditionalInfoPtr item(AutocompleteAdditionalInfo::New()); | 49 AutocompleteAdditionalInfoPtr item(AutocompleteAdditionalInfo::New()); |
50 item->key = i->first; | 50 item->key = i->first; |
51 item->value = i->second; | 51 item->value = i->second; |
52 array[index] = item.Pass(); | 52 array[index] = std::move(item); |
53 } | 53 } |
54 return array.Pass(); | 54 return array; |
55 } | 55 } |
56 }; | 56 }; |
57 | 57 |
58 template <> | 58 template <> |
59 struct TypeConverter<AutocompleteMatchMojoPtr, AutocompleteMatch> { | 59 struct TypeConverter<AutocompleteMatchMojoPtr, AutocompleteMatch> { |
60 static AutocompleteMatchMojoPtr Convert(const AutocompleteMatch& input) { | 60 static AutocompleteMatchMojoPtr Convert(const AutocompleteMatch& input) { |
61 AutocompleteMatchMojoPtr result(AutocompleteMatchMojo::New()); | 61 AutocompleteMatchMojoPtr result(AutocompleteMatchMojo::New()); |
62 if (input.provider != NULL) { | 62 if (input.provider != NULL) { |
63 result->provider_name = input.provider->GetName(); | 63 result->provider_name = input.provider->GetName(); |
64 result->provider_done = input.provider->done(); | 64 result->provider_done = input.provider->done(); |
(...skipping 18 matching lines...) Expand all Loading... |
83 if (input.associated_keyword.get() != NULL) { | 83 if (input.associated_keyword.get() != NULL) { |
84 result->associated_keyword = | 84 result->associated_keyword = |
85 mojo::String::From(input.associated_keyword->keyword); | 85 mojo::String::From(input.associated_keyword->keyword); |
86 } | 86 } |
87 result->keyword = mojo::String::From(input.keyword); | 87 result->keyword = mojo::String::From(input.keyword); |
88 result->duplicates = static_cast<int32_t>(input.duplicate_matches.size()); | 88 result->duplicates = static_cast<int32_t>(input.duplicate_matches.size()); |
89 result->from_previous = input.from_previous; | 89 result->from_previous = input.from_previous; |
90 | 90 |
91 result->additional_info = | 91 result->additional_info = |
92 mojo::Array<AutocompleteAdditionalInfoPtr>::From(input.additional_info); | 92 mojo::Array<AutocompleteAdditionalInfoPtr>::From(input.additional_info); |
93 return result.Pass(); | 93 return result; |
94 } | 94 } |
95 }; | 95 }; |
96 | 96 |
97 template <> | 97 template <> |
98 struct TypeConverter<AutocompleteResultsForProviderMojoPtr, | 98 struct TypeConverter<AutocompleteResultsForProviderMojoPtr, |
99 scoped_refptr<AutocompleteProvider> > { | 99 scoped_refptr<AutocompleteProvider> > { |
100 static AutocompleteResultsForProviderMojoPtr Convert( | 100 static AutocompleteResultsForProviderMojoPtr Convert( |
101 const scoped_refptr<AutocompleteProvider>& input) { | 101 const scoped_refptr<AutocompleteProvider>& input) { |
102 AutocompleteResultsForProviderMojoPtr result( | 102 AutocompleteResultsForProviderMojoPtr result( |
103 AutocompleteResultsForProviderMojo::New()); | 103 AutocompleteResultsForProviderMojo::New()); |
104 result->provider_name = input->GetName(); | 104 result->provider_name = input->GetName(); |
105 result->results = | 105 result->results = |
106 mojo::Array<AutocompleteMatchMojoPtr>::From(input->matches()); | 106 mojo::Array<AutocompleteMatchMojoPtr>::From(input->matches()); |
107 return result.Pass(); | 107 return result; |
108 } | 108 } |
109 }; | 109 }; |
110 | 110 |
111 } // namespace mojo | 111 } // namespace mojo |
112 | 112 |
113 OmniboxUIHandler::OmniboxUIHandler( | 113 OmniboxUIHandler::OmniboxUIHandler( |
114 Profile* profile, | 114 Profile* profile, |
115 mojo::InterfaceRequest<OmniboxUIHandlerMojo> request) | 115 mojo::InterfaceRequest<OmniboxUIHandlerMojo> request) |
116 : profile_(profile), | 116 : profile_(profile), binding_(this, std::move(request)) { |
117 binding_(this, request.Pass()) { | |
118 ResetController(); | 117 ResetController(); |
119 } | 118 } |
120 | 119 |
121 OmniboxUIHandler::~OmniboxUIHandler() { | 120 OmniboxUIHandler::~OmniboxUIHandler() { |
122 } | 121 } |
123 | 122 |
124 void OmniboxUIHandler::OnResultChanged(bool default_match_changed) { | 123 void OmniboxUIHandler::OnResultChanged(bool default_match_changed) { |
125 OmniboxResultMojoPtr result(OmniboxResultMojo::New()); | 124 OmniboxResultMojoPtr result(OmniboxResultMojo::New()); |
126 result->done = controller_->done(); | 125 result->done = controller_->done(); |
127 result->time_since_omnibox_started_ms = | 126 result->time_since_omnibox_started_ms = |
(...skipping 29 matching lines...) Expand all Loading... |
157 for (size_t i = 0; i < result->results_by_provider.size(); ++i) { | 156 for (size_t i = 0; i < result->results_by_provider.size(); ++i) { |
158 const AutocompleteResultsForProviderMojo& result_by_provider = | 157 const AutocompleteResultsForProviderMojo& result_by_provider = |
159 *result->results_by_provider[i]; | 158 *result->results_by_provider[i]; |
160 for (size_t j = 0; j < result_by_provider.results.size(); ++j) { | 159 for (size_t j = 0; j < result_by_provider.results.size(); ++j) { |
161 result_by_provider.results[j]->starred = bookmark_model->IsBookmarked( | 160 result_by_provider.results[j]->starred = bookmark_model->IsBookmarked( |
162 GURL(result_by_provider.results[j]->destination_url)); | 161 GURL(result_by_provider.results[j]->destination_url)); |
163 } | 162 } |
164 } | 163 } |
165 } | 164 } |
166 | 165 |
167 page_->HandleNewAutocompleteResult(result.Pass()); | 166 page_->HandleNewAutocompleteResult(std::move(result)); |
168 } | 167 } |
169 | 168 |
170 bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host, | 169 bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host, |
171 bool* is_typed_host) const { | 170 bool* is_typed_host) const { |
172 history::HistoryService* const history_service = | 171 history::HistoryService* const history_service = |
173 HistoryServiceFactory::GetForProfile(profile_, | 172 HistoryServiceFactory::GetForProfile(profile_, |
174 ServiceAccessType::EXPLICIT_ACCESS); | 173 ServiceAccessType::EXPLICIT_ACCESS); |
175 if (!history_service) | 174 if (!history_service) |
176 return false; | 175 return false; |
177 history::URLDatabase* url_db = history_service->InMemoryDatabase(); | 176 history::URLDatabase* url_db = history_service->InMemoryDatabase(); |
178 if (!url_db) | 177 if (!url_db) |
179 return false; | 178 return false; |
180 *is_typed_host = url_db->IsTypedHost(base::UTF16ToUTF8(host)); | 179 *is_typed_host = url_db->IsTypedHost(base::UTF16ToUTF8(host)); |
181 return true; | 180 return true; |
182 } | 181 } |
183 | 182 |
184 void OmniboxUIHandler::StartOmniboxQuery(const mojo::String& input_string, | 183 void OmniboxUIHandler::StartOmniboxQuery(const mojo::String& input_string, |
185 int32_t cursor_position, | 184 int32_t cursor_position, |
186 bool prevent_inline_autocomplete, | 185 bool prevent_inline_autocomplete, |
187 bool prefer_keyword, | 186 bool prefer_keyword, |
188 int32_t page_classification, | 187 int32_t page_classification, |
189 OmniboxPagePtr page) { | 188 OmniboxPagePtr page) { |
190 // Reset the controller. If we don't do this, then the | 189 // Reset the controller. If we don't do this, then the |
191 // AutocompleteController might inappropriately set its |minimal_changes| | 190 // AutocompleteController might inappropriately set its |minimal_changes| |
192 // variable (or something else) and some providers will short-circuit | 191 // variable (or something else) and some providers will short-circuit |
193 // important logic and return stale results. In short, we want the | 192 // important logic and return stale results. In short, we want the |
194 // actual results to not depend on the state of the previous request. | 193 // actual results to not depend on the state of the previous request. |
195 ResetController(); | 194 ResetController(); |
196 page_ = page.Pass(); | 195 page_ = std::move(page); |
197 time_omnibox_started_ = base::Time::Now(); | 196 time_omnibox_started_ = base::Time::Now(); |
198 input_ = AutocompleteInput( | 197 input_ = AutocompleteInput( |
199 input_string.To<base::string16>(), cursor_position, std::string(), GURL(), | 198 input_string.To<base::string16>(), cursor_position, std::string(), GURL(), |
200 static_cast<metrics::OmniboxEventProto::PageClassification>( | 199 static_cast<metrics::OmniboxEventProto::PageClassification>( |
201 page_classification), | 200 page_classification), |
202 prevent_inline_autocomplete, prefer_keyword, true, true, false, | 201 prevent_inline_autocomplete, prefer_keyword, true, true, false, |
203 ChromeAutocompleteSchemeClassifier(profile_)); | 202 ChromeAutocompleteSchemeClassifier(profile_)); |
204 controller_->Start(input_); | 203 controller_->Start(input_); |
205 } | 204 } |
206 | 205 |
207 void OmniboxUIHandler::ResetController() { | 206 void OmniboxUIHandler::ResetController() { |
208 controller_.reset(new AutocompleteController( | 207 controller_.reset(new AutocompleteController( |
209 make_scoped_ptr(new ChromeAutocompleteProviderClient(profile_)), this, | 208 make_scoped_ptr(new ChromeAutocompleteProviderClient(profile_)), this, |
210 AutocompleteClassifier::kDefaultOmniboxProviders)); | 209 AutocompleteClassifier::kDefaultOmniboxProviders)); |
211 } | 210 } |
OLD | NEW |