| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/webui/ntp/suggestions_page_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/history/page_usage_data.h" | 20 #include "chrome/browser/history/page_usage_data.h" |
| 21 #include "chrome/browser/history/top_sites.h" | 21 #include "chrome/browser/history/top_sites.h" |
| 22 #include "chrome/browser/history/visit_filter.h" | 22 #include "chrome/browser/history/visit_filter.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 25 #include "chrome/browser/ui/webui/favicon_source.h" | 25 #include "chrome/browser/ui/webui/favicon_source.h" |
| 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 27 #include "chrome/browser/ui/webui/ntp/ntp_stats.h" |
| 27 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 28 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/navigation_controller.h" | 32 #include "content/public/browser/navigation_controller.h" |
| 32 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
| 33 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 34 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/browser/web_ui.h" | 37 #include "content/public/browser/web_ui.h" |
| 37 #include "content/public/common/page_transition_types.h" | 38 #include "content/public/common/page_transition_types.h" |
| 38 #include "googleurl/src/gurl.h" | 39 #include "googleurl/src/gurl.h" |
| 39 | 40 |
| 40 using content::UserMetricsAction; | 41 using content::UserMetricsAction; |
| 41 | 42 |
| 42 namespace { | |
| 43 | |
| 44 // Those values are defined in histograms.xml. These represent the action that | |
| 45 // the user has taken to leave the Suggested pane, given that they have viewed | |
| 46 // that pane on the NTP. | |
| 47 enum SuggestedSitesActions { | |
| 48 // Values 0 to 10 are the core values from PageTransition (see | |
| 49 // page_transition_types.h). | |
| 50 | |
| 51 // The user has clicked on a Suggested tile. | |
| 52 SUGGESTED_SITES_ACTION_CLICKED_SUGGESTED_TILE = 11, | |
| 53 // The user has moved to another pane within the NTP. | |
| 54 SUGGESTED_SITES_ACTION_CLICKED_OTHER_NTP_PANE, | |
| 55 // Any action other than what is listed here (e.g. closing the tab, etc.). | |
| 56 SUGGESTED_SITES_ACTION_OTHER, | |
| 57 // The number of suggested sites actions that we log. | |
| 58 NUM_SUGGESTED_SITES_ACTIONS | |
| 59 }; | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 SuggestionsHandler::SuggestionsHandler() | 43 SuggestionsHandler::SuggestionsHandler() |
| 64 : got_first_suggestions_request_(false), | 44 : got_first_suggestions_request_(false), |
| 65 suggestions_viewed_(false), | 45 suggestions_viewed_(false), |
| 66 user_action_logged_(false) { | 46 user_action_logged_(false) { |
| 67 } | 47 } |
| 68 | 48 |
| 69 SuggestionsHandler::~SuggestionsHandler() { | 49 SuggestionsHandler::~SuggestionsHandler() { |
| 70 // TODO(macourteau): ensure that |suggestions_viewed_| gets set correctly, | |
| 71 // once the Suggestions pane gets statically included into the NTP (e.g., | |
| 72 // if the Suggestions pane is the one shown by default, the | |
| 73 // |suggestions_viewed_| flag might not get set). | |
| 74 if (!user_action_logged_ && suggestions_viewed_) { | 50 if (!user_action_logged_ && suggestions_viewed_) { |
| 75 const GURL ntp_url = GURL(chrome::kChromeUINewTabURL); | 51 const GURL ntp_url = GURL(chrome::kChromeUINewTabURL); |
| 76 int action_id = SUGGESTED_SITES_ACTION_OTHER; | 52 int action_id = NTP_FOLLOW_ACTION_OTHER; |
| 77 content::NavigationEntry* entry = | 53 content::NavigationEntry* entry = |
| 78 web_ui()->GetWebContents()->GetController().GetActiveEntry(); | 54 web_ui()->GetWebContents()->GetController().GetActiveEntry(); |
| 79 if (entry && (entry->GetURL() != ntp_url)) { | 55 if (entry && (entry->GetURL() != ntp_url)) { |
| 80 action_id = | 56 action_id = |
| 81 content::PageTransitionStripQualifier(entry->GetTransitionType()); | 57 content::PageTransitionStripQualifier(entry->GetTransitionType()); |
| 82 } | 58 } |
| 83 | 59 |
| 84 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", action_id, | 60 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", action_id, |
| 85 NUM_SUGGESTED_SITES_ACTIONS); | 61 NUM_NTP_FOLLOW_ACTIONS); |
| 86 } | 62 } |
| 87 } | 63 } |
| 88 | 64 |
| 89 void SuggestionsHandler::RegisterMessages() { | 65 void SuggestionsHandler::RegisterMessages() { |
| 90 Profile* profile = Profile::FromWebUI(web_ui()); | 66 Profile* profile = Profile::FromWebUI(web_ui()); |
| 91 // Set up our sources for thumbnail and favicon data. | 67 // Set up our sources for thumbnail and favicon data. |
| 92 profile->GetChromeURLDataManager()->AddDataSource( | 68 profile->GetChromeURLDataManager()->AddDataSource( |
| 93 new ThumbnailSource(profile)); | 69 new ThumbnailSource(profile)); |
| 94 profile->GetChromeURLDataManager()->AddDataSource( | 70 profile->GetChromeURLDataManager()->AddDataSource( |
| 95 new FaviconSource(profile, FaviconSource::FAVICON)); | 71 new FaviconSource(profile, FaviconSource::FAVICON)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void SuggestionsHandler::HandleSuggestedSitesAction( | 165 void SuggestionsHandler::HandleSuggestedSitesAction( |
| 190 const base::ListValue* args) { | 166 const base::ListValue* args) { |
| 191 DCHECK(args); | 167 DCHECK(args); |
| 192 | 168 |
| 193 double action_id; | 169 double action_id; |
| 194 if (!args->GetDouble(0, &action_id)) | 170 if (!args->GetDouble(0, &action_id)) |
| 195 NOTREACHED(); | 171 NOTREACHED(); |
| 196 | 172 |
| 197 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", | 173 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", |
| 198 static_cast<int>(action_id), | 174 static_cast<int>(action_id), |
| 199 NUM_SUGGESTED_SITES_ACTIONS); | 175 NUM_NTP_FOLLOW_ACTIONS); |
| 200 suggestions_viewed_ = true; | 176 suggestions_viewed_ = true; |
| 201 user_action_logged_ = true; | 177 user_action_logged_ = true; |
| 202 } | 178 } |
| 203 | 179 |
| 204 void SuggestionsHandler::HandleSuggestedSitesSelected( | 180 void SuggestionsHandler::HandleSuggestedSitesSelected( |
| 205 const base::ListValue* args) { | 181 const base::ListValue* args) { |
| 206 suggestions_viewed_ = true; | 182 suggestions_viewed_ = true; |
| 207 } | 183 } |
| 208 | 184 |
| 209 void SuggestionsHandler::SetPagesValueFromTopSites( | 185 void SuggestionsHandler::SetPagesValueFromTopSites( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 220 } |
| 245 | 221 |
| 246 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { | 222 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { |
| 247 return base::MD5String(url); | 223 return base::MD5String(url); |
| 248 } | 224 } |
| 249 | 225 |
| 250 // static | 226 // static |
| 251 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { | 227 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { |
| 252 // TODO(georgey) add user preferences (such as own blacklist) as needed. | 228 // TODO(georgey) add user preferences (such as own blacklist) as needed. |
| 253 } | 229 } |
| OLD | NEW |