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

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: Spacing fix 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
Jered 2013/06/26 16:37:57 instant_controller.cc feels like the wrong place f
annark1 2013/06/28 15:30:49 Done.
255 // instance.
256 class NtpLoggingUserData
Jered 2013/06/26 16:37:57 Ntp -> NTP.
annark1 2013/06/28 15:30:49 Done.
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. Called
267 // when a tab is about to be deactivated (be it by switching tabs, losing
268 // focus or closing the tab/shutting down Chrome) or when the contents of the
269 // current tab is replaced. Does not log 0 mouseover cases (for instance if a
Jered 2013/06/26 16:37:57 Why not log the case with 0 hovers? This seems lik
annark1 2013/06/28 15:30:49 After offline discussions with Jered and Mark Pear
270 // user opens the NTP then immediately switches to another tab without
271 // interacting with the NTP).
272 void log_number_of_mouseovers() {
273 if (number_of_mouseovers > 0) {
274 UMA_HISTOGRAM_COUNTS("NewTabPage.NumberOfMouseOvers",
275 number_of_mouseovers);
276 number_of_mouseovers = 0;
277 }
278 }
279
280 private:
281 explicit NtpLoggingUserData(content::WebContents* contents)
282 : number_of_mouseovers(0) {}
283 friend class content::WebContentsUserData<NtpLoggingUserData>;
284
285 int number_of_mouseovers;
Jered 2013/06/26 16:37:57 Member variables should end with _.
annark1 2013/06/28 15:30:49 Done.
286
287 DISALLOW_COPY_AND_ASSIGN(NtpLoggingUserData);
288 };
289
253 } // namespace 290 } // namespace
254 291
292 DEFINE_WEB_CONTENTS_USER_DATA_KEY(NtpLoggingUserData);
293
255 InstantController::InstantController(BrowserInstantController* browser, 294 InstantController::InstantController(BrowserInstantController* browser,
256 bool extended_enabled) 295 bool extended_enabled)
257 : browser_(browser), 296 : browser_(browser),
258 extended_enabled_(extended_enabled), 297 extended_enabled_(extended_enabled),
259 instant_enabled_(false), 298 instant_enabled_(false),
260 use_local_page_only_(true), 299 use_local_page_only_(true),
261 preload_ntp_(true), 300 preload_ntp_(true),
262 model_(this), 301 model_(this),
263 use_tab_for_suggestions_(false), 302 use_tab_for_suggestions_(false),
264 last_omnibox_text_has_inline_autocompletion_(false), 303 last_omnibox_text_has_inline_autocompletion_(false),
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 ResetInstantTab(); 1094 ResetInstantTab();
1056 } 1095 }
1057 1096
1058 void InstantController::TabDeactivated(content::WebContents* contents) { 1097 void InstantController::TabDeactivated(content::WebContents* contents) {
1059 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); 1098 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated");
1060 if (extended_enabled() && !contents->IsBeingDestroyed()) 1099 if (extended_enabled() && !contents->IsBeingDestroyed())
1061 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); 1100 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
1062 1101
1063 if (GetOverlayContents()) 1102 if (GetOverlayContents())
1064 HideOverlay(); 1103 HideOverlay();
1104
1105 if (NtpLoggingUserData::FromWebContents(contents))
1106 NtpLoggingUserData::FromWebContents(contents)->log_number_of_mouseovers();
1065 } 1107 }
1066 1108
1067 void InstantController::SetInstantEnabled(bool instant_enabled, 1109 void InstantController::SetInstantEnabled(bool instant_enabled,
1068 bool use_local_page_only) { 1110 bool use_local_page_only) {
1069 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1111 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1070 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d", 1112 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d",
1071 instant_enabled, use_local_page_only)); 1113 instant_enabled, use_local_page_only));
1072 1114
1073 // Non extended mode does not care about |use_local_page_only|. 1115 // Non extended mode does not care about |use_local_page_only|.
1074 if (instant_enabled == instant_enabled_ && 1116 if (instant_enabled == instant_enabled_ &&
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 return; 1637 return;
1596 1638
1597 // Instant NTP is only used in extended mode so we should always have a 1639 // Instant NTP is only used in extended mode so we should always have a
1598 // non-empty URL to use. 1640 // non-empty URL to use.
1599 DCHECK(!instant_url.empty()); 1641 DCHECK(!instant_url.empty());
1600 ntp_.reset(new InstantNTP(this, instant_url, 1642 ntp_.reset(new InstantNTP(this, instant_url,
1601 browser_->profile()->IsOffTheRecord())); 1643 browser_->profile()->IsOffTheRecord()));
1602 ntp_->InitContents(profile(), browser_->GetActiveWebContents(), 1644 ntp_->InitContents(profile(), browser_->GetActiveWebContents(),
1603 base::Bind(&InstantController::ReloadStaleNTP, 1645 base::Bind(&InstantController::ReloadStaleNTP,
1604 base::Unretained(this))); 1646 base::Unretained(this)));
1647
1648 if (ntp_->contents())
1649 NtpLoggingUserData::CreateForWebContents(ntp_->contents());
1650
1605 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1651 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1606 "ResetNTP: instant_url='%s'", instant_url.c_str())); 1652 "ResetNTP: instant_url='%s'", instant_url.c_str()));
1607 } 1653 }
1608 1654
1609 void InstantController::ReloadStaleNTP() { 1655 void InstantController::ReloadStaleNTP() {
1610 ResetNTP(GetInstantURL()); 1656 ResetNTP(GetInstantURL());
1611 } 1657 }
1612 1658
1613 bool InstantController::ShouldSwitchToLocalNTP() const { 1659 bool InstantController::ShouldSwitchToLocalNTP() const {
1614 if (!ntp()) 1660 if (!ntp())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 instant_tab_->Init(active_tab); 1714 instant_tab_->Init(active_tab);
1669 UpdateInfoForInstantTab(); 1715 UpdateInfoForInstantTab();
1670 use_tab_for_suggestions_ = true; 1716 use_tab_for_suggestions_ = true;
1671 } 1717 }
1672 1718
1673 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1719 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1674 HideOverlay(); 1720 HideOverlay();
1675 } else { 1721 } else {
1676 instant_tab_.reset(); 1722 instant_tab_.reset();
1677 } 1723 }
1724
1725 if (NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents())) {
Jered 2013/06/26 16:37:57 Why are you calling this here?
annark1 2013/06/28 15:30:49 I was calling this here to capture the cases when
1726 NtpLoggingUserData::FromWebContents(
1727 browser_->GetActiveWebContents())->log_number_of_mouseovers();
1728 }
1678 } 1729 }
1679 1730
1680 void InstantController::UpdateInfoForInstantTab() { 1731 void InstantController::UpdateInfoForInstantTab() {
1681 if (instant_tab_) { 1732 if (instant_tab_) {
1682 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_); 1733 instant_tab_->sender()->SetDisplayInstantResults(instant_enabled_);
1683 instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_); 1734 instant_tab_->sender()->SetOmniboxBounds(omnibox_bounds_);
1684 1735
1685 // Update theme details. 1736 // Update theme details.
1686 InstantService* instant_service = GetInstantService(); 1737 InstantService* instant_service = GetInstantService();
1687 if (instant_service) 1738 if (instant_service)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 result->relevance = match.relevance; 1944 result->relevance = match.relevance;
1894 result->autocomplete_match_index = autocomplete_match_index; 1945 result->autocomplete_match_index = autocomplete_match_index;
1895 1946
1896 DVLOG(1) << " " << result->relevance << " " 1947 DVLOG(1) << " " << result->relevance << " "
1897 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " 1948 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " "
1898 << result->provider << " " << result->destination_url << " '" 1949 << result->provider << " " << result->destination_url << " '"
1899 << result->description << "' '" << result->search_query << "' " 1950 << result->description << "' '" << result->search_query << "' "
1900 << result->transition << " " << result->autocomplete_match_index; 1951 << result->transition << " " << result->autocomplete_match_index;
1901 } 1952 }
1902 1953
1954 void InstantController::LogIframeHover() {
1955 if (!browser_ || !browser_->GetActiveWebContents())
1956 return;
1957
1958 if(NtpLoggingUserData::FromWebContents(browser_->GetActiveWebContents())) {
1959 NtpLoggingUserData::FromWebContents(
1960 browser_->GetActiveWebContents())->increment_number_of_mouseovers();
1961 }
1962 }
1963
1903 bool InstantController::IsJavascriptEnabled() const { 1964 bool InstantController::IsJavascriptEnabled() const {
1904 GURL instant_url(GetInstantURL()); 1965 GURL instant_url(GetInstantURL());
1905 GURL origin(instant_url.GetOrigin()); 1966 GURL origin(instant_url.GetOrigin());
1906 ContentSetting js_setting = profile()->GetHostContentSettingsMap()-> 1967 ContentSetting js_setting = profile()->GetHostContentSettingsMap()->
1907 GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT, 1968 GetContentSetting(origin, origin, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
1908 NO_RESOURCE_IDENTIFIER); 1969 NO_RESOURCE_IDENTIFIER);
1909 // Javascript can be disabled either in content settings or via a WebKit 1970 // Javascript can be disabled either in content settings or via a WebKit
1910 // preference, so check both. Disabling it through the Settings page affects 1971 // 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 1972 // content settings. I'm not sure how to disable the WebKit preference, but
1912 // it's theoretically possible some users have it off. 1973 // it's theoretically possible some users have it off.
1913 bool js_content_enabled = 1974 bool js_content_enabled =
1914 js_setting == CONTENT_SETTING_DEFAULT || 1975 js_setting == CONTENT_SETTING_DEFAULT ||
1915 js_setting == CONTENT_SETTING_ALLOW; 1976 js_setting == CONTENT_SETTING_ALLOW;
1916 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean( 1977 bool js_webkit_enabled = profile()->GetPrefs()->GetBoolean(
1917 prefs::kWebKitJavascriptEnabled); 1978 prefs::kWebKitJavascriptEnabled);
1918 return js_content_enabled && js_webkit_enabled; 1979 return js_content_enabled && js_webkit_enabled;
1919 } 1980 }
1920 1981
1921 bool InstantController::InStartup() const { 1982 bool InstantController::InStartup() const {
1922 // TODO(shishir): This is not completely reliable. Find a better way to detect 1983 // TODO(shishir): This is not completely reliable. Find a better way to detect
1923 // startup time. 1984 // startup time.
1924 return !browser_->GetActiveWebContents(); 1985 return !browser_->GetActiveWebContents();
1925 } 1986 }
1926 1987
1927 InstantService* InstantController::GetInstantService() const { 1988 InstantService* InstantController::GetInstantService() const {
1928 return InstantServiceFactory::GetForProfile(profile()); 1989 return InstantServiceFactory::GetForProfile(profile());
1929 } 1990 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698