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

Side by Side Diff: chrome/browser/autocomplete/shortcuts_provider.cc

Issue 836213002: Assume all providers may give zero suggest responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation issue in athena Created 5 years, 11 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
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/autocomplete/shortcuts_provider.h" 5 #include "chrome/browser/autocomplete/shortcuts_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 scoped_refptr<ShortcutsBackend> backend = 60 scoped_refptr<ShortcutsBackend> backend =
61 ShortcutsBackendFactory::GetForProfile(profile_); 61 ShortcutsBackendFactory::GetForProfile(profile_);
62 if (backend.get()) { 62 if (backend.get()) {
63 backend->AddObserver(this); 63 backend->AddObserver(this);
64 if (backend->initialized()) 64 if (backend->initialized())
65 initialized_ = true; 65 initialized_ = true;
66 } 66 }
67 } 67 }
68 68
69 void ShortcutsProvider::Start(const AutocompleteInput& input, 69 void ShortcutsProvider::Start(const AutocompleteInput& input,
70 bool minimal_changes) { 70 bool minimal_changes,
71 bool called_due_to_focus) {
71 matches_.clear(); 72 matches_.clear();
72 73
73 if ((input.type() == metrics::OmniboxInputType::INVALID) || 74 if (called_due_to_focus ||
74 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) 75 (input.type() == metrics::OmniboxInputType::INVALID) ||
75 return; 76 (input.type() == metrics::OmniboxInputType::FORCED_QUERY) ||
76 77 input.text().empty() ||
77 if (input.text().empty()) 78 !initialized_)
78 return;
79
80 if (!initialized_)
81 return; 79 return;
82 80
83 base::TimeTicks start_time = base::TimeTicks::Now(); 81 base::TimeTicks start_time = base::TimeTicks::Now();
84 GetMatches(input); 82 GetMatches(input);
85 if (input.text().length() < 6) { 83 if (input.text().length() < 6) {
86 base::TimeTicks end_time = base::TimeTicks::Now(); 84 base::TimeTicks end_time = base::TimeTicks::Now();
87 std::string name = "ShortcutsProvider.QueryIndexTime." + 85 std::string name = "ShortcutsProvider.QueryIndexTime." +
88 base::IntToString(input.text().size()); 86 base::IntToString(input.text().size());
89 base::HistogramBase* counter = base::Histogram::FactoryGet( 87 base::HistogramBase* counter = base::Histogram::FactoryGet(
90 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); 88 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 401 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
404 const double kMaxDecaySpeedDivisor = 5.0; 402 const double kMaxDecaySpeedDivisor = 5.0;
405 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 403 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
406 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 404 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
407 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 405 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
408 kNumUsesPerDecaySpeedDivisorIncrement); 406 kNumUsesPerDecaySpeedDivisorIncrement);
409 407
410 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 408 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
411 0.5); 409 0.5);
412 } 410 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_provider.h ('k') | chrome/browser/autocomplete/shortcuts_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698