OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 |
| 14 class PrefRegistrySimple; |
| 15 class PrefService; |
| 16 |
| 17 namespace translate { |
| 18 |
| 19 // Collects data about languages in which the user reads the web and provides |
| 20 // access to current estimated language preferences. The past behaviour is |
| 21 // discounted so that this model reflects changes in browsing habits. This model |
| 22 // does not have to contain all languages that ever appeared in user's browsing, |
| 23 // languages with insignificant frequency are removed, eventually. |
| 24 class LanguageModel : public KeyedService { |
| 25 public: |
| 26 struct LanguageInfo { |
| 27 // The ISO 639 language code. |
| 28 std::string language_code; |
| 29 |
| 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 |
| 32 // opens is in this language). Frequencies over all LanguageInfos from |
| 33 // GetTopLanguages() sum to 1. |
| 34 float frequency; |
| 35 |
| 36 bool operator==(const LanguageInfo& m) const { |
| 37 return language_code == m.language_code; |
| 38 } |
| 39 }; |
| 40 |
| 41 explicit LanguageModel(PrefService* pref_service); |
| 42 ~LanguageModel() override; |
| 43 |
| 44 // Registers profile prefs for the model. |
| 45 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 46 |
| 47 // Returns a list of the languages currently tracked by the model, sorted by |
| 48 // frequency in decreasing order. |
| 49 std::vector<LanguageInfo> GetTopLanguages() const; |
| 50 |
| 51 // 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 float GetLanguageFrequency(const std::string& language_code) const; |
| 54 |
| 55 // Informs the model that a page with the given language has been visited. |
| 56 void OnPageVisited(const std::string& language_code); |
| 57 |
| 58 private: |
| 59 PrefService* pref_service_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(LanguageModel); |
| 62 }; |
| 63 |
| 64 } // namespace translate |
| 65 |
| 66 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
OLD | NEW |