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

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

Issue 10913262: Implement Bookmark Autocomplete Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
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/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 must remain 64 for server-side compatability.
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
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 if ((provider_types & AutocompleteProvider::TYPE_BOOKMARK) &&
145 !CommandLine::ForCurrentProcess()->HasSwitch(
146 switches::kDisableBookmarkAutocompleteProvider))
147 providers_.push_back(new BookmarkProvider(this, profile));
148
140 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) 149 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
141 (*i)->AddRef(); 150 (*i)->AddRef();
142 } 151 }
143 152
144 AutocompleteController::~AutocompleteController() { 153 AutocompleteController::~AutocompleteController() {
145 // The providers may have tasks outstanding that hold refs to them. We need 154 // 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, 155 // 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 156 // 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 157 // 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 158 // result changes here, because the notification observer is in the midst of
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 471 }
463 done_ = true; 472 done_ = true;
464 } 473 }
465 474
466 void AutocompleteController::StartExpireTimer() { 475 void AutocompleteController::StartExpireTimer() {
467 if (result_.HasCopiedMatches()) 476 if (result_.HasCopiedMatches())
468 expire_timer_.Start(FROM_HERE, 477 expire_timer_.Start(FROM_HERE,
469 base::TimeDelta::FromMilliseconds(kExpireTimeMS), 478 base::TimeDelta::FromMilliseconds(kExpireTimeMS),
470 this, &AutocompleteController::ExpireCopiedEntries); 479 this, &AutocompleteController::ExpireCopiedEntries);
471 } 480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698