| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/ntp_snippets/category_rankers/click_based_category_ranker.h
" | 5 #include "components/ntp_snippets/category_rankers/click_based_category_ranker.h
" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 bool ClickBasedCategoryRanker::ReadOrderFromPrefs( | 407 bool ClickBasedCategoryRanker::ReadOrderFromPrefs( |
| 408 std::vector<RankedCategory>* result_categories) const { | 408 std::vector<RankedCategory>* result_categories) const { |
| 409 result_categories->clear(); | 409 result_categories->clear(); |
| 410 const base::ListValue* list = | 410 const base::ListValue* list = |
| 411 pref_service_->GetList(prefs::kClickBasedCategoryRankerOrderWithClicks); | 411 pref_service_->GetList(prefs::kClickBasedCategoryRankerOrderWithClicks); |
| 412 if (!list || list->GetSize() == 0) { | 412 if (!list || list->GetSize() == 0) { |
| 413 return false; | 413 return false; |
| 414 } | 414 } |
| 415 | 415 |
| 416 for (const base::Value& value : *list) { | 416 for (const std::unique_ptr<base::Value>& value : *list) { |
| 417 const base::DictionaryValue* dictionary; | 417 base::DictionaryValue* dictionary; |
| 418 if (!value.GetAsDictionary(&dictionary)) { | 418 if (!value->GetAsDictionary(&dictionary)) { |
| 419 LOG(DFATAL) << "Failed to parse category data from prefs param " | 419 LOG(DFATAL) << "Failed to parse category data from prefs param " |
| 420 << prefs::kClickBasedCategoryRankerOrderWithClicks | 420 << prefs::kClickBasedCategoryRankerOrderWithClicks |
| 421 << " into dictionary."; | 421 << " into dictionary."; |
| 422 return false; | 422 return false; |
| 423 } | 423 } |
| 424 int category_id, clicks; | 424 int category_id, clicks; |
| 425 if (!dictionary->GetInteger(kCategoryIdKey, &category_id)) { | 425 if (!dictionary->GetInteger(kCategoryIdKey, &category_id)) { |
| 426 LOG(DFATAL) << "Dictionary does not have '" << kCategoryIdKey << "' key."; | 426 LOG(DFATAL) << "Dictionary does not have '" << kCategoryIdKey << "' key."; |
| 427 return false; | 427 return false; |
| 428 } | 428 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 num_pending_decays * GetTimeBetweenDecays()); | 519 num_pending_decays * GetTimeBetweenDecays()); |
| 520 | 520 |
| 521 if (executed_decays > 0) { | 521 if (executed_decays > 0) { |
| 522 StoreOrderToPrefs(ordered_categories_); | 522 StoreOrderToPrefs(ordered_categories_); |
| 523 return true; | 523 return true; |
| 524 } | 524 } |
| 525 return false; | 525 return false; |
| 526 } | 526 } |
| 527 | 527 |
| 528 } // namespace ntp_snippets | 528 } // namespace ntp_snippets |
| OLD | NEW |