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/format_macros.h" | 11 #include "base/format_macros.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 17 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
17 #include "chrome/browser/autocomplete/builtin_provider.h" | 18 #include "chrome/browser/autocomplete/builtin_provider.h" |
18 #include "chrome/browser/autocomplete/extension_app_provider.h" | 19 #include "chrome/browser/autocomplete/extension_app_provider.h" |
19 #include "chrome/browser/autocomplete/history_contents_provider.h" | 20 #include "chrome/browser/autocomplete/history_contents_provider.h" |
20 #include "chrome/browser/autocomplete/history_quick_provider.h" | 21 #include "chrome/browser/autocomplete/history_quick_provider.h" |
21 #include "chrome/browser/autocomplete/history_url_provider.h" | 22 #include "chrome/browser/autocomplete/history_url_provider.h" |
22 #include "chrome/browser/autocomplete/keyword_provider.h" | 23 #include "chrome/browser/autocomplete/keyword_provider.h" |
23 #include "chrome/browser/autocomplete/search_provider.h" | 24 #include "chrome/browser/autocomplete/search_provider.h" |
24 #include "chrome/browser/autocomplete/shortcuts_provider.h" | 25 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/chrome_switches.h" |
28 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
29 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
30 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
32 | 34 |
| 35 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/autocomplete/contact_provider_chromeos.h" |
| 37 #include "chrome/browser/chromeos/contacts/contact_manager.h" |
| 38 #endif |
| 39 |
33 namespace { | 40 namespace { |
34 | 41 |
35 // Converts the given type to an integer based on the AQS specification. | 42 // Converts the given type to an integer based on the AQS specification. |
36 // For more details, See http://goto.google.com/binary-clients-logging . | 43 // For more details, See http://goto.google.com/binary-clients-logging . |
37 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { | 44 int AutocompleteMatchToAssistedQueryType(const AutocompleteMatch::Type& type) { |
38 switch (type) { | 45 switch (type) { |
39 case AutocompleteMatch::SEARCH_SUGGEST: return 0; | 46 case AutocompleteMatch::SEARCH_SUGGEST: return 0; |
40 case AutocompleteMatch::NAVSUGGEST: return 5; | 47 case AutocompleteMatch::NAVSUGGEST: return 5; |
41 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57; | 48 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57; |
42 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58; | 49 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // HistoryURLProvider to not search titles once HQP is turned on permanently. | 101 // HistoryURLProvider to not search titles once HQP is turned on permanently. |
95 // TODO(jcivelli): Enable the History Quick Provider and figure out why it | 102 // TODO(jcivelli): Enable the History Quick Provider and figure out why it |
96 // reports the wrong results for some pages. | 103 // reports the wrong results for some pages. |
97 bool hqp_enabled = false; | 104 bool hqp_enabled = false; |
98 #endif // !OS_ANDROID | 105 #endif // !OS_ANDROID |
99 providers_.push_back(new HistoryURLProvider(this, profile)); | 106 providers_.push_back(new HistoryURLProvider(this, profile)); |
100 providers_.push_back(new ShortcutsProvider(this, profile)); | 107 providers_.push_back(new ShortcutsProvider(this, profile)); |
101 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); | 108 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); |
102 providers_.push_back(new BuiltinProvider(this, profile)); | 109 providers_.push_back(new BuiltinProvider(this, profile)); |
103 providers_.push_back(new ExtensionAppProvider(this, profile)); | 110 providers_.push_back(new ExtensionAppProvider(this, profile)); |
| 111 #if defined(OS_CHROMEOS) |
| 112 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableContacts)) { |
| 113 providers_.push_back( |
| 114 new ContactProvider( |
| 115 this, |
| 116 profile, |
| 117 contacts::ContactManager::GetInstance()->GetWeakPtr())); |
| 118 } |
| 119 #endif |
104 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 120 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
105 (*i)->AddRef(); | 121 (*i)->AddRef(); |
106 } | 122 } |
107 | 123 |
108 AutocompleteController::~AutocompleteController() { | 124 AutocompleteController::~AutocompleteController() { |
109 // The providers may have tasks outstanding that hold refs to them. We need | 125 // The providers may have tasks outstanding that hold refs to them. We need |
110 // to ensure they won't call us back if they outlive us. (Practically, | 126 // to ensure they won't call us back if they outlive us. (Practically, |
111 // calling Stop() should also cancel those tasks and make it so that we hold | 127 // calling Stop() should also cancel those tasks and make it so that we hold |
112 // the only refs.) We also don't want to bother notifying anyone of our | 128 // the only refs.) We also don't want to bother notifying anyone of our |
113 // result changes here, because the notification observer is in the midst of | 129 // result changes here, because the notification observer is in the midst of |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 416 } |
401 done_ = true; | 417 done_ = true; |
402 } | 418 } |
403 | 419 |
404 void AutocompleteController::StartExpireTimer() { | 420 void AutocompleteController::StartExpireTimer() { |
405 if (result_.HasCopiedMatches()) | 421 if (result_.HasCopiedMatches()) |
406 expire_timer_.Start(FROM_HERE, | 422 expire_timer_.Start(FROM_HERE, |
407 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 423 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
408 this, &AutocompleteController::ExpireCopiedEntries); | 424 this, &AutocompleteController::ExpireCopiedEntries); |
409 } | 425 } |
OLD | NEW |