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

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

Issue 5023001: Handful of related instant changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 10 years, 1 month 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
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_opt_in.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/metrics/histogram.h"
9 #include "base/rand_util.h"
8 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
9 #include "chrome/browser/instant/instant_delegate.h" 11 #include "chrome/browser/instant/instant_delegate.h"
10 #include "chrome/browser/instant/instant_loader.h" 12 #include "chrome/browser/instant/instant_loader.h"
11 #include "chrome/browser/instant/instant_loader_manager.h" 13 #include "chrome/browser/instant/instant_loader_manager.h"
14 #include "chrome/browser/instant/promo_counter.h"
12 #include "chrome/browser/platform_util.h" 15 #include "chrome/browser/platform_util.h"
13 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
15 #include "chrome/browser/renderer_host/render_widget_host_view.h" 18 #include "chrome/browser/renderer_host/render_widget_host_view.h"
16 #include "chrome/browser/search_engines/template_url.h" 19 #include "chrome/browser/search_engines/template_url.h"
17 #include "chrome/browser/search_engines/template_url_model.h" 20 #include "chrome/browser/search_engines/template_url_model.h"
18 #include "chrome/browser/tab_contents/tab_contents.h" 21 #include "chrome/browser/tab_contents/tab_contents.h"
19 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/notification_service.h" 23 #include "chrome/common/notification_service.h"
21 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
23 26
24 // Number of ms to delay between loading urls. 27 // Number of ms to delay between loading urls.
25 static const int kUpdateDelayMS = 200; 28 static const int kUpdateDelayMS = 200;
26 29
30 static InstantController::Type GetType(Profile* profile) {
31 return InstantController::IsEnabled(profile,
32 InstantController::PREDICTIVE_TYPE) ?
33 InstantController::PREDICTIVE_TYPE : InstantController::VERBATIM_TYPE;
34 }
35
36 InstantController::InstantController(Profile* profile,
37 InstantDelegate* delegate)
38 : delegate_(delegate),
39 tab_contents_(NULL),
40 is_active_(false),
41 commit_on_mouse_up_(false),
42 last_transition_type_(PageTransition::LINK),
43 type_(GetType(profile)) {
44 PrefService* service = profile->GetPrefs();
45 if (service) {
46 // kInstantWasEnabledOnce was added after instant, set it now to make sure
Evan Stade 2010/11/15 19:59:23 nit: kInstantEnabledOnce
47 // it is correctly set.
48 service->SetBoolean(prefs::kInstantEnabledOnce, true);
49 }
50 }
51
52 InstantController::~InstantController() {
53 }
54
27 // static 55 // static
28 void InstantController::RegisterUserPrefs(PrefService* prefs) { 56 void InstantController::RegisterUserPrefs(PrefService* prefs) {
29 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false); 57 prefs->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false);
30 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false); 58 prefs->RegisterBooleanPref(prefs::kInstantEnabled, false);
59 prefs->RegisterBooleanPref(prefs::kInstantEnabledOnce, false);
60 prefs->RegisterInt64Pref(prefs::kInstantEnabledTime, false);
61 prefs->RegisterIntegerPref(prefs::kInstantType, 0);
62 PromoCounter::RegisterUserPrefs(prefs, prefs::kInstantPromo);
31 } 63 }
32 64
33 // static 65 // static
66 void InstantController::RecordMetrics(Profile* profile) {
67 if (!IsEnabled(profile))
68 return;
69
70 PrefService* service = profile->GetPrefs();
71 if (service) {
72 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime);
73 if (!enable_time) {
74 service->SetInt64(prefs::kInstantEnabledTime,
75 base::Time::Now().ToInternalValue());
76 } else {
77 base::TimeDelta delta =
78 base::Time::Now() - base::Time::FromInternalValue(enable_time);
79 std::string name = IsEnabled(profile, PREDICTIVE_TYPE) ?
80 "Instant.EnabledTime.Predictive" : "Instant.EnabledTime.Verbatim";
81 // Histogram from 1 hour to 30 days.
82 UMA_HISTOGRAM_CUSTOM_COUNTS(name, delta.InHours(), 1, 30 * 24, 50);
Evan Stade 2010/11/15 19:59:23 so the idea is we're tracking how long people leav
sky 2010/11/15 20:15:26 Yes.
83 }
84 }
85 }
86
87 // static
34 bool InstantController::IsEnabled(Profile* profile) { 88 bool InstantController::IsEnabled(Profile* profile) {
35 return IsEnabled(profile, PREDICTIVE_TYPE) || 89 return IsEnabled(profile, PREDICTIVE_TYPE) ||
36 IsEnabled(profile, VERBATIM_TYPE); 90 IsEnabled(profile, VERBATIM_TYPE);
37 } 91 }
38 92
39 // static 93 // static
40 bool InstantController::IsEnabled(Profile* profile, Type type) { 94 bool InstantController::IsEnabled(Profile* profile, Type type) {
95 // CommandLine takes precedence.
41 CommandLine* cl = CommandLine::ForCurrentProcess(); 96 CommandLine* cl = CommandLine::ForCurrentProcess();
42 if (type == PREDICTIVE_TYPE) { 97 if (type == PREDICTIVE_TYPE &&
43 return (cl->HasSwitch(switches::kEnablePredictiveInstant) || 98 cl->HasSwitch(switches::kEnablePredictiveInstant)) {
44 (profile->GetPrefs() && 99 return true;
45 profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)));
46 } 100 }
47 return cl->HasSwitch(switches::kEnableVerbatimInstant); 101 if (type == VERBATIM_TYPE &&
102 cl->HasSwitch(switches::kEnableVerbatimInstant)) {
103 return true;
104 }
105
106 // Then prefs.
107 PrefService* prefs = profile->GetPrefs();
108 if (!prefs->GetBoolean(prefs::kInstantEnabled))
109 return false;
110
111 Type pref_type = prefs->GetInteger(prefs::kInstantType) ==
112 static_cast<int>(PREDICTIVE_TYPE) ? PREDICTIVE_TYPE : VERBATIM_TYPE;
113 return pref_type == type;
48 } 114 }
49 115
50 static InstantController::Type GetType(Profile* profile) { 116 // static
51 return InstantController::IsEnabled(profile, 117 void InstantController::Enable(Profile* profile) {
52 InstantController::PREDICTIVE_TYPE) ? 118 PromoCounter* promo_counter = profile->GetInstantPromoCounter();
53 InstantController::PREDICTIVE_TYPE : InstantController::VERBATIM_TYPE; 119 if (promo_counter)
120 promo_counter->Hide();
121
122 PrefService* service = profile->GetPrefs();
123 if (!service)
124 return;
125
126 service->SetBoolean(prefs::kInstantEnabled, true);
127 service->SetBoolean(prefs::kInstantConfirmDialogShown, true);
128 service->SetInt64(prefs::kInstantEnabledTime,
129 base::Time::Now().ToInternalValue());
130 service->SetBoolean(prefs::kInstantEnabledOnce, true);
131 // Randomly pick a type. We're doing this to get feedback as to which variant
132 // folks prefer.
133 service->SetInteger(prefs::kInstantType,
134 base::RandInt(static_cast<int>(PREDICTIVE_TYPE),
135 static_cast<int>(LAST_TYPE)));
54 } 136 }
55 137
56 InstantController::InstantController(Profile* profile, 138 // static
57 InstantDelegate* delegate) 139 void InstantController::Disable(Profile* profile) {
58 : delegate_(delegate), 140 PrefService* service = profile->GetPrefs();
59 tab_contents_(NULL), 141 if (!service)
60 is_active_(false), 142 return;
61 commit_on_mouse_up_(false), 143
62 last_transition_type_(PageTransition::LINK), 144 service->SetBoolean(prefs::kInstantEnabled, false);
63 type_(GetType(profile)) { 145
146 int64 enable_time = service->GetInt64(prefs::kInstantEnabledTime);
147 if (!enable_time)
148 return;
149
150 base::TimeDelta delta =
151 base::Time::Now() - base::Time::FromInternalValue(enable_time);
152 std::string name = IsEnabled(profile, PREDICTIVE_TYPE) ?
153 "Instant.TimeToDisable.Predictive" : "Instant.TimeToDisable.Verbatim";
154 // histogram from 1 minute to 10 days.
155 UMA_HISTOGRAM_CUSTOM_COUNTS(name, delta.InMinutes(), 1, 60 * 24 * 10, 50);
64 } 156 }
65 157
66 InstantController::~InstantController() {
67 }
68 158
69 void InstantController::Update(TabContents* tab_contents, 159 void InstantController::Update(TabContents* tab_contents,
70 const AutocompleteMatch& match, 160 const AutocompleteMatch& match,
71 const string16& user_text, 161 const string16& user_text,
72 string16* suggested_text) { 162 string16* suggested_text) {
73 if (tab_contents != tab_contents_) 163 if (tab_contents != tab_contents_)
74 DestroyPreviewContents(); 164 DestroyPreviewContents();
75 165
76 const GURL& url = match.destination_url; 166 const GURL& url = match.destination_url;
77 167
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 template_url = model ? model->GetDefaultSearchProvider() : NULL; 499 template_url = model ? model->GetDefaultSearchProvider() : NULL;
410 } 500 }
411 if (template_url && template_url->id() && 501 if (template_url && template_url->id() &&
412 template_url->instant_url() && 502 template_url->instant_url() &&
413 !IsBlacklistedFromInstant(template_url->id()) && 503 !IsBlacklistedFromInstant(template_url->id()) &&
414 template_url->instant_url()->SupportsReplacement()) { 504 template_url->instant_url()->SupportsReplacement()) {
415 return template_url; 505 return template_url;
416 } 506 }
417 return NULL; 507 return NULL;
418 } 508 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_opt_in.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698