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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 17526008: Log NTP hovers in 1993 clients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed newline Created 7 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/common/content_settings_types.h" 36 #include "chrome/common/content_settings_types.h"
37 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
38 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
39 #include "components/sessions/serialized_navigation_entry.h" 39 #include "components/sessions/serialized_navigation_entry.h"
40 #include "content/public/browser/navigation_entry.h" 40 #include "content/public/browser/navigation_entry.h"
41 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
42 #include "content/public/browser/render_process_host.h" 42 #include "content/public/browser/render_process_host.h"
43 #include "content/public/browser/render_widget_host_view.h" 43 #include "content/public/browser/render_widget_host_view.h"
44 #include "content/public/browser/user_metrics.h" 44 #include "content/public/browser/user_metrics.h"
45 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
46 #include "content/public/browser/web_contents_user_data.h"
46 #include "content/public/browser/web_contents_view.h" 47 #include "content/public/browser/web_contents_view.h"
47 #include "net/base/escape.h" 48 #include "net/base/escape.h"
48 #include "net/base/network_change_notifier.h" 49 #include "net/base/network_change_notifier.h"
49 #include "third_party/icu/public/common/unicode/normalizer2.h" 50 #include "third_party/icu/public/common/unicode/normalizer2.h"
50 51
51 #if defined(TOOLKIT_VIEWS) 52 #if defined(TOOLKIT_VIEWS)
52 #include "ui/views/widget/widget.h" 53 #include "ui/views/widget/widget.h"
53 #endif 54 #endif
54 55
55 namespace { 56 namespace {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 template <typename T> 244 template <typename T>
244 void DeletePageSoon(scoped_ptr<T> page) { 245 void DeletePageSoon(scoped_ptr<T> page) {
245 if (page->contents()) { 246 if (page->contents()) {
246 base::MessageLoop::current()->DeleteSoon( 247 base::MessageLoop::current()->DeleteSoon(
247 FROM_HERE, page->ReleaseContents().release()); 248 FROM_HERE, page->ReleaseContents().release());
248 } 249 }
249 250
250 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); 251 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release());
251 } 252 }
252 253
254 // Helper class for logging data from the NTP. Attached to each InstantNTP
255 // instance.
256 class NtpLoggingUserData
257 : public content::WebContentsUserData<NtpLoggingUserData> {
258 public:
259 virtual ~NtpLoggingUserData() {}
260
261 // Called each time the mouse hovers over an iframe or title.
262 void increment_number_of_mouseovers() {
263 number_of_mouseovers++;
264 }
265
266 // Logs total number of mouseovers per NTP session to UMA histogram.
267 // Called when a tab is about to be deactivated.
268 void log_number_of_mouseovers() {
269 if (number_of_mouseovers > 0) {
270 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers",
Mark P 2013/06/25 19:04:32 Why do you only log if the number is greater than
annark1 2013/06/25 21:04:11 As per our offline discussion, I've addressed this
271 number_of_mouseovers);
272 number_of_mouseovers = 0;
273 }
274 }
275
276 private:
277 explicit NtpLoggingUserData(content::WebContents* contents)
278 : number_of_mouseovers(0) {}
279 friend class content::WebContentsUserData<NtpLoggingUserData>;
280
281 int number_of_mouseovers;
282 };
Alexei Svitkine (slow) 2013/06/25 17:21:20 Should this have DISALLOW_COPY_AND_ASSIGN(NtpLoggi
annark1 2013/06/25 21:04:11 Done.
283
253 } // namespace 284 } // namespace
254 285
286 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NtpLoggingUserData);
287
255 InstantController::InstantController(BrowserInstantController* browser, 288 InstantController::InstantController(BrowserInstantController* browser,
256 bool extended_enabled) 289 bool extended_enabled)
257 : browser_(browser), 290 : browser_(browser),
258 extended_enabled_(extended_enabled), 291 extended_enabled_(extended_enabled),
259 instant_enabled_(false), 292 instant_enabled_(false),
260 use_local_page_only_(true), 293 use_local_page_only_(true),
261 preload_ntp_(true), 294 preload_ntp_(true),
262 model_(this), 295 model_(this),
263 use_tab_for_suggestions_(false), 296 use_tab_for_suggestions_(false),
264 last_omnibox_text_has_inline_autocompletion_(false), 297 last_omnibox_text_has_inline_autocompletion_(false),
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 ResetInstantTab(); 1088 ResetInstantTab();
1056 } 1089 }
1057 1090
1058 void InstantController::TabDeactivated(content::WebContents* contents) { 1091 void InstantController::TabDeactivated(content::WebContents* contents) {
1059 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); 1092 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated");
1060 if (extended_enabled() && !contents->IsBeingDestroyed()) 1093 if (extended_enabled() && !contents->IsBeingDestroyed())
1061 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); 1094 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
1062 1095
1063 if (GetOverlayContents()) 1096 if (GetOverlayContents())
1064 HideOverlay(); 1097 HideOverlay();
1098
1099 NtpLoggingUserData* data =
1100 NtpLoggingUserData::FromWebContents(contents);
1101 if (data)
1102 data->log_number_of_mouseovers();
1065 } 1103 }
1066 1104
1067 void InstantController::SetInstantEnabled(bool instant_enabled, 1105 void InstantController::SetInstantEnabled(bool instant_enabled,
1068 bool use_local_page_only) { 1106 bool use_local_page_only) {
1069 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1107 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1070 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d", 1108 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d",
1071 instant_enabled, use_local_page_only)); 1109 instant_enabled, use_local_page_only));
1072 1110
1073 // Non extended mode does not care about |use_local_page_only|. 1111 // Non extended mode does not care about |use_local_page_only|.
1074 if (instant_enabled == instant_enabled_ && 1112 if (instant_enabled == instant_enabled_ &&
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 return; 1633 return;
1596 1634
1597 // Instant NTP is only used in extended mode so we should always have a 1635 // Instant NTP is only used in extended mode so we should always have a
1598 // non-empty URL to use. 1636 // non-empty URL to use.
1599 DCHECK(!instant_url.empty()); 1637 DCHECK(!instant_url.empty());
1600 ntp_.reset(new InstantNTP(this, instant_url, 1638 ntp_.reset(new InstantNTP(this, instant_url,
1601 browser_->profile()->IsOffTheRecord())); 1639 browser_->profile()->IsOffTheRecord()));
1602 ntp_->InitContents(profile(), browser_->GetActiveWebContents(), 1640 ntp_->InitContents(profile(), browser_->GetActiveWebContents(),
1603 base::Bind(&InstantController::ReloadStaleNTP, 1641 base::Bind(&InstantController::ReloadStaleNTP,
1604 base::Unretained(this))); 1642 base::Unretained(this)));
1643
1644 if (ntp_->contents())
1645 NtpLoggingUserData::CreateForWebContents(ntp_->contents());
1646
1605 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1647 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1606 "ResetNTP: instant_url='%s'", instant_url.c_str())); 1648 "ResetNTP: instant_url='%s'", instant_url.c_str()));
1607 } 1649 }
1608 1650
1609 void InstantController::ReloadStaleNTP() { 1651 void InstantController::ReloadStaleNTP() {
1610 ResetNTP(GetInstantURL()); 1652 ResetNTP(GetInstantURL());
1611 } 1653 }
1612 1654
1613 bool InstantController::ShouldSwitchToLocalNTP() const { 1655 bool InstantController::ShouldSwitchToLocalNTP() const {
1614 if (!ntp()) 1656 if (!ntp())
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 result->relevance = match.relevance; 1935 result->relevance = match.relevance;
1894 result->autocomplete_match_index = autocomplete_match_index; 1936 result->autocomplete_match_index = autocomplete_match_index;
1895 1937
1896 DVLOG(1) << " " << result->relevance << " " 1938 DVLOG(1) << " " << result->relevance << " "
1897 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " 1939 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " "
1898 << result->provider << " " << result->destination_url << " '" 1940 << result->provider << " " << result->destination_url << " '"
1899 << result->description << "' '" << result->search_query << "' " 1941 << result->description << "' '" << result->search_query << "' "
1900 << result->transition << " " << result->autocomplete_match_index; 1942 << result->transition << " " << result->autocomplete_match_index;
1901 } 1943 }
1902 1944
1945 void InstantController::LogIframeHover() {
1946 if (!browser_ || !browser_->GetActiveWebContents())
1947 return;
1948
1949 NtpLoggingUserData* data =
1950 NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents());
1951 if (data)
1952 data->increment_number_of_mouseovers();
1953 }
1954
1903 bool InstantController::IsJavascriptEnabled() const { 1955 bool InstantController::IsJavascriptEnabled() const {
1904 GURL instant_url(GetInstantURL()); 1956 GURL instant_url(GetInstantURL());
1905 GURL origin(instant_url.GetOrigin()); 1957 GURL origin(instant_url.GetOrigin());
1906 ContentSetting js_setting = profile()->GetHostContentSettingsMap()-> 1958 ContentSetting js_setting = profile()->GetHostContentSettingsMap()->
1907 GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT, 1959 GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
1908 NO_RESOURCE_IDENTIFIER); 1960 NO_RESOURCE_IDENTIFIER);
1909 // Javascript can be disabled either in content settings or via a WebKit 1961 // Javascript can be disabled either in content settings or via a WebKit
1910 // preference, so check both. Disabling it through the Settings page affects 1962 // preference, so check both. Disabling it through the Settings page affects
1911 // content settings. I'm not sure how to disable the WebKit preference, but 1963 // content settings. I'm not sure how to disable the WebKit preference, but
1912 // it's theoretically possible some users have it off. 1964 // it's theoretically possible some users have it off.
1913 bool js_content_enabled = 1965 bool js_content_enabled =
1914 js_setting == CONTENT_SETTING_DEFAULT || 1966 js_setting == CONTENT_SETTING_DEFAULT ||
1915 js_setting == CONTENT_SETTING_ALLOW; 1967 js_setting == CONTENT_SETTING_ALLOW;
1916 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( 1968 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean(
1917 prefs::kWebKitJavascriptEnabled); 1969 prefs::kWebKitJavascriptEnabled);
1918 return js_content_enabled && js_webkit_enabled; 1970 return js_content_enabled && js_webkit_enabled;
1919 } 1971 }
1920 1972
1921 bool InstantController::InStartup() const { 1973 bool InstantController::InStartup() const {
1922 // TODO(shishir): This is not completely reliable. Find a better way to detect 1974 // TODO(shishir): This is not completely reliable. Find a better way to detect
1923 // startup time. 1975 // startup time.
1924 return !browser_->GetActiveWebContents(); 1976 return !browser_->GetActiveWebContents();
1925 } 1977 }
1926 1978
1927 InstantService* InstantController::GetInstantService() const { 1979 InstantService* InstantController::GetInstantService() const {
1928 return InstantServiceFactory::GetForProfile(profile()); 1980 return InstantServiceFactory::GetForProfile(profile());
1929 } 1981 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698