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/builtin_provider.h" | 18 #include "chrome/browser/autocomplete/builtin_provider.h" |
19 #include "chrome/browser/autocomplete/extension_app_provider.h" | 19 #include "chrome/browser/autocomplete/extension_app_provider.h" |
20 #include "chrome/browser/autocomplete/history_contents_provider.h" | 20 #include "chrome/browser/autocomplete/history_contents_provider.h" |
21 #include "chrome/browser/autocomplete/history_quick_provider.h" | 21 #include "chrome/browser/autocomplete/history_quick_provider.h" |
22 #include "chrome/browser/autocomplete/history_url_provider.h" | 22 #include "chrome/browser/autocomplete/history_url_provider.h" |
23 #include "chrome/browser/autocomplete/keyword_provider.h" | 23 #include "chrome/browser/autocomplete/keyword_provider.h" |
24 #include "chrome/browser/autocomplete/search_provider.h" | 24 #include "chrome/browser/autocomplete/search_provider.h" |
25 #include "chrome/browser/autocomplete/shortcuts_provider.h" | 25 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
26 #include "chrome/browser/autocomplete/zero_suggest_provider.h" | 26 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/search_engines/template_url.h" | 28 #include "chrome/browser/search_engines/template_url.h" |
29 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_switches.h" | |
31 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
32 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
33 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
34 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
35 | 34 |
36 namespace { | 35 namespace { |
37 | 36 |
38 // Converts the given type to an integer based on the AQS specification. | 37 // Converts the given type to an integer based on the AQS specification. |
39 // For more details, See http://goto.google.com/binary-clients-logging . | 38 // For more details, See http://goto.google.com/binary-clients-logging . |
40 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { | 39 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // HistoryURLProvider to not search titles once HQP is turned on permanently. | 98 // HistoryURLProvider to not search titles once HQP is turned on permanently. |
100 // TODO(jcivelli): Enable the History Quick Provider and figure out why it | 99 // TODO(jcivelli): Enable the History Quick Provider and figure out why it |
101 // reports the wrong results for some pages. | 100 // reports the wrong results for some pages. |
102 bool hqp_enabled = false; | 101 bool hqp_enabled = false; |
103 #endif // !OS_ANDROID | 102 #endif // !OS_ANDROID |
104 providers_.push_back(new HistoryURLProvider(this, profile)); | 103 providers_.push_back(new HistoryURLProvider(this, profile)); |
105 providers_.push_back(new ShortcutsProvider(this, profile)); | 104 providers_.push_back(new ShortcutsProvider(this, profile)); |
106 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); | 105 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); |
107 providers_.push_back(new BuiltinProvider(this, profile)); | 106 providers_.push_back(new BuiltinProvider(this, profile)); |
108 providers_.push_back(new ExtensionAppProvider(this, profile)); | 107 providers_.push_back(new ExtensionAppProvider(this, profile)); |
109 // Create ZeroSuggest if its switch is present. | 108 |
110 CommandLine* cl = CommandLine::ForCurrentProcess(); | 109 // Create ZeroSuggest if it is enabled. |
111 if (cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) { | 110 zero_suggest_provider_ = ZeroSuggestProvider::Create(this, profile); |
112 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile, | 111 if (zero_suggest_provider_) { |
113 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix)); | |
114 providers_.push_back(zero_suggest_provider_); | 112 providers_.push_back(zero_suggest_provider_); |
115 } | 113 } |
| 114 |
116 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 115 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
117 (*i)->AddRef(); | 116 (*i)->AddRef(); |
118 } | 117 } |
119 | 118 |
120 AutocompleteController::~AutocompleteController() { | 119 AutocompleteController::~AutocompleteController() { |
121 // The providers may have tasks outstanding that hold refs to them. We need | 120 // The providers may have tasks outstanding that hold refs to them. We need |
122 // to ensure they won't call us back if they outlive us. (Practically, | 121 // to ensure they won't call us back if they outlive us. (Practically, |
123 // calling Stop() should also cancel those tasks and make it so that we hold | 122 // calling Stop() should also cancel those tasks and make it so that we hold |
124 // the only refs.) We also don't want to bother notifying anyone of our | 123 // the only refs.) We also don't want to bother notifying anyone of our |
125 // result changes here, because the notification observer is in the midst of | 124 // result changes here, because the notification observer is in the midst of |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 436 } |
438 done_ = true; | 437 done_ = true; |
439 } | 438 } |
440 | 439 |
441 void AutocompleteController::StartExpireTimer() { | 440 void AutocompleteController::StartExpireTimer() { |
442 if (result_.HasCopiedMatches()) | 441 if (result_.HasCopiedMatches()) |
443 expire_timer_.Start(FROM_HERE, | 442 expire_timer_.Start(FROM_HERE, |
444 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 443 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
445 this, &AutocompleteController::ExpireCopiedEntries); | 444 this, &AutocompleteController::ExpireCopiedEntries); |
446 } | 445 } |
OLD | NEW |