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

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, 3 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"
(...skipping 18 matching lines...) Expand all
46 switch (type) { 47 switch (type) {
47 case AutocompleteMatch::SEARCH_SUGGEST: return 0; 48 case AutocompleteMatch::SEARCH_SUGGEST: return 0;
48 case AutocompleteMatch::NAVSUGGEST: return 5; 49 case AutocompleteMatch::NAVSUGGEST: return 5;
49 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57; 50 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: return 57;
50 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58; 51 case AutocompleteMatch::URL_WHAT_YOU_TYPED: return 58;
51 case AutocompleteMatch::SEARCH_HISTORY: return 59; 52 case AutocompleteMatch::SEARCH_HISTORY: return 59;
52 case AutocompleteMatch::HISTORY_URL: return 60; 53 case AutocompleteMatch::HISTORY_URL: return 60;
53 case AutocompleteMatch::HISTORY_TITLE: return 61; 54 case AutocompleteMatch::HISTORY_TITLE: return 61;
54 case AutocompleteMatch::HISTORY_BODY: return 62; 55 case AutocompleteMatch::HISTORY_BODY: return 62;
55 case AutocompleteMatch::HISTORY_KEYWORD: return 63; 56 case AutocompleteMatch::HISTORY_KEYWORD: return 63;
56 default: return 64; 57 default: return 64;
Mark P 2012/09/28 00:55:13 Please look into whether you need to add something
mrossetti 2012/10/02 00:44:16 Done.
57 } 58 }
58 } 59 }
59 60
60 // Appends available autocompletion of the given type and number to the existing 61 // Appends available autocompletion of the given type and number to the existing
61 // available autocompletions string, encoding according to the spec. 62 // available autocompletions string, encoding according to the spec.
62 void AppendAvailableAutocompletion(int type, 63 void AppendAvailableAutocompletion(int type,
63 int count, 64 int count,
64 std::string* autocompletions) { 65 std::string* autocompletions) {
65 if (!autocompletions->empty()) 66 if (!autocompletions->empty())
66 autocompletions->append("j"); 67 autocompletions->append("j");
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 providers_.push_back(new ShortcutsProvider(this, profile)); 133 providers_.push_back(new ShortcutsProvider(this, profile));
133 134
134 CommandLine* cl = CommandLine::ForCurrentProcess(); 135 CommandLine* cl = CommandLine::ForCurrentProcess();
135 if ((provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) && 136 if ((provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) &&
136 cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) { 137 cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) {
137 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile, 138 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile,
138 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix)); 139 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix));
139 providers_.push_back(zero_suggest_provider_); 140 providers_.push_back(zero_suggest_provider_);
140 } 141 }
141 142
143 // Disable the BookmarkProvider if there the switch says so.
144 if ((provider_types & AutocompleteProvider::TYPE_BOOKMARK) &&
145 !cl->HasSwitch(switches::kDisableBookmarkAutocompleteProvider))
146 providers_.push_back(new BookmarkProvider(this, profile));
147
142 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) 148 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
143 (*i)->AddRef(); 149 (*i)->AddRef();
144 } 150 }
145 151
146 AutocompleteController::~AutocompleteController() { 152 AutocompleteController::~AutocompleteController() {
147 // The providers may have tasks outstanding that hold refs to them. We need 153 // The providers may have tasks outstanding that hold refs to them. We need
148 // to ensure they won't call us back if they outlive us. (Practically, 154 // to ensure they won't call us back if they outlive us. (Practically,
149 // calling Stop() should also cancel those tasks and make it so that we hold 155 // calling Stop() should also cancel those tasks and make it so that we hold
150 // the only refs.) We also don't want to bother notifying anyone of our 156 // the only refs.) We also don't want to bother notifying anyone of our
151 // result changes here, because the notification observer is in the midst of 157 // result changes here, because the notification observer is in the midst of
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 470 }
465 done_ = true; 471 done_ = true;
466 } 472 }
467 473
468 void AutocompleteController::StartExpireTimer() { 474 void AutocompleteController::StartExpireTimer() {
469 if (result_.HasCopiedMatches()) 475 if (result_.HasCopiedMatches())
470 expire_timer_.Start(FROM_HERE, 476 expire_timer_.Start(FROM_HERE,
471 base::TimeDelta::FromMilliseconds(kExpireTimeMS), 477 base::TimeDelta::FromMilliseconds(kExpireTimeMS),
472 this, &AutocompleteController::ExpireCopiedEntries); 478 this, &AutocompleteController::ExpireCopiedEntries);
473 } 479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698