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/string16.h" | 15 #include "base/string16.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "chrome/browser/history/page_usage_data.h" | 20 #include "chrome/browser/history/page_usage_data.h" |
20 #include "chrome/browser/history/top_sites.h" | 21 #include "chrome/browser/history/top_sites.h" |
21 #include "chrome/browser/history/visit_filter.h" | 22 #include "chrome/browser/history/visit_filter.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
24 #include "chrome/browser/ui/webui/favicon_source.h" | 25 #include "chrome/browser/ui/webui/favicon_source.h" |
25 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
26 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" | 27 #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/navigation_controller.h" | |
32 #include "content/public/browser/navigation_entry.h" | |
30 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
31 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
35 #include "content/public/browser/web_contents.h" | |
32 #include "content/public/browser/web_ui.h" | 36 #include "content/public/browser/web_ui.h" |
37 #include "content/public/common/page_transition_types.h" | |
33 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
34 | 39 |
35 using content::UserMetricsAction; | 40 using content::UserMetricsAction; |
36 | 41 |
42 namespace { | |
43 | |
44 enum SuggestedSitesActions { | |
45 SUGGESTED_SITES_ACTION_OTHER = 0, | |
46 SUGGESTED_SITES_ACTION_CLICKED_SUGGESTED_TILE, | |
Evan Stade
2012/04/04 20:33:35
comments for these.
I'm also still a bit confused
macourteau
2012/04/04 21:00:36
Done.
| |
47 SUGGESTED_SITES_ACTION_CLICKED_OTHER_NTP_PANE, | |
48 SUGGESTED_SITES_ACTION_OMNIBOX_NAVIGATION | |
49 }; | |
50 | |
51 } // namespace | |
52 | |
37 SuggestionsHandler::SuggestionsHandler() | 53 SuggestionsHandler::SuggestionsHandler() |
38 : got_first_suggestions_request_(false) { | 54 : got_first_suggestions_request_(false), |
55 suggestions_viewed_(false), | |
56 valid_user_action_(false) { | |
39 } | 57 } |
40 | 58 |
41 SuggestionsHandler::~SuggestionsHandler() { | 59 SuggestionsHandler::~SuggestionsHandler() { |
60 // TODO(macourteau): ensure that |suggestions_viewed_| gets set correctly, | |
61 // once the Suggestions pane gets be statically included into the NTP (e.g., | |
62 // if the Suggestions pane is the one shown by default, the | |
63 // |suggestions_viewed_| flag might not get set). | |
64 if (!valid_user_action_ && suggestions_viewed_) { | |
65 const GURL ntp_url = GURL(chrome::kChromeUINewTabURL); | |
66 int action_id = SUGGESTED_SITES_ACTION_OTHER; | |
67 content::NavigationEntry* entry = | |
68 web_ui()->GetWebContents()->GetController().GetActiveEntry(); | |
69 if (entry && (entry->GetURL() != ntp_url)) { | |
70 if (content::PageTransitionStripQualifier(entry->GetTransitionType()) == | |
71 content::PAGE_TRANSITION_TYPED) { | |
72 action_id = SUGGESTED_SITES_ACTION_OMNIBOX_NAVIGATION; | |
73 } | |
74 } | |
75 | |
76 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", action_id, 4); | |
77 } | |
42 } | 78 } |
43 | 79 |
44 void SuggestionsHandler::RegisterMessages() { | 80 void SuggestionsHandler::RegisterMessages() { |
45 Profile* profile = Profile::FromWebUI(web_ui()); | 81 Profile* profile = Profile::FromWebUI(web_ui()); |
46 // Set up our sources for thumbnail and favicon data. | 82 // Set up our sources for thumbnail and favicon data. |
47 profile->GetChromeURLDataManager()->AddDataSource( | 83 profile->GetChromeURLDataManager()->AddDataSource( |
48 new ThumbnailSource(profile)); | 84 new ThumbnailSource(profile)); |
49 profile->GetChromeURLDataManager()->AddDataSource( | 85 profile->GetChromeURLDataManager()->AddDataSource( |
50 new FaviconSource(profile, FaviconSource::FAVICON)); | 86 new FaviconSource(profile, FaviconSource::FAVICON)); |
51 | 87 |
(...skipping 22 matching lines...) Expand all Loading... | |
74 // Register ourselves for any suggestions item blacklisting. | 110 // Register ourselves for any suggestions item blacklisting. |
75 web_ui()->RegisterMessageCallback("blacklistURLFromSuggestions", | 111 web_ui()->RegisterMessageCallback("blacklistURLFromSuggestions", |
76 base::Bind(&SuggestionsHandler::HandleBlacklistURL, | 112 base::Bind(&SuggestionsHandler::HandleBlacklistURL, |
77 base::Unretained(this))); | 113 base::Unretained(this))); |
78 web_ui()->RegisterMessageCallback("removeURLsFromSuggestionsBlacklist", | 114 web_ui()->RegisterMessageCallback("removeURLsFromSuggestionsBlacklist", |
79 base::Bind(&SuggestionsHandler::HandleRemoveURLsFromBlacklist, | 115 base::Bind(&SuggestionsHandler::HandleRemoveURLsFromBlacklist, |
80 base::Unretained(this))); | 116 base::Unretained(this))); |
81 web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist", | 117 web_ui()->RegisterMessageCallback("clearSuggestionsURLsBlacklist", |
82 base::Bind(&SuggestionsHandler::HandleClearBlacklist, | 118 base::Bind(&SuggestionsHandler::HandleClearBlacklist, |
83 base::Unretained(this))); | 119 base::Unretained(this))); |
120 web_ui()->RegisterMessageCallback("suggestedSitesAction", | |
121 base::Bind(&SuggestionsHandler::HandleSuggestedSitesAction, | |
122 base::Unretained(this))); | |
123 web_ui()->RegisterMessageCallback("suggestedSitesSelected", | |
124 base::Bind(&SuggestionsHandler::HandleSuggestedSitesSelected, | |
125 base::Unretained(this))); | |
84 } | 126 } |
85 | 127 |
86 void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) { | 128 void SuggestionsHandler::HandleGetSuggestions(const ListValue* args) { |
87 if (!got_first_suggestions_request_) { | 129 if (!got_first_suggestions_request_) { |
88 // If our initial data is already here, return it. | 130 // If our initial data is already here, return it. |
89 SendPagesValue(); | 131 SendPagesValue(); |
90 got_first_suggestions_request_ = true; | 132 got_first_suggestions_request_ = true; |
91 } else { | 133 } else { |
92 StartQueryForSuggestions(); | 134 StartQueryForSuggestions(); |
93 } | 135 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 170 |
129 void SuggestionsHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { | 171 void SuggestionsHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { |
130 DCHECK_GT(args->GetSize(), 0U); | 172 DCHECK_GT(args->GetSize(), 0U); |
131 // TODO(georgey) remove URLs from blacklist. | 173 // TODO(georgey) remove URLs from blacklist. |
132 } | 174 } |
133 | 175 |
134 void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) { | 176 void SuggestionsHandler::HandleClearBlacklist(const ListValue* args) { |
135 // TODO(georgey) clear blacklist. | 177 // TODO(georgey) clear blacklist. |
136 } | 178 } |
137 | 179 |
180 void SuggestionsHandler::HandleSuggestedSitesAction( | |
181 const base::ListValue* args) { | |
182 DCHECK(args); | |
183 | |
184 double action_id; | |
185 if (!args->GetDouble(0, &action_id)) | |
186 NOTREACHED(); | |
187 | |
188 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SuggestedSitesAction", | |
189 static_cast<int>(action_id), 4); | |
190 suggestions_viewed_ = true; | |
191 valid_user_action_ = true; | |
192 } | |
193 | |
194 void SuggestionsHandler::HandleSuggestedSitesSelected( | |
195 const base::ListValue* args) { | |
196 suggestions_viewed_ = true; | |
197 } | |
198 | |
138 void SuggestionsHandler::SetPagesValueFromTopSites( | 199 void SuggestionsHandler::SetPagesValueFromTopSites( |
139 const history::MostVisitedURLList& data) { | 200 const history::MostVisitedURLList& data) { |
140 pages_value_.reset(new ListValue()); | 201 pages_value_.reset(new ListValue()); |
141 for (size_t i = 0; i < data.size(); i++) { | 202 for (size_t i = 0; i < data.size(); i++) { |
142 const history::MostVisitedURL& suggested_url = data[i]; | 203 const history::MostVisitedURL& suggested_url = data[i]; |
143 if (suggested_url.url.is_empty()) | 204 if (suggested_url.url.is_empty()) |
144 continue; | 205 continue; |
145 | 206 |
146 DictionaryValue* page_value = new DictionaryValue(); | 207 DictionaryValue* page_value = new DictionaryValue(); |
147 NewTabUI::SetURLTitleAndDirection(page_value, | 208 NewTabUI::SetURLTitleAndDirection(page_value, |
(...skipping 25 matching lines...) Expand all Loading... | |
173 } | 234 } |
174 | 235 |
175 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { | 236 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { |
176 return base::MD5String(url); | 237 return base::MD5String(url); |
177 } | 238 } |
178 | 239 |
179 // static | 240 // static |
180 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { | 241 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { |
181 // TODO(georgey) add user preferences (such as own blacklist) as needed. | 242 // TODO(georgey) add user preferences (such as own blacklist) as needed. |
182 } | 243 } |
OLD | NEW |