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_controller.h" | 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 // Start the new query. | 258 // Start the new query. |
259 in_start_ = true; | 259 in_start_ = true; |
260 base::TimeTicks start_time = base::TimeTicks::Now(); | 260 base::TimeTicks start_time = base::TimeTicks::Now(); |
261 for (Providers::iterator i(providers_.begin()); i != providers_.end(); ++i) { | 261 for (Providers::iterator i(providers_.begin()); i != providers_.end(); ++i) { |
262 // TODO(mpearson): Remove timing code once bugs 178705 / 237703 / 168933 | 262 // TODO(mpearson): Remove timing code once bugs 178705 / 237703 / 168933 |
263 // are resolved. | 263 // are resolved. |
264 base::TimeTicks provider_start_time = base::TimeTicks::Now(); | 264 base::TimeTicks provider_start_time = base::TimeTicks::Now(); |
265 | 265 |
266 // Call Start() on ZeroSuggestProvider with an INVALID AutocompleteInput | 266 // Call Start() on ZeroSuggestProvider with an INVALID AutocompleteInput |
267 // to clear out zero-suggest |matches_|. | 267 // to clear out zero-suggest |matches_|. |
268 if (i->get() == zero_suggest_provider_) | 268 if (i->get() == zero_suggest_provider_) |
Maria
2015/01/05 19:09:52
This bit is a little strange now. Here we clear ou
Peter Kasting
2015/01/05 19:31:07
Yeah, this is weird. I kind of think the ZeroSugg
| |
269 (*i)->Start(AutocompleteInput(), minimal_changes); | 269 (*i)->Start(AutocompleteInput(), minimal_changes); |
270 else | 270 else |
271 (*i)->Start(input_, minimal_changes); | 271 (*i)->Start(input_, minimal_changes); |
272 | 272 |
273 if (!input.want_asynchronous_matches()) | 273 if (!input.want_asynchronous_matches()) |
274 DCHECK((*i)->done()); | 274 DCHECK((*i)->done()); |
275 base::TimeTicks provider_end_time = base::TimeTicks::Now(); | 275 base::TimeTicks provider_end_time = base::TimeTicks::Now(); |
276 std::string name = std::string("Omnibox.ProviderTime.") + (*i)->GetName(); | 276 std::string name = std::string("Omnibox.ProviderTime.") + (*i)->GetName(); |
277 base::HistogramBase* counter = base::Histogram::FactoryGet( | 277 base::HistogramBase* counter = base::Histogram::FactoryGet( |
278 name, 1, 5000, 20, base::Histogram::kUmaTargetedHistogramFlag); | 278 name, 1, 5000, 20, base::Histogram::kUmaTargetedHistogramFlag); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 stop_timer_.Stop(); | 320 stop_timer_.Stop(); |
321 done_ = true; | 321 done_ = true; |
322 if (clear_result && !result_.empty()) { | 322 if (clear_result && !result_.empty()) { |
323 result_.Reset(); | 323 result_.Reset(); |
324 // NOTE: We pass in false since we're trying to only clear the popup, not | 324 // NOTE: We pass in false since we're trying to only clear the popup, not |
325 // touch the edit... this is all a mess and should be cleaned up :( | 325 // touch the edit... this is all a mess and should be cleaned up :( |
326 NotifyChanged(false); | 326 NotifyChanged(false); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 void AutocompleteController::StartZeroSuggest(const AutocompleteInput& input) { | 330 void AutocompleteController::OnOmniboxFocused(const AutocompleteInput& input) { |
331 if (zero_suggest_provider_ == NULL) | |
332 return; | |
333 | |
334 DCHECK(!in_start_); // We should not be already running a query. | 331 DCHECK(!in_start_); // We should not be already running a query. |
335 | 332 |
336 // Call Start() on all prefix-based providers with an INVALID | 333 // Call Start() on all prefix-based providers with an INVALID |
337 // AutocompleteInput to clear out cached |matches_|, which ensures that | 334 // AutocompleteInput to clear out cached |matches_|, which ensures that |
338 // they aren't used with zero suggest. | 335 // they aren't used with zero suggest. |
339 for (Providers::iterator i(providers_.begin()); i != providers_.end(); ++i) { | 336 for (Providers::iterator i(providers_.begin()); i != providers_.end(); ++i) { |
340 if (i->get() == zero_suggest_provider_) | 337 if ((*i)->ProvidesMatchesOnOmniboxFocus()) |
341 (*i)->Start(input, false); | 338 (*i)->Start(input, false); |
342 else | 339 else |
343 (*i)->Start(AutocompleteInput(), false); | 340 (*i)->Start(AutocompleteInput(), false); |
344 } | 341 } |
345 | 342 |
346 if (!zero_suggest_provider_->matches().empty()) | 343 UpdateResult(false, false); |
347 UpdateResult(false, false); | |
348 } | 344 } |
349 | 345 |
350 void AutocompleteController::DeleteMatch(const AutocompleteMatch& match) { | 346 void AutocompleteController::DeleteMatch(const AutocompleteMatch& match) { |
351 DCHECK(match.SupportsDeletion()); | 347 DCHECK(match.SupportsDeletion()); |
352 | 348 |
353 // Delete duplicate matches attached to the main match first. | 349 // Delete duplicate matches attached to the main match first. |
354 for (ACMatches::const_iterator it(match.duplicate_matches.begin()); | 350 for (ACMatches::const_iterator it(match.duplicate_matches.begin()); |
355 it != match.duplicate_matches.end(); ++it) { | 351 it != match.duplicate_matches.end(); ++it) { |
356 if (it->deletable) | 352 if (it->deletable) |
357 it->provider->DeleteMatch(*it); | 353 it->provider->DeleteMatch(*it); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 this, &AutocompleteController::ExpireCopiedEntries); | 675 this, &AutocompleteController::ExpireCopiedEntries); |
680 } | 676 } |
681 | 677 |
682 void AutocompleteController::StartStopTimer() { | 678 void AutocompleteController::StartStopTimer() { |
683 stop_timer_.Start(FROM_HERE, | 679 stop_timer_.Start(FROM_HERE, |
684 stop_timer_duration_, | 680 stop_timer_duration_, |
685 base::Bind(&AutocompleteController::Stop, | 681 base::Bind(&AutocompleteController::Stop, |
686 base::Unretained(this), | 682 base::Unretained(this), |
687 false)); | 683 false)); |
688 } | 684 } |
OLD | NEW |