| 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/translate/core/browser/language_model.h" | 5 #include "components/translate/core/browser/language_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // If the sample is not large enough yet, pretend there are no top languages. | 66 // If the sample is not large enough yet, pretend there are no top languages. |
| 67 if (counters_sum < kMinCountersSum) | 67 if (counters_sum < kMinCountersSum) |
| 68 return std::vector<LanguageModel::LanguageInfo>(); | 68 return std::vector<LanguageModel::LanguageInfo>(); |
| 69 | 69 |
| 70 std::vector<LanguageModel::LanguageInfo> top_languages; | 70 std::vector<LanguageModel::LanguageInfo> top_languages; |
| 71 int counter_value = 0; | 71 int counter_value = 0; |
| 72 for (base::DictionaryValue::Iterator itr(dict); !itr.IsAtEnd(); | 72 for (base::DictionaryValue::Iterator itr(dict); !itr.IsAtEnd(); |
| 73 itr.Advance()) { | 73 itr.Advance()) { |
| 74 if (!itr.value().GetAsInteger(&counter_value)) | 74 if (!itr.value().GetAsInteger(&counter_value)) |
| 75 continue; | 75 continue; |
| 76 top_languages.push_back( | 76 top_languages.emplace_back( |
| 77 {itr.key(), static_cast<float>(counter_value) / counters_sum}); | 77 itr.key(), static_cast<float>(counter_value) / counters_sum); |
| 78 } | 78 } |
| 79 return top_languages; | 79 return top_languages; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace | 82 } // namespace |
| 83 | 83 |
| 84 LanguageModel::LanguageModel(PrefService* pref_service) | 84 LanguageModel::LanguageModel(PrefService* pref_service) |
| 85 : pref_service_(pref_service) {} | 85 : pref_service_(pref_service) {} |
| 86 | 86 |
| 87 LanguageModel::~LanguageModel() = default; | 87 LanguageModel::~LanguageModel() = default; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 int counter_value = 0; | 126 int counter_value = 0; |
| 127 // If the key |language_code| does not exist, |counter_value| stays 0. | 127 // If the key |language_code| does not exist, |counter_value| stays 0. |
| 128 dict->GetInteger(language_code, &counter_value); | 128 dict->GetInteger(language_code, &counter_value); |
| 129 dict->SetInteger(language_code, counter_value + 1); | 129 dict->SetInteger(language_code, counter_value + 1); |
| 130 | 130 |
| 131 if (GetCountersSum(*dict) > kMaxCountersSum) | 131 if (GetCountersSum(*dict) > kMaxCountersSum) |
| 132 DiscountAndCleanCounters(dict); | 132 DiscountAndCleanCounters(dict); |
| 133 } | 133 } |
| 134 | 134 |
| 135 } // namespace translate | 135 } // namespace translate |
| OLD | NEW |