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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
18 #include "chrome/browser/autocomplete/bookmark_provider.h" | |
18 #include "chrome/browser/autocomplete/builtin_provider.h" | 19 #include "chrome/browser/autocomplete/builtin_provider.h" |
19 #include "chrome/browser/autocomplete/extension_app_provider.h" | 20 #include "chrome/browser/autocomplete/extension_app_provider.h" |
20 #include "chrome/browser/autocomplete/history_contents_provider.h" | 21 #include "chrome/browser/autocomplete/history_contents_provider.h" |
21 #include "chrome/browser/autocomplete/history_quick_provider.h" | 22 #include "chrome/browser/autocomplete/history_quick_provider.h" |
22 #include "chrome/browser/autocomplete/history_url_provider.h" | 23 #include "chrome/browser/autocomplete/history_url_provider.h" |
23 #include "chrome/browser/autocomplete/keyword_provider.h" | 24 #include "chrome/browser/autocomplete/keyword_provider.h" |
24 #include "chrome/browser/autocomplete/search_provider.h" | 25 #include "chrome/browser/autocomplete/search_provider.h" |
25 #include "chrome/browser/autocomplete/shortcuts_provider.h" | 26 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
26 #include "chrome/browser/autocomplete/zero_suggest_provider.h" | 27 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/search_engines/template_url.h" | 29 #include "chrome/browser/search_engines/template_url.h" |
29 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/chrome_switches.h" | |
30 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
32 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
33 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
34 | 36 |
35 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
36 #include "chrome/browser/autocomplete/contact_provider_chromeos.h" | 38 #include "chrome/browser/autocomplete/contact_provider_chromeos.h" |
37 #include "chrome/browser/chromeos/contacts/contact_manager.h" | 39 #include "chrome/browser/chromeos/contacts/contact_manager.h" |
38 #endif | 40 #endif |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 // Converts the given type to an integer based on the AQS specification. | 44 // Converts the given type to an integer based on the AQS specification. |
43 // For more details, See http://goto.google.com/binary-clients-logging . | 45 // For more details, See http://goto.google.com/binary-clients-logging . |
44 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { | 46 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { |
45 switch (type) { | 47 switch (type) { |
46 case AutocompleteMatch::SEARCH_SUGGEST: return 0; | 48 case AutocompleteMatch::SEARCH_SUGGEST: return 0; |
47 case AutocompleteMatch::NAVSUGGEST: return 5; | 49 case AutocompleteMatch::NAVSUGGEST: return 5; |
48 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57; | 50 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57; |
49 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58; | 51 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58; |
50 case AutocompleteMatch::SEARCH_HISTORY: return 59; | 52 case AutocompleteMatch::SEARCH_HISTORY: return 59; |
51 case AutocompleteMatch::HISTORY_URL: return 60; | 53 case AutocompleteMatch::HISTORY_URL: return 60; |
52 case AutocompleteMatch::HISTORY_TITLE: return 61; | 54 case AutocompleteMatch::HISTORY_TITLE: return 61; |
53 case AutocompleteMatch::HISTORY_BODY: return 62; | 55 case AutocompleteMatch::HISTORY_BODY: return 62; |
54 case AutocompleteMatch::HISTORY_KEYWORD: return 63; | 56 case AutocompleteMatch::HISTORY_KEYWORD: return 63; |
57 case AutocompleteMatch::BOOKMARK_TITLE: return 65; | |
58 // NOTE: Default is equivalent to OMNIBOX_OTHER and must remain 64. | |
Peter Kasting
2012/10/04 20:40:31
OMNIBOX_OTHER? What is that?
mrossetti
2012/10/05 22:10:04
Please see email sent separately.
| |
55 default: return 64; | 59 default: return 64; |
56 } | 60 } |
57 } | 61 } |
58 | 62 |
59 // Appends available autocompletion of the given type and number to the existing | 63 // Appends available autocompletion of the given type and number to the existing |
60 // available autocompletions string, encoding according to the spec. | 64 // available autocompletions string, encoding according to the spec. |
61 void AppendAvailableAutocompletion(int type, | 65 void AppendAvailableAutocompletion(int type, |
62 int count, | 66 int count, |
63 std::string* autocompletions) { | 67 std::string* autocompletions) { |
64 if (!autocompletions->empty()) | 68 if (!autocompletions->empty()) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) | 134 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) |
131 providers_.push_back(new ShortcutsProvider(this, profile)); | 135 providers_.push_back(new ShortcutsProvider(this, profile)); |
132 | 136 |
133 // Create ZeroSuggest if it is enabled. | 137 // Create ZeroSuggest if it is enabled. |
134 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { | 138 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { |
135 zero_suggest_provider_ = ZeroSuggestProvider::Create(this, profile); | 139 zero_suggest_provider_ = ZeroSuggestProvider::Create(this, profile); |
136 if (zero_suggest_provider_) | 140 if (zero_suggest_provider_) |
137 providers_.push_back(zero_suggest_provider_); | 141 providers_.push_back(zero_suggest_provider_); |
138 } | 142 } |
139 | 143 |
144 // Disable the BookmarkProvider if there the switch says so. | |
Peter Kasting
2012/10/04 20:40:31
Nit: Comment adds nothing
mrossetti
2012/10/05 22:10:04
Done. (I was just following the pattern used for Z
| |
145 if ((provider_types & AutocompleteProvider::TYPE_BOOKMARK) && | |
146 !CommandLine::ForCurrentProcess()->HasSwitch( | |
147 switches::kDisableBookmarkAutocompleteProvider)) | |
148 providers_.push_back(new BookmarkProvider(this, profile)); | |
149 | |
140 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 150 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
141 (*i)->AddRef(); | 151 (*i)->AddRef(); |
142 } | 152 } |
143 | 153 |
144 AutocompleteController::~AutocompleteController() { | 154 AutocompleteController::~AutocompleteController() { |
145 // The providers may have tasks outstanding that hold refs to them. We need | 155 // The providers may have tasks outstanding that hold refs to them. We need |
146 // to ensure they won't call us back if they outlive us. (Practically, | 156 // to ensure they won't call us back if they outlive us. (Practically, |
147 // calling Stop() should also cancel those tasks and make it so that we hold | 157 // calling Stop() should also cancel those tasks and make it so that we hold |
148 // the only refs.) We also don't want to bother notifying anyone of our | 158 // the only refs.) We also don't want to bother notifying anyone of our |
149 // result changes here, because the notification observer is in the midst of | 159 // result changes here, because the notification observer is in the midst of |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 } | 472 } |
463 done_ = true; | 473 done_ = true; |
464 } | 474 } |
465 | 475 |
466 void AutocompleteController::StartExpireTimer() { | 476 void AutocompleteController::StartExpireTimer() { |
467 if (result_.HasCopiedMatches()) | 477 if (result_.HasCopiedMatches()) |
468 expire_timer_.Start(FROM_HERE, | 478 expire_timer_.Start(FROM_HERE, |
469 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 479 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
470 this, &AutocompleteController::ExpireCopiedEntries); | 480 this, &AutocompleteController::ExpireCopiedEntries); |
471 } | 481 } |
OLD | NEW |