| 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 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // languages with insignificant frequency are removed, eventually. | 23 // languages with insignificant frequency are removed, eventually. |
| 24 class LanguageModel : public KeyedService { | 24 class LanguageModel : public KeyedService { |
| 25 public: | 25 public: |
| 26 struct LanguageInfo { | 26 struct LanguageInfo { |
| 27 // The ISO 639 language code. | 27 // The ISO 639 language code. |
| 28 std::string language_code; | 28 std::string language_code; |
| 29 | 29 |
| 30 // The current estimated frequency of the language share, a number between 0 | 30 // The current estimated frequency of the language share, a number between 0 |
| 31 // and 1 (can be understood as the probability that the next page the user | 31 // and 1 (can be understood as the probability that the next page the user |
| 32 // opens is in this language). Frequencies over all LanguageInfos from | 32 // opens is in this language). Frequencies over all LanguageInfos from |
| 33 // GetTopLanguages() sum to 1. | 33 // GetTopLanguages() sum to 1 (unless there are no top languages, yet). |
| 34 float frequency; | 34 float frequency; |
| 35 | 35 |
| 36 bool operator==(const LanguageInfo& m) const { | 36 bool operator==(const LanguageInfo& m) const { |
| 37 return language_code == m.language_code; | 37 return language_code == m.language_code; |
| 38 } | 38 } |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 explicit LanguageModel(PrefService* pref_service); | 41 explicit LanguageModel(PrefService* pref_service); |
| 42 ~LanguageModel() override; | 42 ~LanguageModel() override; |
| 43 | 43 |
| 44 // Registers profile prefs for the model. | 44 // Registers profile prefs for the model. |
| 45 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 45 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 46 | 46 |
| 47 // Returns a list of the languages currently tracked by the model, sorted by | 47 // Returns a list of the languages currently tracked by the model, sorted by |
| 48 // frequency in decreasing order. | 48 // frequency in decreasing order. The list is empty, if the model has not |
| 49 // enough data points. |
| 49 std::vector<LanguageInfo> GetTopLanguages() const; | 50 std::vector<LanguageInfo> GetTopLanguages() const; |
| 50 | 51 |
| 51 // Returns the estimated frequency for the given language or 0 if the language | 52 // Returns the estimated frequency for the given language or 0 if the language |
| 52 // is not among the top languages kept in the model. | 53 // is not among the top languages kept in the model. |
| 53 float GetLanguageFrequency(const std::string& language_code) const; | 54 float GetLanguageFrequency(const std::string& language_code) const; |
| 54 | 55 |
| 55 // Informs the model that a page with the given language has been visited. | 56 // Informs the model that a page with the given language has been visited. |
| 56 void OnPageVisited(const std::string& language_code); | 57 void OnPageVisited(const std::string& language_code); |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 PrefService* pref_service_; | 60 PrefService* pref_service_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(LanguageModel); | 62 DISALLOW_COPY_AND_ASSIGN(LanguageModel); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 } // namespace translate | 65 } // namespace translate |
| 65 | 66 |
| 66 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ | 67 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| OLD | NEW |