| 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/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 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" | 26 #include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
| 27 #include "chrome/browser/autocomplete/url_prefix.h" | 27 #include "chrome/browser/autocomplete/url_prefix.h" |
| 28 #include "chrome/browser/history/history_notifications.h" | 28 #include "chrome/browser/history/history_notifications.h" |
| 29 #include "chrome/browser/history/history_service.h" | 29 #include "chrome/browser/history/history_service.h" |
| 30 #include "chrome/browser/history/history_service_factory.h" | 30 #include "chrome/browser/history/history_service_factory.h" |
| 31 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 31 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/common/net/url_fixer_upper.h" | 33 #include "chrome/common/net/url_fixer_upper.h" |
| 34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 36 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 36 #include "url/url_parse.h" | 37 #include "url/url_parse.h" |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 class DestinationURLEqualsURL { | 41 class DestinationURLEqualsURL { |
| 41 public: | 42 public: |
| 42 explicit DestinationURLEqualsURL(const GURL& url) : url_(url) {} | 43 explicit DestinationURLEqualsURL(const GURL& url) : url_(url) {} |
| 43 bool operator()(const AutocompleteMatch& match) const { | 44 bool operator()(const AutocompleteMatch& match) const { |
| 44 return match.destination_url == url_; | 45 return match.destination_url == url_; |
| 45 } | 46 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 backend->AddObserver(this); | 64 backend->AddObserver(this); |
| 64 if (backend->initialized()) | 65 if (backend->initialized()) |
| 65 initialized_ = true; | 66 initialized_ = true; |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ShortcutsProvider::Start(const AutocompleteInput& input, | 70 void ShortcutsProvider::Start(const AutocompleteInput& input, |
| 70 bool minimal_changes) { | 71 bool minimal_changes) { |
| 71 matches_.clear(); | 72 matches_.clear(); |
| 72 | 73 |
| 73 if ((input.type() == AutocompleteInput::INVALID) || | 74 if ((input.type() == metrics::OmniboxInputType::INVALID) || |
| 74 (input.type() == AutocompleteInput::FORCED_QUERY)) | 75 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) |
| 75 return; | 76 return; |
| 76 | 77 |
| 77 if (input.text().empty()) | 78 if (input.text().empty()) |
| 78 return; | 79 return; |
| 79 | 80 |
| 80 if (!initialized_) | 81 if (!initialized_) |
| 81 return; | 82 return; |
| 82 | 83 |
| 83 base::TimeTicks start_time = base::TimeTicks::Now(); | 84 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 84 GetMatches(input); | 85 GetMatches(input); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 413 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
| 413 const double kMaxDecaySpeedDivisor = 5.0; | 414 const double kMaxDecaySpeedDivisor = 5.0; |
| 414 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 415 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
| 415 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 416 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
| 416 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 417 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
| 417 kNumUsesPerDecaySpeedDivisorIncrement); | 418 kNumUsesPerDecaySpeedDivisorIncrement); |
| 418 | 419 |
| 419 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 420 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
| 420 0.5); | 421 0.5); |
| 421 } | 422 } |
| OLD | NEW |