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

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

Issue 6245012: Removes different instant behaviors that are no longer used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update tests Created 9 years, 10 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) 2010 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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
(...skipping 22 matching lines...) Expand all
34 InstantController::HostBlacklist* InstantController::host_blacklist_ = NULL; 34 InstantController::HostBlacklist* InstantController::host_blacklist_ = NULL;
35 35
36 InstantController::InstantController(Profile* profile, 36 InstantController::InstantController(Profile* profile,
37 InstantDelegate* delegate) 37 InstantDelegate* delegate)
38 : delegate_(delegate), 38 : delegate_(delegate),
39 tab_contents_(NULL), 39 tab_contents_(NULL),
40 is_active_(false), 40 is_active_(false),
41 is_displayable_(false), 41 is_displayable_(false),
42 commit_on_mouse_up_(false), 42 commit_on_mouse_up_(false),
43 last_transition_type_(PageTransition::LINK), 43 last_transition_type_(PageTransition::LINK),
44 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)), 44 ALLOW_THIS_IN_INITIALIZER_LIST(destroy_factory_(this)) {
45 type_(FIRST_TYPE) {
46 bool enabled = GetType(profile, &type_);
47 DCHECK(enabled);
48 PrefService* service = profile->GetPrefs(); 45 PrefService* service = profile->GetPrefs();
49 if (service) { 46 if (service) {
50 // kInstantWasEnabledOnce was added after instant, set it now to make sure 47 // kInstantWasEnabledOnce was added after instant, set it now to make sure
51 // it is correctly set. 48 // it is correctly set.
52 service->SetBoolean(prefs::kInstantEnabledOnce, true); 49 service->SetBoolean(prefs::kInstantEnabledOnce, true);
53 } 50 }
54 } 51 }
55 52
56 InstantController::~InstantController() { 53 InstantController::~InstantController() {
57 } 54 }
(...skipping 14 matching lines...) Expand all
72 69
73 PrefService* service = profile->GetPrefs(); 70 PrefService* service = profile->GetPrefs();
74 if (service) { 71 if (service) {
75 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime); 72 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime);
76 if (!enable_time) { 73 if (!enable_time) {
77 service->SetInt64(prefs::kInstantEnabledTime, 74 service->SetInt64(prefs::kInstantEnabledTime,
78 base::Time::Now().ToInternalValue()); 75 base::Time::Now().ToInternalValue());
79 } else { 76 } else {
80 base::TimeDelta delta = 77 base::TimeDelta delta =
81 base::Time::Now() - base::Time::FromInternalValue(enable_time); 78 base::Time::Now() - base::Time::FromInternalValue(enable_time);
82 std::string name = "Instant.EnabledTime. " + GetTypeString(profile);
83 // Can't use histogram macros as name isn't constant.
84 // Histogram from 1 hour to 30 days. 79 // Histogram from 1 hour to 30 days.
85 scoped_refptr<base::Histogram> counter = 80 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.EnabledTime.Predictive",
86 base::Histogram::FactoryGet(name, 1, 30 * 24, 50, 81 delta.InHours(), 1, 30 * 24, 50);
87 base::Histogram::kUmaTargetedHistogramFlag);
88 counter->Add(delta.InHours());
89 } 82 }
90 } 83 }
91 } 84 }
92 85
93 // static 86 // static
94 bool InstantController::IsEnabled(Profile* profile) { 87 bool InstantController::IsEnabled(Profile* profile) {
95 Type type; 88 PrefService* prefs = profile->GetPrefs();
96 return GetType(profile, &type); 89 return prefs->GetBoolean(prefs::kInstantEnabled);
97 } 90 }
98 91
99 // static 92 // static
100 bool InstantController::IsEnabled(Profile* profile, Type type) {
101 Type enabled_type;
102 return GetType(profile, &enabled_type) && type == enabled_type;
103 }
104
105 // static
106 void InstantController::Enable(Profile* profile) { 93 void InstantController::Enable(Profile* profile) {
107 PromoCounter* promo_counter = profile->GetInstantPromoCounter(); 94 PromoCounter* promo_counter = profile->GetInstantPromoCounter();
108 if (promo_counter) 95 if (promo_counter)
109 promo_counter->Hide(); 96 promo_counter->Hide();
110 97
111 PrefService* service = profile->GetPrefs(); 98 PrefService* service = profile->GetPrefs();
112 if (!service) 99 if (!service)
113 return; 100 return;
114 101
115 service->SetBoolean(prefs::kInstantEnabled, true); 102 service->SetBoolean(prefs::kInstantEnabled, true);
116 service->SetBoolean(prefs::kInstantConfirmDialogShown, true); 103 service->SetBoolean(prefs::kInstantConfirmDialogShown, true);
117 service->SetInt64(prefs::kInstantEnabledTime, 104 service->SetInt64(prefs::kInstantEnabledTime,
118 base::Time::Now().ToInternalValue()); 105 base::Time::Now().ToInternalValue());
119 service->SetBoolean(prefs::kInstantEnabledOnce, true); 106 service->SetBoolean(prefs::kInstantEnabledOnce, true);
120 } 107 }
121 108
122 // static 109 // static
123 void InstantController::Disable(Profile* profile) { 110 void InstantController::Disable(Profile* profile) {
124 PrefService* service = profile->GetPrefs(); 111 PrefService* service = profile->GetPrefs();
125 if (!service || !IsEnabled(profile)) 112 if (!service || !IsEnabled(profile))
126 return; 113 return;
127 114
128 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime); 115 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime);
129 if (enable_time) { 116 if (enable_time) {
130 base::TimeDelta delta = 117 base::TimeDelta delta =
131 base::Time::Now() - base::Time::FromInternalValue(enable_time); 118 base::Time::Now() - base::Time::FromInternalValue(enable_time);
132 std::string name = "Instant.TimeToDisable." + GetTypeString(profile);
133 // Can't use histogram macros as name isn't constant.
134 // Histogram from 1 minute to 10 days. 119 // Histogram from 1 minute to 10 days.
135 scoped_refptr<base::Histogram> counter = 120 UMA_HISTOGRAM_CUSTOM_COUNTS("Instant.TimeToDisable.Predictive",
136 base::Histogram::FactoryGet(name, 1, 60 * 24 * 10, 50, 121 delta.InMinutes(), 1, 60 * 24 * 10, 50);
137 base::Histogram::kUmaTargetedHistogramFlag);
138 counter->Add(delta.InMinutes());
139 } 122 }
140 123
141 service->SetBoolean(prefs::kInstantEnabled, false); 124 service->SetBoolean(prefs::kInstantEnabled, false);
142 } 125 }
143 126
144 // static 127 // static
145 bool InstantController::CommitIfCurrent(InstantController* controller) { 128 bool InstantController::CommitIfCurrent(InstantController* controller) {
146 if (controller && controller->IsCurrent()) { 129 if (controller && controller->IsCurrent()) {
147 controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); 130 controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
148 return true; 131 return true;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 &InstantController::DestroyLoaders)); 562 &InstantController::DestroyLoaders));
580 } 563 }
581 } 564 }
582 565
583 void InstantController::DestroyLoaders() { 566 void InstantController::DestroyLoaders() {
584 loaders_to_destroy_.reset(); 567 loaders_to_destroy_.reset();
585 } 568 }
586 569
587 const TemplateURL* InstantController::GetTemplateURL( 570 const TemplateURL* InstantController::GetTemplateURL(
588 const AutocompleteMatch& match) { 571 const AutocompleteMatch& match) {
589 if (type_ == VERBATIM_TYPE) {
590 // When using VERBATIM_TYPE we don't want to attempt to use the instant
591 // JavaScript API, otherwise the page would show predictive results. By
592 // returning NULL here we ensure we don't attempt to use the instant API.
593 //
594 // TODO: when the full search box API is in place we can lift this
595 // restriction and force the page to show verbatim results always.
596 return NULL;
597 }
598
599 const TemplateURL* template_url = match.template_url; 572 const TemplateURL* template_url = match.template_url;
600 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || 573 if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED ||
601 match.type == AutocompleteMatch::SEARCH_HISTORY || 574 match.type == AutocompleteMatch::SEARCH_HISTORY ||
602 match.type == AutocompleteMatch::SEARCH_SUGGEST) { 575 match.type == AutocompleteMatch::SEARCH_SUGGEST) {
603 TemplateURLModel* model = tab_contents_->profile()->GetTemplateURLModel(); 576 TemplateURLModel* model = tab_contents_->profile()->GetTemplateURLModel();
604 template_url = model ? model->GetDefaultSearchProvider() : NULL; 577 template_url = model ? model->GetDefaultSearchProvider() : NULL;
605 } 578 }
606 return template_url; 579 return template_url;
607 } 580 }
608
609 // static
610 bool InstantController::GetType(Profile* profile, Type* type) {
611 *type = FIRST_TYPE;
612 // CommandLine takes precedence.
613 CommandLine* cl = CommandLine::ForCurrentProcess();
614 if (cl->HasSwitch(switches::kEnablePredictiveInstant)) {
615 *type = PREDICTIVE_TYPE;
616 return true;
617 }
618 if (cl->HasSwitch(switches::kEnableVerbatimInstant)) {
619 *type = VERBATIM_TYPE;
620 return true;
621 }
622 if (cl->HasSwitch(switches::kEnablePredictiveNoAutoCompleteInstant)) {
623 *type = PREDICTIVE_NO_AUTO_COMPLETE_TYPE;
624 return true;
625 }
626
627 // Then prefs.
628 PrefService* prefs = profile->GetPrefs();
629 if (!prefs->GetBoolean(prefs::kInstantEnabled))
630 return false;
631
632 // PREDICTIVE_TYPE is the default if enabled via preferences.
633 *type = PREDICTIVE_TYPE;
634 return true;
635 }
636
637 // static
638 std::string InstantController::GetTypeString(Profile* profile) {
639 Type type;
640 if (!GetType(profile, &type)) {
641 NOTREACHED();
642 return std::string();
643 }
644 switch (type) {
645 case PREDICTIVE_TYPE:
646 return "Predictive";
647 case VERBATIM_TYPE:
648 return "Verbatim";
649 case PREDICTIVE_NO_AUTO_COMPLETE_TYPE:
650 return "PredictiveNoAutoComplete";
651 default:
652 NOTREACHED();
653 return std::string();
654 }
655 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/ui/views/location_bar/suggested_text_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698