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

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: 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 // any copied entries. We do this from the time the user stopped typing as some 781 // any copied entries. We do this from the time the user stopped typing as some
781 // providers (such as SearchProvider) wait for the user to stop typing before 782 // providers (such as SearchProvider) wait for the user to stop typing before
782 // they initiate a query. 783 // they initiate a query.
783 static const int kExpireTimeMS = 500; 784 static const int kExpireTimeMS = 500;
784 785
785 AutocompleteController::AutocompleteController( 786 AutocompleteController::AutocompleteController(
786 Profile* profile, 787 Profile* profile,
787 AutocompleteControllerDelegate* delegate) 788 AutocompleteControllerDelegate* delegate)
788 : delegate_(delegate), 789 : delegate_(delegate),
789 done_(true), 790 done_(true),
790 in_start_(false) { 791 in_start_(false),
792 profile_(profile) {
791 search_provider_ = new SearchProvider(this, profile); 793 search_provider_ = new SearchProvider(this, profile);
792 providers_.push_back(search_provider_); 794 providers_.push_back(search_provider_);
793 // TODO(mrossetti): Remove the following and permanently modify the 795 // TODO(mrossetti): Remove the following and permanently modify the
794 // HistoryURLProvider to not search titles once HQP is turned on permanently. 796 // HistoryURLProvider to not search titles once HQP is turned on permanently.
795 bool hqp_enabled = !CommandLine::ForCurrentProcess()->HasSwitch( 797 bool hqp_enabled = !CommandLine::ForCurrentProcess()->HasSwitch(
796 switches::kDisableHistoryQuickProvider); 798 switches::kDisableHistoryQuickProvider);
797 if (hqp_enabled) 799 if (hqp_enabled)
798 providers_.push_back(new HistoryQuickProvider(this, profile)); 800 providers_.push_back(new HistoryQuickProvider(this, profile));
799 if (CommandLine::ForCurrentProcess()->HasSwitch( 801 if (CommandLine::ForCurrentProcess()->HasSwitch(
800 switches::kEnableShortcutsProvider)) 802 switches::kEnableShortcutsProvider))
(...skipping 24 matching lines...) Expand all
825 827
826 providers_.clear(); // Not really necessary. 828 providers_.clear(); // Not really necessary.
827 } 829 }
828 830
829 void AutocompleteController::SetProfile(Profile* profile) { 831 void AutocompleteController::SetProfile(Profile* profile) {
830 Stop(true); 832 Stop(true);
831 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) 833 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
832 (*i)->SetProfile(profile); 834 (*i)->SetProfile(profile);
833 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a 835 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a
834 // different profile. 836 // different profile.
837 profile_ = profile;
835 } 838 }
836 839
837 void AutocompleteController::Start( 840 void AutocompleteController::Start(
838 const string16& text, 841 const string16& text,
839 const string16& desired_tld, 842 const string16& desired_tld,
840 bool prevent_inline_autocomplete, 843 bool prevent_inline_autocomplete,
841 bool prefer_keyword, 844 bool prefer_keyword,
842 bool allow_exact_keyword_match, 845 bool allow_exact_keyword_match,
843 AutocompleteInput::MatchesRequested matches_requested) { 846 AutocompleteInput::MatchesRequested matches_requested) {
844 const string16 old_input_text(input_.text()); 847 const string16 old_input_text(input_.text());
(...skipping 21 matching lines...) Expand all
866 base::TimeTicks start_time = base::TimeTicks::Now(); 869 base::TimeTicks start_time = base::TimeTicks::Now();
867 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); 870 for (ACProviders::iterator i(providers_.begin()); i != providers_.end();
868 ++i) { 871 ++i) {
869 (*i)->Start(input_, minimal_changes); 872 (*i)->Start(input_, minimal_changes);
870 if (matches_requested != AutocompleteInput::ALL_MATCHES) 873 if (matches_requested != AutocompleteInput::ALL_MATCHES)
871 DCHECK((*i)->done()); 874 DCHECK((*i)->done());
872 } 875 }
873 if (matches_requested == AutocompleteInput::ALL_MATCHES && 876 if (matches_requested == AutocompleteInput::ALL_MATCHES &&
874 (text.length() < 6)) { 877 (text.length() < 6)) {
875 base::TimeTicks end_time = base::TimeTicks::Now(); 878 base::TimeTicks end_time = base::TimeTicks::Now();
876 std::string name = "Omnibox.QueryTime." + base::IntToString(text.length()); 879 std::string name = "Omnibox.QueryTime." +
880 instant_field_trial::GetGroupName(profile_) +
881 base::IntToString(text.length());
877 base::Histogram* counter = base::Histogram::FactoryGet( 882 base::Histogram* counter = base::Histogram::FactoryGet(
878 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); 883 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag);
879 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); 884 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds()));
880 } 885 }
881 in_start_ = false; 886 in_start_ = false;
882 CheckIfDone(); 887 CheckIfDone();
883 UpdateResult(true); 888 UpdateResult(true);
884 889
885 if (!done_) 890 if (!done_)
886 StartExpireTimer(); 891 StartExpireTimer();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 } 1005 }
1001 } 1006 }
1002 done_ = true; 1007 done_ = true;
1003 } 1008 }
1004 1009
1005 void AutocompleteController::StartExpireTimer() { 1010 void AutocompleteController::StartExpireTimer() {
1006 if (result_.HasCopiedMatches()) 1011 if (result_.HasCopiedMatches())
1007 expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS), 1012 expire_timer_.Start(base::TimeDelta::FromMilliseconds(kExpireTimeMS),
1008 this, &AutocompleteController::ExpireCopiedEntries); 1013 this, &AutocompleteController::ExpireCopiedEntries);
1009 } 1014 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698