OLD | NEW |
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 Loading... |
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->RegisterDoublePref(prefs::kInstantFieldTrialRandomDraw, |
| 80 base::RandDouble(), |
| 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) |
(...skipping 14 matching lines...) Expand all Loading... |
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 |
| 151 service->SetBoolean(prefs::kInstantEnabledOnce, true); |
138 service->SetBoolean(prefs::kInstantEnabled, false); | 152 service->SetBoolean(prefs::kInstantEnabled, false); |
139 } | 153 } |
140 | 154 |
141 // static | 155 // static |
142 bool InstantController::CommitIfCurrent(InstantController* controller) { | 156 bool InstantController::CommitIfCurrent(InstantController* controller) { |
143 if (controller && controller->IsCurrent()) { | 157 if (controller && controller->IsCurrent()) { |
144 controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); | 158 controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); |
145 return true; | 159 return true; |
146 } | 160 } |
147 return false; | 161 return false; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return; | 383 return; |
370 } | 384 } |
371 | 385 |
372 DestroyPreviewContents(); | 386 DestroyPreviewContents(); |
373 } | 387 } |
374 #endif | 388 #endif |
375 | 389 |
376 void InstantController::OnAutocompleteGotFocus( | 390 void InstantController::OnAutocompleteGotFocus( |
377 TabContentsWrapper* tab_contents) { | 391 TabContentsWrapper* tab_contents) { |
378 CommandLine* cl = CommandLine::ForCurrentProcess(); | 392 CommandLine* cl = CommandLine::ForCurrentProcess(); |
379 if (!cl->HasSwitch(switches::kPreloadInstantSearch)) | 393 if (!cl->HasSwitch(switches::kPreloadInstantSearch) && |
| 394 !InstantFieldTrial::IsExperimentGroup(tab_contents->profile())) { |
380 return; | 395 return; |
| 396 } |
381 | 397 |
382 if (is_active_) | 398 if (is_active_) |
383 return; | 399 return; |
384 | 400 |
385 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( | 401 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile( |
386 tab_contents->profile()); | 402 tab_contents->profile()); |
387 if (!model) | 403 if (!model) |
388 return; | 404 return; |
389 | 405 |
390 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 Loading... |
697 | 713 |
698 // Extension keywords don't have a real destination URL. | 714 // Extension keywords don't have a real destination URL. |
699 if (match.template_url && match.template_url->IsExtensionKeyword()) | 715 if (match.template_url && match.template_url->IsExtensionKeyword()) |
700 return PREVIEW_CONDITION_EXTENSION_KEYWORD; | 716 return PREVIEW_CONDITION_EXTENSION_KEYWORD; |
701 | 717 |
702 // Was the host blacklisted? | 718 // Was the host blacklisted? |
703 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) | 719 if (host_blacklist_ && host_blacklist_->count(match.destination_url.host())) |
704 return PREVIEW_CONDITION_BLACKLISTED; | 720 return PREVIEW_CONDITION_BLACKLISTED; |
705 | 721 |
706 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 722 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
707 if (cl->HasSwitch(switches::kRestrictInstantToSearch) && | 723 if ((cl->HasSwitch(switches::kRestrictInstantToSearch) || |
| 724 InstantFieldTrial::IsExperimentGroup(tab_contents_->profile())) && |
708 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && | 725 match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED && |
709 match.type != AutocompleteMatch::SEARCH_HISTORY && | 726 match.type != AutocompleteMatch::SEARCH_HISTORY && |
710 match.type != AutocompleteMatch::SEARCH_SUGGEST && | 727 match.type != AutocompleteMatch::SEARCH_SUGGEST && |
711 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { | 728 match.type != AutocompleteMatch::SEARCH_OTHER_ENGINE) { |
712 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; | 729 return PREVIEW_CONDITION_INSTANT_SEARCH_ONLY; |
713 } | 730 } |
714 | 731 |
715 return PREVIEW_CONDITION_SUCCESS; | 732 return PREVIEW_CONDITION_SUCCESS; |
716 } | 733 } |
717 | 734 |
(...skipping 14 matching lines...) Expand all Loading... |
732 if (destroy_factory_.empty()) { | 749 if (destroy_factory_.empty()) { |
733 MessageLoop::current()->PostTask( | 750 MessageLoop::current()->PostTask( |
734 FROM_HERE, destroy_factory_.NewRunnableMethod( | 751 FROM_HERE, destroy_factory_.NewRunnableMethod( |
735 &InstantController::DestroyLoaders)); | 752 &InstantController::DestroyLoaders)); |
736 } | 753 } |
737 } | 754 } |
738 | 755 |
739 void InstantController::DestroyLoaders() { | 756 void InstantController::DestroyLoaders() { |
740 loaders_to_destroy_.reset(); | 757 loaders_to_destroy_.reset(); |
741 } | 758 } |
OLD | NEW |