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

Side by Side Diff: chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc

Issue 882883006: Remove Client= relationship in omnibox.mojom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
« no previous file with comments | « chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 }; 108 };
109 109
110 } // namespace mojo 110 } // namespace mojo
111 111
112 OmniboxUIHandler::OmniboxUIHandler(Profile* profile) 112 OmniboxUIHandler::OmniboxUIHandler(Profile* profile)
113 : profile_(profile) { 113 : profile_(profile) {
114 ResetController(); 114 ResetController();
115 } 115 }
116 116
117 OmniboxUIHandler::~OmniboxUIHandler() {} 117 OmniboxUIHandler::~OmniboxUIHandler() {
118 }
118 119
119 void OmniboxUIHandler::OnResultChanged(bool default_match_changed) { 120 void OmniboxUIHandler::OnResultChanged(bool default_match_changed) {
120 OmniboxResultMojoPtr result(OmniboxResultMojo::New()); 121 OmniboxResultMojoPtr result(OmniboxResultMojo::New());
121 result->done = controller_->done(); 122 result->done = controller_->done();
122 result->time_since_omnibox_started_ms = 123 result->time_since_omnibox_started_ms =
123 (base::Time::Now() - time_omnibox_started_).InMilliseconds(); 124 (base::Time::Now() - time_omnibox_started_).InMilliseconds();
124 const base::string16 host = input_.text().substr( 125 const base::string16 host = input_.text().substr(
125 input_.parts().host.begin, 126 input_.parts().host.begin,
126 input_.parts().host.len); 127 input_.parts().host.len);
127 result->host = mojo::String::From(host); 128 result->host = mojo::String::From(host);
(...skipping 24 matching lines...) Expand all
152 for (size_t i = 0; i < result->results_by_provider.size(); ++i) { 153 for (size_t i = 0; i < result->results_by_provider.size(); ++i) {
153 const AutocompleteResultsForProviderMojo& result_by_provider = 154 const AutocompleteResultsForProviderMojo& result_by_provider =
154 *result->results_by_provider[i]; 155 *result->results_by_provider[i];
155 for (size_t j = 0; j < result_by_provider.results.size(); ++j) { 156 for (size_t j = 0; j < result_by_provider.results.size(); ++j) {
156 result_by_provider.results[j]->starred = bookmark_model->IsBookmarked( 157 result_by_provider.results[j]->starred = bookmark_model->IsBookmarked(
157 GURL(result_by_provider.results[j]->destination_url)); 158 GURL(result_by_provider.results[j]->destination_url));
158 } 159 }
159 } 160 }
160 } 161 }
161 162
162 client()->HandleNewAutocompleteResult(result.Pass()); 163 page_->HandleNewAutocompleteResult(result.Pass());
163 } 164 }
164 165
165 bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host, 166 bool OmniboxUIHandler::LookupIsTypedHost(const base::string16& host,
166 bool* is_typed_host) const { 167 bool* is_typed_host) const {
167 HistoryService* const history_service = HistoryServiceFactory::GetForProfile( 168 HistoryService* const history_service = HistoryServiceFactory::GetForProfile(
168 profile_, ServiceAccessType::EXPLICIT_ACCESS); 169 profile_, ServiceAccessType::EXPLICIT_ACCESS);
169 if (!history_service) 170 if (!history_service)
170 return false; 171 return false;
171 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 172 history::URLDatabase* url_db = history_service->InMemoryDatabase();
172 if (!url_db) 173 if (!url_db)
173 return false; 174 return false;
174 *is_typed_host = url_db->IsTypedHost(base::UTF16ToUTF8(host)); 175 *is_typed_host = url_db->IsTypedHost(base::UTF16ToUTF8(host));
175 return true; 176 return true;
176 } 177 }
177 178
178 void OmniboxUIHandler::StartOmniboxQuery(const mojo::String& input_string, 179 void OmniboxUIHandler::StartOmniboxQuery(const mojo::String& input_string,
179 int32_t cursor_position, 180 int32_t cursor_position,
180 bool prevent_inline_autocomplete, 181 bool prevent_inline_autocomplete,
181 bool prefer_keyword, 182 bool prefer_keyword,
182 int32_t page_classification) { 183 int32_t page_classification,
184 OmniboxPagePtr page) {
183 // Reset the controller. If we don't do this, then the 185 // Reset the controller. If we don't do this, then the
184 // AutocompleteController might inappropriately set its |minimal_changes| 186 // AutocompleteController might inappropriately set its |minimal_changes|
185 // variable (or something else) and some providers will short-circuit 187 // variable (or something else) and some providers will short-circuit
186 // important logic and return stale results. In short, we want the 188 // important logic and return stale results. In short, we want the
187 // actual results to not depend on the state of the previous request. 189 // actual results to not depend on the state of the previous request.
188 ResetController(); 190 ResetController();
191 page_ = page.Pass();
189 time_omnibox_started_ = base::Time::Now(); 192 time_omnibox_started_ = base::Time::Now();
190 input_ = AutocompleteInput( 193 input_ = AutocompleteInput(
191 input_string.To<base::string16>(), cursor_position, std::string(), GURL(), 194 input_string.To<base::string16>(), cursor_position, std::string(), GURL(),
192 static_cast<metrics::OmniboxEventProto::PageClassification>( 195 static_cast<metrics::OmniboxEventProto::PageClassification>(
193 page_classification), 196 page_classification),
194 prevent_inline_autocomplete, prefer_keyword, true, true, 197 prevent_inline_autocomplete, prefer_keyword, true, true,
195 ChromeAutocompleteSchemeClassifier(profile_)); 198 ChromeAutocompleteSchemeClassifier(profile_));
196 controller_->Start(input_); 199 controller_->Start(input_);
197 } 200 }
198 201
199 void OmniboxUIHandler::ResetController() { 202 void OmniboxUIHandler::ResetController() {
200 controller_.reset(new AutocompleteController(profile_, 203 controller_.reset(new AutocompleteController(profile_,
201 TemplateURLServiceFactory::GetForProfile(profile_), 204 TemplateURLServiceFactory::GetForProfile(profile_),
202 this, 205 this,
203 AutocompleteClassifier::kDefaultOmniboxProviders)); 206 AutocompleteClassifier::kDefaultOmniboxProviders));
204 } 207 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698