Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: components/translate/core/browser/translate_prefs.cc

Issue 2740143002: Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Comment Updates Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/translate_prefs.h" 5 #include "components/translate/core/browser/translate_prefs.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 return confidence; 607 return confidence;
608 608
609 // Use a map to fold the probability of all the same normalized language 609 // Use a map to fold the probability of all the same normalized language
610 // code together. 610 // code together.
611 std::map<std::string, double> probability_map; 611 std::map<std::string, double> probability_map;
612 // Iterate through the preference. 612 // Iterate through the preference.
613 for (const auto& entry : *preference) { 613 for (const auto& entry : *preference) {
614 const base::DictionaryValue* item = nullptr; 614 const base::DictionaryValue* item = nullptr;
615 std::string language; 615 std::string language;
616 double probability = 0.0; 616 double probability = 0.0;
617 if (entry->GetAsDictionary(&item) && 617 if (entry.GetAsDictionary(&item) && item->GetString(kLanguage, &language) &&
618 item->GetString(kLanguage, &language) &&
619 item->GetDouble(kProbability, &probability)) { 618 item->GetDouble(kProbability, &probability)) {
620 // Normalize the the language code known and supported by 619 // Normalize the the language code known and supported by
621 // Translate. 620 // Translate.
622 translate::ToTranslateLanguageSynonym(&language); 621 translate::ToTranslateLanguageSynonym(&language);
623 // Discard if the normalized version is unsupported. 622 // Discard if the normalized version is unsupported.
624 if (TranslateDownloadManager::IsSupportedLanguage(language)) { 623 if (TranslateDownloadManager::IsSupportedLanguage(language)) {
625 probability_map[language] += probability; 624 probability_map[language] += probability;
626 } 625 }
627 } 626 }
628 } 627 }
629 for (const auto& it : probability_map) 628 for (const auto& it : probability_map)
630 out_value->push_back(it); 629 out_value->push_back(it);
631 std::sort(out_value->begin(), out_value->end(), 630 std::sort(out_value->begin(), out_value->end(),
632 [](const LanguageAndProbability& left, 631 [](const LanguageAndProbability& left,
633 const LanguageAndProbability& right) { 632 const LanguageAndProbability& right) {
634 return left.second > right.second; 633 return left.second > right.second;
635 }); 634 });
636 return confidence; 635 return confidence;
637 } 636 }
638 637
639 } // namespace translate 638 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698