OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/most_visited_handler.h" | 5 #include "chrome/browser/dom_ui/most_visited_handler.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/md5.h" | 12 #include "base/md5.h" |
13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
14 #include "base/scoped_vector.h" | 14 #include "base/scoped_vector.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/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
21 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 21 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
22 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" | 22 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" |
23 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" | 23 #include "chrome/browser/dom_ui/dom_ui_thumbnail_source.h" |
24 #include "chrome/browser/dom_ui/new_tab_ui.h" | 24 #include "chrome/browser/dom_ui/new_tab_ui.h" |
25 #include "chrome/browser/history/page_usage_data.h" | 25 #include "chrome/browser/history/page_usage_data.h" |
26 #include "chrome/browser/history/history.h" | |
27 #include "chrome/browser/history/top_sites.h" | 26 #include "chrome/browser/history/top_sites.h" |
28 #include "chrome/browser/metrics/user_metrics.h" | 27 #include "chrome/browser/metrics/user_metrics.h" |
29 #include "chrome/browser/prefs/pref_service.h" | 28 #include "chrome/browser/prefs/pref_service.h" |
30 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/notification_type.h" | 30 #include "chrome/common/notification_type.h" |
32 #include "chrome/common/notification_source.h" | 31 #include "chrome/common/notification_source.h" |
33 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
34 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
35 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
36 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 SendPagesValue(); | 124 SendPagesValue(); |
126 got_first_most_visited_request_ = true; | 125 got_first_most_visited_request_ = true; |
127 } else { | 126 } else { |
128 StartQueryForMostVisited(); | 127 StartQueryForMostVisited(); |
129 } | 128 } |
130 } | 129 } |
131 | 130 |
132 void MostVisitedHandler::SendPagesValue() { | 131 void MostVisitedHandler::SendPagesValue() { |
133 if (pages_value_.get()) { | 132 if (pages_value_.get()) { |
134 bool has_blacklisted_urls = !url_blacklist_->empty(); | 133 bool has_blacklisted_urls = !url_blacklist_->empty(); |
135 if (history::TopSites::IsEnabled()) { | 134 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
136 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 135 if (ts) |
137 if (ts) | 136 has_blacklisted_urls = ts->HasBlacklistedItems(); |
138 has_blacklisted_urls = ts->HasBlacklistedItems(); | |
139 } | |
140 FundamentalValue first_run(IsFirstRun()); | 137 FundamentalValue first_run(IsFirstRun()); |
141 FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls); | 138 FundamentalValue has_blacklisted_urls_value(has_blacklisted_urls); |
142 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", | 139 dom_ui_->CallJavascriptFunction(L"mostVisitedPages", |
143 *(pages_value_.get()), | 140 *(pages_value_.get()), |
144 first_run, | 141 first_run, |
145 has_blacklisted_urls_value); | 142 has_blacklisted_urls_value); |
146 pages_value_.reset(); | 143 pages_value_.reset(); |
147 } | 144 } |
148 } | 145 } |
149 | 146 |
150 void MostVisitedHandler::StartQueryForMostVisited() { | 147 void MostVisitedHandler::StartQueryForMostVisited() { |
151 if (history::TopSites::IsEnabled()) { | 148 // Use TopSites. |
152 // Use TopSites. | 149 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
153 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 150 if (ts) { |
154 if (ts) { | 151 ts->GetMostVisitedURLs( |
155 ts->GetMostVisitedURLs( | 152 &topsites_consumer_, |
156 &topsites_consumer_, | 153 NewCallback(this, &MostVisitedHandler::OnMostVisitedURLsAvailable)); |
157 NewCallback(this, &MostVisitedHandler::OnMostVisitedURLsAvailable)); | |
158 } | |
159 return; | |
160 } | |
161 | |
162 const int page_count = kMostVisitedPages; | |
163 // Let's query for the number of items we want plus the blacklist size as | |
164 // we'll be filtering-out the returned list with the blacklist URLs. | |
165 // We do not subtract the number of pinned URLs we have because the | |
166 // HistoryService does not know about those. | |
167 const int result_count = page_count + url_blacklist_->size(); | |
168 HistoryService* hs = | |
169 dom_ui_->GetProfile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | |
170 // |hs| may be null during unit tests. | |
171 if (hs) { | |
172 hs->QuerySegmentUsageSince( | |
173 &cancelable_consumer_, | |
174 base::Time::Now() - base::TimeDelta::FromDays(kMostVisitedScope), | |
175 result_count, | |
176 NewCallback(this, &MostVisitedHandler::OnSegmentUsageAvailable)); | |
177 } | 154 } |
178 } | 155 } |
179 | 156 |
180 void MostVisitedHandler::HandleBlacklistURL(const ListValue* args) { | 157 void MostVisitedHandler::HandleBlacklistURL(const ListValue* args) { |
181 std::string url = WideToUTF8(ExtractStringValue(args)); | 158 std::string url = WideToUTF8(ExtractStringValue(args)); |
182 BlacklistURL(GURL(url)); | 159 BlacklistURL(GURL(url)); |
183 } | 160 } |
184 | 161 |
185 void MostVisitedHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { | 162 void MostVisitedHandler::HandleRemoveURLsFromBlacklist(const ListValue* args) { |
186 DCHECK(args->GetSize() != 0); | 163 DCHECK(args->GetSize() != 0); |
187 | 164 |
188 for (ListValue::const_iterator iter = args->begin(); | 165 for (ListValue::const_iterator iter = args->begin(); |
189 iter != args->end(); ++iter) { | 166 iter != args->end(); ++iter) { |
190 std::string url; | 167 std::string url; |
191 bool r = (*iter)->GetAsString(&url); | 168 bool r = (*iter)->GetAsString(&url); |
192 if (!r) { | 169 if (!r) { |
193 NOTREACHED(); | 170 NOTREACHED(); |
194 return; | 171 return; |
195 } | 172 } |
196 UserMetrics::RecordAction(UserMetricsAction("MostVisited_UrlRemoved"), | 173 UserMetrics::RecordAction(UserMetricsAction("MostVisited_UrlRemoved"), |
197 dom_ui_->GetProfile()); | 174 dom_ui_->GetProfile()); |
198 if (history::TopSites::IsEnabled()) { | 175 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
199 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 176 if (ts) |
200 if (ts) | 177 ts->RemoveBlacklistedURL(GURL(url)); |
201 ts->RemoveBlacklistedURL(GURL(url)); | |
202 return; | |
203 } | |
204 | |
205 r = url_blacklist_->Remove(GetDictionaryKeyForURL(url), NULL); | |
206 DCHECK(r) << "Unknown URL removed from the NTP Most Visited blacklist."; | |
207 } | 178 } |
208 } | 179 } |
209 | 180 |
210 void MostVisitedHandler::HandleClearBlacklist(const ListValue* args) { | 181 void MostVisitedHandler::HandleClearBlacklist(const ListValue* args) { |
211 UserMetrics::RecordAction(UserMetricsAction("MostVisited_BlacklistCleared"), | 182 UserMetrics::RecordAction(UserMetricsAction("MostVisited_BlacklistCleared"), |
212 dom_ui_->GetProfile()); | 183 dom_ui_->GetProfile()); |
213 | 184 |
214 if (history::TopSites::IsEnabled()) { | 185 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
215 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 186 if (ts) |
216 if (ts) | 187 ts->ClearBlacklistedURLs(); |
217 ts->ClearBlacklistedURLs(); | |
218 return; | |
219 } | |
220 | |
221 url_blacklist_->Clear(); | |
222 } | 188 } |
223 | 189 |
224 void MostVisitedHandler::HandleAddPinnedURL(const ListValue* args) { | 190 void MostVisitedHandler::HandleAddPinnedURL(const ListValue* args) { |
225 DCHECK_EQ(5U, args->GetSize()) << "Wrong number of params to addPinnedURL"; | 191 DCHECK_EQ(5U, args->GetSize()) << "Wrong number of params to addPinnedURL"; |
226 MostVisitedPage mvp; | 192 MostVisitedPage mvp; |
227 std::string tmp_string; | 193 std::string tmp_string; |
228 string16 tmp_string16; | 194 string16 tmp_string16; |
229 int index; | 195 int index; |
230 | 196 |
231 bool r = args->GetString(0, &tmp_string); | 197 bool r = args->GetString(0, &tmp_string); |
(...skipping 17 matching lines...) Expand all Loading... |
249 mvp.thumbnail_url = GURL(tmp_string); | 215 mvp.thumbnail_url = GURL(tmp_string); |
250 | 216 |
251 r = args->GetString(4, &tmp_string); | 217 r = args->GetString(4, &tmp_string); |
252 DCHECK(r) << "Missing index in addPinnedURL from the NTP Most Visited."; | 218 DCHECK(r) << "Missing index in addPinnedURL from the NTP Most Visited."; |
253 base::StringToInt(tmp_string, &index); | 219 base::StringToInt(tmp_string, &index); |
254 | 220 |
255 AddPinnedURL(mvp, index); | 221 AddPinnedURL(mvp, index); |
256 } | 222 } |
257 | 223 |
258 void MostVisitedHandler::AddPinnedURL(const MostVisitedPage& page, int index) { | 224 void MostVisitedHandler::AddPinnedURL(const MostVisitedPage& page, int index) { |
259 if (history::TopSites::IsEnabled()) { | 225 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
260 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 226 if (ts) |
261 if (ts) | 227 ts->AddPinnedURL(page.url, index); |
262 ts->AddPinnedURL(page.url, index); | |
263 return; | |
264 } | |
265 | |
266 // Remove any pinned URL at the given index. | |
267 MostVisitedPage old_page; | |
268 if (GetPinnedURLAtIndex(index, &old_page)) { | |
269 RemovePinnedURL(old_page.url); | |
270 } | |
271 | |
272 DictionaryValue* new_value = new DictionaryValue(); | |
273 SetMostVisistedPage(new_value, page); | |
274 | |
275 new_value->SetInteger("index", index); | |
276 pinned_urls_->Set(GetDictionaryKeyForURL(page.url.spec()), new_value); | |
277 | |
278 // TODO(arv): Notify observers? | |
279 | |
280 // Don't call HandleGetMostVisited. Let the client call this as needed. | |
281 } | 228 } |
282 | 229 |
283 void MostVisitedHandler::HandleRemovePinnedURL(const ListValue* args) { | 230 void MostVisitedHandler::HandleRemovePinnedURL(const ListValue* args) { |
284 std::string url = WideToUTF8(ExtractStringValue(args)); | 231 std::string url = WideToUTF8(ExtractStringValue(args)); |
285 RemovePinnedURL(GURL(url)); | 232 RemovePinnedURL(GURL(url)); |
286 } | 233 } |
287 | 234 |
288 void MostVisitedHandler::RemovePinnedURL(const GURL& url) { | 235 void MostVisitedHandler::RemovePinnedURL(const GURL& url) { |
289 if (history::TopSites::IsEnabled()) { | 236 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
290 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 237 if (ts) |
291 if (ts) | 238 ts->RemovePinnedURL(url); |
292 ts->RemovePinnedURL(url); | |
293 return; | |
294 } | |
295 | |
296 const std::string key = GetDictionaryKeyForURL(url.spec()); | |
297 if (pinned_urls_->HasKey(key)) | |
298 pinned_urls_->Remove(key, NULL); | |
299 | |
300 // TODO(arv): Notify observers? | |
301 | |
302 // Don't call HandleGetMostVisited. Let the client call this as needed. | |
303 } | 239 } |
304 | 240 |
305 bool MostVisitedHandler::GetPinnedURLAtIndex(int index, | 241 bool MostVisitedHandler::GetPinnedURLAtIndex(int index, |
306 MostVisitedPage* page) { | 242 MostVisitedPage* page) { |
307 // This iterates over all the pinned URLs. It might seem like it is worth | 243 // This iterates over all the pinned URLs. It might seem like it is worth |
308 // having a map from the index to the item but the number of items is limited | 244 // having a map from the index to the item but the number of items is limited |
309 // to the number of items the most visited section is showing on the NTP so | 245 // to the number of items the most visited section is showing on the NTP so |
310 // this will be fast enough for now. | 246 // this will be fast enough for now. |
311 for (DictionaryValue::key_iterator it = pinned_urls_->begin_keys(); | 247 for (DictionaryValue::key_iterator it = pinned_urls_->begin_keys(); |
312 it != pinned_urls_->end_keys(); ++it) { | 248 it != pinned_urls_->end_keys(); ++it) { |
(...skipping 23 matching lines...) Expand all Loading... |
336 return dict->GetString("title", &page->title); | 272 return dict->GetString("title", &page->title); |
337 } | 273 } |
338 } else { | 274 } else { |
339 NOTREACHED() << "DictionaryValue iterators are filthy liars."; | 275 NOTREACHED() << "DictionaryValue iterators are filthy liars."; |
340 } | 276 } |
341 } | 277 } |
342 | 278 |
343 return false; | 279 return false; |
344 } | 280 } |
345 | 281 |
346 void MostVisitedHandler::OnSegmentUsageAvailable( | |
347 CancelableRequestProvider::Handle handle, | |
348 std::vector<PageUsageData*>* data) { | |
349 SetPagesValue(data); | |
350 if (got_first_most_visited_request_) { | |
351 SendPagesValue(); | |
352 } | |
353 } | |
354 | |
355 void MostVisitedHandler::SetPagesValue(std::vector<PageUsageData*>* data) { | |
356 most_visited_urls_.clear(); | |
357 pages_value_.reset(new ListValue); | |
358 std::set<GURL> seen_urls; | |
359 | |
360 size_t data_index = 0; | |
361 size_t output_index = 0; | |
362 size_t pre_populated_index = 0; | |
363 const std::vector<MostVisitedPage> pre_populated_pages = | |
364 MostVisitedHandler::GetPrePopulatedPages(); | |
365 | |
366 while (output_index < kMostVisitedPages) { | |
367 bool found = false; | |
368 bool pinned = false; | |
369 std::string pinned_url; | |
370 std::string pinned_title; | |
371 MostVisitedPage mvp; | |
372 | |
373 if (MostVisitedHandler::GetPinnedURLAtIndex(output_index, &mvp)) { | |
374 pinned = true; | |
375 found = true; | |
376 } | |
377 | |
378 while (!found && data_index < data->size()) { | |
379 const PageUsageData& page = *(*data)[data_index]; | |
380 data_index++; | |
381 mvp.url = page.GetURL(); | |
382 | |
383 // Don't include blacklisted or pinned URLs. | |
384 std::string key = GetDictionaryKeyForURL(mvp.url.spec()); | |
385 if (pinned_urls_->HasKey(key) || url_blacklist_->HasKey(key)) | |
386 continue; | |
387 | |
388 mvp.title = page.GetTitle(); | |
389 found = true; | |
390 } | |
391 | |
392 while (!found && pre_populated_index < pre_populated_pages.size()) { | |
393 mvp = pre_populated_pages[pre_populated_index++]; | |
394 std::string key = GetDictionaryKeyForURL(mvp.url.spec()); | |
395 if (pinned_urls_->HasKey(key) || url_blacklist_->HasKey(key) || | |
396 seen_urls.find(mvp.url) != seen_urls.end()) | |
397 continue; | |
398 | |
399 found = true; | |
400 } | |
401 | |
402 if (found) { | |
403 // Add fillers as needed. | |
404 while (pages_value_->GetSize() < output_index) { | |
405 DictionaryValue* filler_value = new DictionaryValue(); | |
406 filler_value->SetBoolean("filler", true); | |
407 pages_value_->Append(filler_value); | |
408 } | |
409 | |
410 DictionaryValue* page_value = new DictionaryValue(); | |
411 SetMostVisistedPage(page_value, mvp); | |
412 page_value->SetBoolean("pinned", pinned); | |
413 pages_value_->Append(page_value); | |
414 most_visited_urls_.push_back(mvp.url); | |
415 seen_urls.insert(mvp.url); | |
416 } | |
417 output_index++; | |
418 } | |
419 } | |
420 | |
421 void MostVisitedHandler::SetPagesValueFromTopSites( | 282 void MostVisitedHandler::SetPagesValueFromTopSites( |
422 const history::MostVisitedURLList& data) { | 283 const history::MostVisitedURLList& data) { |
423 DCHECK(history::TopSites::IsEnabled()); | |
424 pages_value_.reset(new ListValue); | 284 pages_value_.reset(new ListValue); |
425 for (size_t i = 0; i < data.size(); i++) { | 285 for (size_t i = 0; i < data.size(); i++) { |
426 const history::MostVisitedURL& url = data[i]; | 286 const history::MostVisitedURL& url = data[i]; |
427 DictionaryValue* page_value = new DictionaryValue(); | 287 DictionaryValue* page_value = new DictionaryValue(); |
428 if (url.url.is_empty()) { | 288 if (url.url.is_empty()) { |
429 page_value->SetBoolean("filler", true); | 289 page_value->SetBoolean("filler", true); |
430 pages_value_->Append(page_value); | 290 pages_value_->Append(page_value); |
431 continue; | 291 continue; |
432 } | 292 } |
433 | 293 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // If we found no pages we treat this as the first run. | 326 // If we found no pages we treat this as the first run. |
467 bool first_run = NewTabUI::NewTabHTMLSource::first_run() && | 327 bool first_run = NewTabUI::NewTabHTMLSource::first_run() && |
468 pages_value_->GetSize() == | 328 pages_value_->GetSize() == |
469 MostVisitedHandler::GetPrePopulatedPages().size(); | 329 MostVisitedHandler::GetPrePopulatedPages().size(); |
470 // but first_run should only be true once. | 330 // but first_run should only be true once. |
471 NewTabUI::NewTabHTMLSource::set_first_run(false); | 331 NewTabUI::NewTabHTMLSource::set_first_run(false); |
472 return first_run; | 332 return first_run; |
473 } | 333 } |
474 | 334 |
475 // static | 335 // static |
476 void MostVisitedHandler::SetMostVisistedPage( | |
477 DictionaryValue* dict, | |
478 const MostVisitedHandler::MostVisitedPage& page) { | |
479 NewTabUI::SetURLTitleAndDirection(dict, page.title, page.url); | |
480 if (!page.favicon_url.is_empty()) | |
481 dict->SetString("faviconUrl", page.favicon_url.spec()); | |
482 if (!page.thumbnail_url.is_empty()) | |
483 dict->SetString("thumbnailUrl", page.thumbnail_url.spec()); | |
484 } | |
485 | |
486 | |
487 // static | |
488 const std::vector<MostVisitedHandler::MostVisitedPage>& | 336 const std::vector<MostVisitedHandler::MostVisitedPage>& |
489 MostVisitedHandler::GetPrePopulatedPages() { | 337 MostVisitedHandler::GetPrePopulatedPages() { |
490 // TODO(arv): This needs to get the data from some configurable place. | 338 // TODO(arv): This needs to get the data from some configurable place. |
491 // http://crbug.com/17630 | 339 // http://crbug.com/17630 |
492 static std::vector<MostVisitedPage> pages; | 340 static std::vector<MostVisitedPage> pages; |
493 if (pages.empty()) { | 341 if (pages.empty()) { |
494 MostVisitedPage welcome_page = { | 342 MostVisitedPage welcome_page = { |
495 l10n_util::GetStringUTF16(IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE), | 343 l10n_util::GetStringUTF16(IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE), |
496 GURL(l10n_util::GetStringUTF8(IDS_CHROME_WELCOME_URL)), | 344 GURL(l10n_util::GetStringUTF8(IDS_CHROME_WELCOME_URL)), |
497 GURL("chrome://theme/IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL"), | 345 GURL("chrome://theme/IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL"), |
(...skipping 17 matching lines...) Expand all Loading... |
515 if (type != NotificationType::HISTORY_URLS_DELETED) { | 363 if (type != NotificationType::HISTORY_URLS_DELETED) { |
516 NOTREACHED(); | 364 NOTREACHED(); |
517 return; | 365 return; |
518 } | 366 } |
519 | 367 |
520 // Some URLs were deleted from history. Reload the most visited list. | 368 // Some URLs were deleted from history. Reload the most visited list. |
521 HandleGetMostVisited(NULL); | 369 HandleGetMostVisited(NULL); |
522 } | 370 } |
523 | 371 |
524 void MostVisitedHandler::BlacklistURL(const GURL& url) { | 372 void MostVisitedHandler::BlacklistURL(const GURL& url) { |
525 if (history::TopSites::IsEnabled()) { | 373 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); |
526 history::TopSites* ts = dom_ui_->GetProfile()->GetTopSites(); | 374 if (ts) |
527 if (ts) | 375 ts->AddBlacklistedURL(url); |
528 ts->AddBlacklistedURL(url); | |
529 return; | |
530 } | |
531 | |
532 RemovePinnedURL(url); | |
533 | |
534 std::string key = GetDictionaryKeyForURL(url.spec()); | |
535 if (url_blacklist_->HasKey(key)) | |
536 return; | |
537 url_blacklist_->SetBoolean(key, true); | |
538 } | 376 } |
539 | 377 |
540 std::string MostVisitedHandler::GetDictionaryKeyForURL(const std::string& url) { | 378 std::string MostVisitedHandler::GetDictionaryKeyForURL(const std::string& url) { |
541 return MD5String(url); | 379 return MD5String(url); |
542 } | 380 } |
543 | 381 |
544 // static | 382 // static |
545 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { | 383 void MostVisitedHandler::RegisterUserPrefs(PrefService* prefs) { |
546 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist); | 384 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedURLsBlacklist); |
547 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); | 385 prefs->RegisterDictionaryPref(prefs::kNTPMostVisitedPinnedURLs); |
548 } | 386 } |
549 | 387 |
550 // static | 388 // static |
551 std::vector<GURL> MostVisitedHandler::GetPrePopulatedUrls() { | 389 std::vector<GURL> MostVisitedHandler::GetPrePopulatedUrls() { |
552 const std::vector<MostVisitedPage> pages = | 390 const std::vector<MostVisitedPage> pages = |
553 MostVisitedHandler::GetPrePopulatedPages(); | 391 MostVisitedHandler::GetPrePopulatedPages(); |
554 std::vector<GURL> page_urls; | 392 std::vector<GURL> page_urls; |
555 for (size_t i = 0; i < pages.size(); ++i) | 393 for (size_t i = 0; i < pages.size(); ++i) |
556 page_urls.push_back(pages[i].url); | 394 page_urls.push_back(pages[i].url); |
557 return page_urls; | 395 return page_urls; |
558 } | 396 } |
OLD | NEW |