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" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 suggestions_viewed_ = true; | 200 suggestions_viewed_ = true; |
201 user_action_logged_ = true; | 201 user_action_logged_ = true; |
202 } | 202 } |
203 | 203 |
204 void SuggestionsHandler::HandleSuggestedSitesSelected( | 204 void SuggestionsHandler::HandleSuggestedSitesSelected( |
205 const base::ListValue* args) { | 205 const base::ListValue* args) { |
206 suggestions_viewed_ = true; | 206 suggestions_viewed_ = true; |
207 } | 207 } |
208 | 208 |
209 void SuggestionsHandler::SetPagesValueFromTopSites( | 209 void SuggestionsHandler::SetPagesValueFromTopSites( |
210 const history::MostVisitedURLList& data) { | 210 const history::FilteredURLList& data) { |
211 pages_value_.reset(new ListValue()); | 211 pages_value_.reset(new ListValue()); |
212 for (size_t i = 0; i < data.size(); i++) { | 212 for (size_t i = 0; i < data.size(); i++) { |
213 const history::MostVisitedURL& suggested_url = data[i]; | 213 const history::FilteredURL& suggested_url = data[i]; |
214 if (suggested_url.url.is_empty()) | 214 if (suggested_url.url.is_empty()) |
215 continue; | 215 continue; |
216 | 216 |
217 DictionaryValue* page_value = new DictionaryValue(); | 217 DictionaryValue* page_value = new DictionaryValue(); |
218 NewTabUI::SetURLTitleAndDirection(page_value, | 218 NewTabUI::SetURLTitleAndDirection(page_value, |
219 suggested_url.title, | 219 suggested_url.title, |
220 suggested_url.url); | 220 suggested_url.url); |
| 221 page_value->SetDouble("score", suggested_url.score); |
221 pages_value_->Append(page_value); | 222 pages_value_->Append(page_value); |
222 } | 223 } |
223 } | 224 } |
224 | 225 |
225 void SuggestionsHandler::OnSuggestionsURLsAvailable( | 226 void SuggestionsHandler::OnSuggestionsURLsAvailable( |
226 CancelableRequestProvider::Handle handle, | 227 CancelableRequestProvider::Handle handle, |
227 history::MostVisitedURLList data) { | 228 history::FilteredURLList data) { |
228 SetPagesValueFromTopSites(data); | 229 SetPagesValueFromTopSites(data); |
229 if (got_first_suggestions_request_) | 230 if (got_first_suggestions_request_) |
230 SendPagesValue(); | 231 SendPagesValue(); |
231 } | 232 } |
232 | 233 |
233 void SuggestionsHandler::Observe(int type, | 234 void SuggestionsHandler::Observe(int type, |
234 const content::NotificationSource& source, | 235 const content::NotificationSource& source, |
235 const content::NotificationDetails& details) { | 236 const content::NotificationDetails& details) { |
236 DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED); | 237 DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED); |
237 | 238 |
238 // Suggestions urls changed, query again. | 239 // Suggestions urls changed, query again. |
239 StartQueryForSuggestions(); | 240 StartQueryForSuggestions(); |
240 } | 241 } |
241 | 242 |
242 void SuggestionsHandler::BlacklistURL(const GURL& url) { | 243 void SuggestionsHandler::BlacklistURL(const GURL& url) { |
243 // TODO(georgey) blacklist an URL. | 244 // TODO(georgey) blacklist an URL. |
244 } | 245 } |
245 | 246 |
246 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { | 247 std::string SuggestionsHandler::GetDictionaryKeyForURL(const std::string& url) { |
247 return base::MD5String(url); | 248 return base::MD5String(url); |
248 } | 249 } |
249 | 250 |
250 // static | 251 // static |
251 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { | 252 void SuggestionsHandler::RegisterUserPrefs(PrefService* prefs) { |
252 // TODO(georgey) add user preferences (such as own blacklist) as needed. | 253 // TODO(georgey) add user preferences (such as own blacklist) as needed. |
253 } | 254 } |
OLD | NEW |