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

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

Issue 2816513002: Revert of Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Created 3 years, 8 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_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 return confidence; 609 return confidence;
610 610
611 // Use a map to fold the probability of all the same normalized language 611 // Use a map to fold the probability of all the same normalized language
612 // code together. 612 // code together.
613 std::map<std::string, double> probability_map; 613 std::map<std::string, double> probability_map;
614 // Iterate through the preference. 614 // Iterate through the preference.
615 for (const auto& entry : *preference) { 615 for (const auto& entry : *preference) {
616 const base::DictionaryValue* item = nullptr; 616 const base::DictionaryValue* item = nullptr;
617 std::string language; 617 std::string language;
618 double probability = 0.0; 618 double probability = 0.0;
619 if (entry.GetAsDictionary(&item) && item->GetString(kLanguage, &language) && 619 if (entry->GetAsDictionary(&item) &&
620 item->GetString(kLanguage, &language) &&
620 item->GetDouble(kProbability, &probability)) { 621 item->GetDouble(kProbability, &probability)) {
621 // Normalize the the language code known and supported by 622 // Normalize the the language code known and supported by
622 // Translate. 623 // Translate.
623 translate::ToTranslateLanguageSynonym(&language); 624 translate::ToTranslateLanguageSynonym(&language);
624 // Discard if the normalized version is unsupported. 625 // Discard if the normalized version is unsupported.
625 if (TranslateDownloadManager::IsSupportedLanguage(language)) { 626 if (TranslateDownloadManager::IsSupportedLanguage(language)) {
626 probability_map[language] += probability; 627 probability_map[language] += probability;
627 } 628 }
628 } 629 }
629 } 630 }
630 for (const auto& it : probability_map) 631 for (const auto& it : probability_map)
631 out_value->push_back(it); 632 out_value->push_back(it);
632 std::sort(out_value->begin(), out_value->end(), 633 std::sort(out_value->begin(), out_value->end(),
633 [](const LanguageAndProbability& left, 634 [](const LanguageAndProbability& left,
634 const LanguageAndProbability& right) { 635 const LanguageAndProbability& right) {
635 return left.second > right.second; 636 return left.second > right.second;
636 }); 637 });
637 return confidence; 638 return confidence;
638 } 639 }
639 640
640 } // namespace translate 641 } // namespace translate
OLDNEW
« no previous file with comments | « components/sync_preferences/pref_model_associator.cc ('k') | components/update_client/component_patcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698