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

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: Rebase 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) && 619 if (entry.GetAsDictionary(&item) && item->GetString(kLanguage, &language) &&
620 item->GetString(kLanguage, &language) &&
621 item->GetDouble(kProbability, &probability)) { 620 item->GetDouble(kProbability, &probability)) {
622 // Normalize the the language code known and supported by 621 // Normalize the the language code known and supported by
623 // Translate. 622 // Translate.
624 translate::ToTranslateLanguageSynonym(&language); 623 translate::ToTranslateLanguageSynonym(&language);
625 // Discard if the normalized version is unsupported. 624 // Discard if the normalized version is unsupported.
626 if (TranslateDownloadManager::IsSupportedLanguage(language)) { 625 if (TranslateDownloadManager::IsSupportedLanguage(language)) {
627 probability_map[language] += probability; 626 probability_map[language] += probability;
628 } 627 }
629 } 628 }
630 } 629 }
631 for (const auto& it : probability_map) 630 for (const auto& it : probability_map)
632 out_value->push_back(it); 631 out_value->push_back(it);
633 std::sort(out_value->begin(), out_value->end(), 632 std::sort(out_value->begin(), out_value->end(),
634 [](const LanguageAndProbability& left, 633 [](const LanguageAndProbability& left,
635 const LanguageAndProbability& right) { 634 const LanguageAndProbability& right) {
636 return left.second > right.second; 635 return left.second > right.second;
637 }); 636 });
638 return confidence; 637 return confidence;
639 } 638 }
640 639
641 } // namespace translate 640 } // 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