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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 7337007: Introduce a field trial for Instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix onchange handling 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/instant/instant_controller.h" 5 #include "chrome/browser/instant/instant_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/rand_util.h"
10 #include "build/build_config.h" 11 #include "build/build_config.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h" 12 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "chrome/browser/instant/instant_delegate.h" 13 #include "chrome/browser/instant/instant_delegate.h"
14 #include "chrome/browser/instant/instant_field_trial.h"
13 #include "chrome/browser/instant/instant_loader.h" 15 #include "chrome/browser/instant/instant_loader.h"
14 #include "chrome/browser/instant/instant_loader_manager.h" 16 #include "chrome/browser/instant/instant_loader_manager.h"
15 #include "chrome/browser/instant/promo_counter.h" 17 #include "chrome/browser/instant/promo_counter.h"
16 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
17 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/browser/prerender/prerender_manager.h" 20 #include "chrome/browser/prerender/prerender_manager.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/search_engines/template_url.h" 22 #include "chrome/browser/search_engines/template_url.h"
21 #include "chrome/browser/search_engines/template_url_service.h" 23 #include "chrome/browser/search_engines/template_url_service.h"
22 #include "chrome/browser/search_engines/template_url_service_factory.h" 24 #include "chrome/browser/search_engines/template_url_service_factory.h"
(...skipping 19 matching lines...) Expand all
42 InstantController::InstantController(Profile* profile, 44 InstantController::InstantController(Profile* profile,
43 InstantDelegate* delegate) 45 InstantDelegate* delegate)
44 : delegate_(delegate), 46 : delegate_(delegate),
45 tab_contents_(NULL), 47 tab_contents_(NULL),
46 is_active_(false), 48 is_active_(false),
47 displayable_loader_(NULL), 49 displayable_loader_(NULL),
48 commit_on_mouse_up_(false), 50 commit_on_mouse_up_(false),
49 last_transition_type_(PageTransition::LINK), 51 last_transition_type_(PageTransition::LINK),
50 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) { 52 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) {
51 PrefService* service = profile->GetPrefs(); 53 PrefService* service = profile->GetPrefs();
52 if (service) { 54 if (service &&
53 // kInstantWasEnabledOnce was added after instant, set it now to make sure 55 InstantFieldTrial::GetGroup(profile) == InstantFieldTrial::INACTIVE) {
54 // it is correctly set. 56 // kInstantEnabledOnce was added after instant, set it now to make sure it
57 // is correctly set.
55 service->SetBoolean(prefs::kInstantEnabledOnce, true); 58 service->SetBoolean(prefs::kInstantEnabledOnce, true);
56 } 59 }
57 } 60 }
58 61
59 InstantController::~InstantController() { 62 InstantController::~InstantController() {
60 } 63 }
61 64
62 // static 65 // static
63 void InstantController::RegisterUserPrefs(PrefService* prefs) { 66 void InstantController::RegisterUserPrefs(PrefService* prefs) {
64 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, 67 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown,
65 false, 68 false,
66 PrefService::UNSYNCABLE_PREF); 69 PrefService::UNSYNCABLE_PREF);
67 prefs->RegisterBooleanPref(prefs::kInstantEnabled, 70 prefs->RegisterBooleanPref(prefs::kInstantEnabled,
68 false, 71 false,
69 PrefService::UNSYNCABLE_PREF); 72 PrefService::UNSYNCABLE_PREF);
70 prefs->RegisterBooleanPref(prefs::kInstantEnabledOnce, 73 prefs->RegisterBooleanPref(prefs::kInstantEnabledOnce,
71 false, 74 false,
72 PrefService::UNSYNCABLE_PREF); 75 PrefService::UNSYNCABLE_PREF);
73 prefs->RegisterInt64Pref(prefs::kInstantEnabledTime, 76 prefs->RegisterInt64Pref(prefs::kInstantEnabledTime,
74 false, 77 false,
75 PrefService::UNSYNCABLE_PREF); 78 PrefService::UNSYNCABLE_PREF);
79 prefs->RegisterIntegerPref(prefs::kInstantFieldTrialRandomDraw,
80 base::RandInt(0, 9999),
81 PrefService::UNSYNCABLE_PREF);
76 PromoCounter::RegisterUserPrefs(prefs, prefs::kInstantPromo); 82 PromoCounter::RegisterUserPrefs(prefs, prefs::kInstantPromo);
77 } 83 }
78 84
79 // static 85 // static
80 void InstantController::RecordMetrics(Profile* profile) { 86 void InstantController::RecordMetrics(Profile* profile) {
81 if (!IsEnabled(profile)) 87 if (!IsEnabled(profile))
82 return; 88 return;
83 89
84 PrefService* service = profile->GetPrefs(); 90 PrefService* service = profile->GetPrefs();
85 if (service) { 91 if (service) {
86 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime); 92 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime);
87 if (!enable_time) { 93 if (!enable_time) {
88 service->SetInt64(prefs::kInstantEnabledTime, 94 service->SetInt64(prefs::kInstantEnabledTime,
89 base::Time::Now().ToInternalValue()); 95 base::Time::Now().ToInternalValue());
90 } else { 96 } else {
91 base::TimeDelta delta = 97 base::TimeDelta delta =
92 base::Time::Now() - base::Time::FromInternalValue(enable_time); 98 base::Time::Now() - base::Time::FromInternalValue(enable_time);
93 // Histogram from 1 hour to 30 days. 99 // Histogram from 1 hour to 30 days.
94 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.EnabledTime.Predictive", 100 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.EnabledTime.Predictive",
95 delta.InHours(), 1, 30 * 24, 50); 101 delta.InHours(), 1, 30 * 24, 50);
96 } 102 }
97 } 103 }
98 } 104 }
99 105
100 // static 106 // static
101 bool InstantController::IsEnabled(Profile* profile) { 107 bool InstantController::IsEnabled(Profile* profile) {
102 PrefService* prefs = profile->GetPrefs(); 108 PrefService* prefs = profile->GetPrefs();
103 return prefs->GetBoolean(prefs::kInstantEnabled); 109 return prefs->GetBoolean(prefs::kInstantEnabled) ||
110 InstantFieldTrial::IsExperimentGroup(profile);
104 } 111 }
105 112
106 // static 113 // static
107 void InstantController::Enable(Profile* profile) { 114 void InstantController::Enable(Profile* profile) {
108 PromoCounter* promo_counter = profile->GetInstantPromoCounter(); 115 PromoCounter* promo_counter = profile->GetInstantPromoCounter();
109 if (promo_counter) 116 if (promo_counter)
110 promo_counter->Hide(); 117 promo_counter->Hide();
111 118
112 PrefService* service = profile->GetPrefs(); 119 PrefService* service = profile->GetPrefs();
113 if (!service) 120 if (!service)
114 return; 121 return;
115 122
123 service->SetBoolean(prefs::kInstantEnabledOnce, true);
116 service->SetBoolean(prefs::kInstantEnabled, true); 124 service->SetBoolean(prefs::kInstantEnabled, true);
117 service->SetBoolean(prefs::kInstantConfirmDialogShown, true); 125 service->SetBoolean(prefs::kInstantConfirmDialogShown, true);
118 service->SetInt64(prefs::kInstantEnabledTime, 126 service->SetInt64(prefs::kInstantEnabledTime,
119 base::Time::Now().ToInternalValue()); 127 base::Time::Now().ToInternalValue());
120 service->SetBoolean(prefs::kInstantEnabledOnce, true);
121 } 128 }
122 129
123 // static 130 // static
124 void InstantController::Disable(Profile* profile) { 131 void InstantController::Disable(Profile* profile) {
125 PrefService* service = profile->GetPrefs(); 132 PrefService* service = profile->GetPrefs();
126 if (!service || !IsEnabled(profile)) 133 if (!service || !IsEnabled(profile))
127 return; 134 return;
128 135
129 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime); 136 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime);
130 if (enable_time) { 137 if (enable_time) {
131 base::TimeDelta delta = 138 base::TimeDelta delta =
132 base::Time::Now() - base::Time::FromInternalValue(enable_time); 139 base::Time::Now() - base::Time::FromInternalValue(enable_time);
133 // Histogram from 1 minute to 10 days. 140 // Histogram from 1 minute to 10 days.
134 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.TimeToDisable.Predictive", 141 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.TimeToDisable.Predictive",
135 delta.InMinutes(), 1, 60 * 24 * 10, 50); 142 delta.InMinutes(), 1, 60 * 24 * 10, 50);
136 } 143 }
137 144
145 if (InstantFieldTrial::IsExperimentGroup(profile)) {
146 UMA_HISTOGRAM_COUNTS(
147 "Instant.FieldTrialOptOut." + InstantFieldTrial::GetGroupName(profile),
148 1);
149 }
150
138 service->SetBoolean(prefs::kInstantEnabledOnce, true); 151 service->SetBoolean(prefs::kInstantEnabledOnce, true);
139 service->SetBoolean(prefs::kInstantEnabled, false); 152 service->SetBoolean(prefs::kInstantEnabled, false);
140 } 153 }
141 154
142 // static 155 // static
143 bool InstantController::CommitIfCurrent(InstantController* controller) { 156 bool InstantController::CommitIfCurrent(InstantController* controller) {
144 if (controller && controller->IsCurrent()) { 157 if (controller && controller->IsCurrent()) {
145 controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); 158 controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
146 return true; 159 return true;
147 } 160 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return; 383 return;
371 } 384 }
372 385
373 DestroyPreviewContents(); 386 DestroyPreviewContents();
374 } 387 }
375 #endif 388 #endif
376 389
377 void InstantController::OnAutocompleteGotFocus( 390 void InstantController::OnAutocompleteGotFocus(
378 TabContentsWrapper* tab_contents) { 391 TabContentsWrapper* tab_contents) {
379 CommandLine* cl = CommandLine::ForCurrentProcess(); 392 CommandLine* cl = CommandLine::ForCurrentProcess();
380 if (!cl->HasSwitch(switches::kPreloadInstantSearch)) 393 if (!cl->HasSwitch(switches::kPreloadInstantSearch) &&
394 !InstantFieldTrial::IsExperimentGroup(tab_contents->profile())) {
381 return; 395 return;
396 }
382 397
383 if (is_active_) 398 if (is_active_)
384 return; 399 return;
385 400
386 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( 401 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(
387 tab_contents->profile()); 402 tab_contents->profile());
388 if (!model) 403 if (!model)
389 return; 404 return;
390 405
391 const TemplateURL* template_url = model->GetDefaultSearchProvider(); 406 const TemplateURL* template_url = model->GetDefaultSearchProvider();
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 713
699 // Extension keywords don't have a real destination URL. 714 // Extension keywords don't have a real destination URL.
700 if (match.template_url && match.template_url->IsExtensionKeyword()) 715 if (match.template_url && match.template_url->IsExtensionKeyword())
701 return PREVIEW_CONDITION_EXTENSION_KEYWORD; 716 return PREVIEW_CONDITION_EXTENSION_KEYWORD;
702 717
703 // Was the host blacklisted? 718 // Was the host blacklisted?
704 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) 719 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host()))
705 return PREVIEW_CONDITION_BLACKLISTED; 720 return PREVIEW_CONDITION_BLACKLISTED;
706 721
707 const CommandLine* cl = CommandLine::ForCurrentProcess(); 722 const CommandLine* cl = CommandLine::ForCurrentProcess();
708 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && 723 if ((cl->HasSwitch(switches::kRestrictInstantToSearch) ||
724 InstantFieldTrial::IsExperimentGroup(tab_contents_->profile())) &&
709 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && 725 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED &&
710 match.type != AutocompleteMatch::SEARCH_HISTORY && 726 match.type != AutocompleteMatch::SEARCH_HISTORY &&
711 match.type != AutocompleteMatch::SEARCH_SUGGEST && 727 match.type != AutocompleteMatch::SEARCH_SUGGEST &&
712 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { 728 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) {
713 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; 729 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY;
714 } 730 }
715 731
716 return PREVIEW_CONDITION_SUCCESS; 732 return PREVIEW_CONDITION_SUCCESS;
717 } 733 }
718 734
(...skipping 14 matching lines...) Expand all
733 if (destroy_factory_.empty()) { 749 if (destroy_factory_.empty()) {
734 MessageLoop::current()->PostTask( 750 MessageLoop::current()->PostTask(
735 FROM_HERE, destroy_factory_.NewRunnableMethod( 751 FROM_HERE, destroy_factory_.NewRunnableMethod(
736 &InstantController::DestroyLoaders)); 752 &InstantController::DestroyLoaders));
737 } 753 }
738 } 754 }
739 755
740 void InstantController::DestroyLoaders() { 756 void InstantController::DestroyLoaders() {
741 loaders_to_destroy_.reset(); 757 loaders_to_destroy_.reset();
742 } 758 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698