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