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

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

Issue 7337007: Introduce a field trial for Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reverting ifdef'ed constructor Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "chrome/browser/autocomplete/autocomplete.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/number_formatting.h" 11 #include "base/i18n/number_formatting.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
17 #include "chrome/browser/autocomplete/autocomplete_match.h" 17 #include "chrome/browser/autocomplete/autocomplete_match.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/bookmarks/bookmark_model.h" 26 #include "chrome/browser/bookmarks/bookmark_model.h"
27 #include "chrome/browser/external_protocol/external_protocol_handler.h" 27 #include "chrome/browser/external_protocol/external_protocol_handler.h"
28 #include "chrome/browser/instant/instant_field_trial.h"
28 #include "chrome/browser/net/url_fixer_upper.h" 29 #include "chrome/browser/net/url_fixer_upper.h"
29 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/profiles/profile_io_data.h" 32 #include "chrome/browser/profiles/profile_io_data.h"
32 #include "chrome/browser/ui/webui/history_ui.h" 33 #include "chrome/browser/ui/webui/history_ui.h"
33 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
34 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "content/common/notification_service.h" 38 #include "content/common/notification_service.h"
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // any copied entries. We do this from the time the user stopped typing as some 787 // any copied entries. We do this from the time the user stopped typing as some
787 // providers (such as SearchProvider) wait for the user to stop typing before 788 // providers (such as SearchProvider) wait for the user to stop typing before
788 // they initiate a query. 789 // they initiate a query.
789 static const int kExpireTimeMS = 500; 790 static const int kExpireTimeMS = 500;
790 791
791 AutocompleteController::AutocompleteController( 792 AutocompleteController::AutocompleteController(
792 Profile* profile, 793 Profile* profile,
793 AutocompleteControllerDelegate* delegate) 794 AutocompleteControllerDelegate* delegate)
794 : delegate_(delegate), 795 : delegate_(delegate),
795 done_(true), 796 done_(true),
796 in_start_(false) { 797 in_start_(false),
798 profile_(profile) {
797 search_provider_ = new SearchProvider(this, profile); 799 search_provider_ = new SearchProvider(this, profile);
798 providers_.push_back(search_provider_); 800 providers_.push_back(search_provider_);
799 // TODO(mrossetti): Remove the following and permanently modify the 801 // TODO(mrossetti): Remove the following and permanently modify the
800 // HistoryURLProvider to not search titles once HQP is turned on permanently. 802 // HistoryURLProvider to not search titles once HQP is turned on permanently.
801 bool hqp_enabled = !CommandLine::ForCurrentProcess()->HasSwitch( 803 bool hqp_enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
802 switches::kDisableHistoryQuickProvider); 804 switches::kDisableHistoryQuickProvider);
803 if (hqp_enabled) 805 if (hqp_enabled)
804 providers_.push_back(new HistoryQuickProvider(this, profile)); 806 providers_.push_back(new HistoryQuickProvider(this, profile));
805 if (CommandLine::ForCurrentProcess()->HasSwitch( 807 if (CommandLine::ForCurrentProcess()->HasSwitch(
806 switches::kEnableShortcutsProvider)) 808 switches::kEnableShortcutsProvider))
(...skipping 25 matching lines...) Expand all
832 834
833 providers_.clear(); // Not really necessary. 835 providers_.clear(); // Not really necessary.
834 } 836 }
835 837
836 void AutocompleteController::SetProfile(Profile* profile) { 838 void AutocompleteController::SetProfile(Profile* profile) {
837 Stop(true); 839 Stop(true);
838 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) 840 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
839 (*i)->SetProfile(profile); 841 (*i)->SetProfile(profile);
840 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a 842 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a
841 // different profile. 843 // different profile.
844 profile_ = profile;
842 } 845 }
843 846
844 void AutocompleteController::Start( 847 void AutocompleteController::Start(
845 const string16& text, 848 const string16& text,
846 const string16& desired_tld, 849 const string16& desired_tld,
847 bool prevent_inline_autocomplete, 850 bool prevent_inline_autocomplete,
848 bool prefer_keyword, 851 bool prefer_keyword,
849 bool allow_exact_keyword_match, 852 bool allow_exact_keyword_match,
850 AutocompleteInput::MatchesRequested matches_requested) { 853 AutocompleteInput::MatchesRequested matches_requested) {
851 const string16 old_input_text(input_.text()); 854 const string16 old_input_text(input_.text());
(...skipping 21 matching lines...) Expand all
873 base::TimeTicks start_time = base::TimeTicks::Now(); 876 base::TimeTicks start_time = base::TimeTicks::Now();
874 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); 877 for (ACProviders::iterator i(providers_.begin()); i != providers_.end();
875 ++i) { 878 ++i) {
876 (*i)->Start(input_, minimal_changes); 879 (*i)->Start(input_, minimal_changes);
877 if (matches_requested != AutocompleteInput::ALL_MATCHES) 880 if (matches_requested != AutocompleteInput::ALL_MATCHES)
878 DCHECK((*i)->done()); 881 DCHECK((*i)->done());
879 } 882 }
880 if (matches_requested == AutocompleteInput::ALL_MATCHES && 883 if (matches_requested == AutocompleteInput::ALL_MATCHES &&
881 (text.length() < 6)) { 884 (text.length() < 6)) {
882 base::TimeTicks end_time = base::TimeTicks::Now(); 885 base::TimeTicks end_time = base::TimeTicks::Now();
883 std::string name = "Omnibox.QueryTime." + base::IntToString(text.length()); 886 std::string name = "Omnibox.QueryTime." +
887 InstantFieldTrial::GetGroupName(profile_) +
888 base::IntToString(text.length());
884 base::Histogram* counter = base::Histogram::FactoryGet( 889 base::Histogram* counter = base::Histogram::FactoryGet(
885 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); 890 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
886 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); 891 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds()));
887 } 892 }
888 in_start_ = false; 893 in_start_ = false;
889 CheckIfDone(); 894 CheckIfDone();
890 UpdateResult(true); 895 UpdateResult(true);
891 896
892 if (!done_) 897 if (!done_)
893 StartExpireTimer(); 898 StartExpireTimer();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 } 1033 }
1029 } 1034 }
1030 done_ = true; 1035 done_ = true;
1031 } 1036 }
1032 1037
1033 void AutocompleteController::StartExpireTimer() { 1038 void AutocompleteController::StartExpireTimer() {
1034 if (result_.HasCopiedMatches()) 1039 if (result_.HasCopiedMatches())
1035 expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS), 1040 expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS),
1036 this, &AutocompleteController::ExpireCopiedEntries); 1041 this, &AutocompleteController::ExpireCopiedEntries);
1037 } 1042 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete.h ('k') | chrome/browser/autocomplete/autocomplete_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698