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 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
13 | 13 |
14 class PrefRegistrySimple; | 14 class PrefRegistrySimple; |
15 class PrefService; | 15 class PrefService; |
16 | 16 |
17 namespace translate { | 17 namespace translate { |
18 | 18 |
19 // Collects data about languages in which the user reads the web and provides | 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 | 20 // access to current estimated language preferences. The past behaviour is |
21 // discounted so that this model reflects changes in browsing habits. This model | 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, | 22 // does not have to contain all languages that ever appeared in user's browsing, |
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 LanguageInfo() = default; | |
Bernhard Bauer
2016/10/26 09:24:02
So, is there a rule for when to use {} and when to
Marc Treib
2016/10/26 09:29:40
I don't know of any "official" rule - my personal
| |
28 LanguageInfo(const std::string& language_code, float frequency) | |
29 : language_code(language_code), frequency(frequency) {} | |
30 | |
27 // The ISO 639 language code. | 31 // The ISO 639 language code. |
28 std::string language_code; | 32 std::string language_code; |
29 | 33 |
30 // The current estimated frequency of the language share, a number between 0 | 34 // 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 | 35 // 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 | 36 // opens is in this language). Frequencies over all LanguageInfos from |
33 // GetTopLanguages() sum to 1 (unless there are no top languages, yet). | 37 // GetTopLanguages() sum to 1 (unless there are no top languages, yet). |
34 float frequency; | 38 float frequency = 0.0f; |
Marc Treib
2016/10/26 09:21:05
Uninitialized values are Teh Evilz! :)
Unfortunate
| |
35 | 39 |
36 bool operator==(const LanguageInfo& m) const { | 40 bool operator==(const LanguageInfo& m) const { |
37 return language_code == m.language_code; | 41 return language_code == m.language_code; |
38 } | 42 } |
39 }; | 43 }; |
40 | 44 |
41 explicit LanguageModel(PrefService* pref_service); | 45 explicit LanguageModel(PrefService* pref_service); |
42 ~LanguageModel() override; | 46 ~LanguageModel() override; |
43 | 47 |
44 // Registers profile prefs for the model. | 48 // Registers profile prefs for the model. |
(...skipping 13 matching lines...) Expand all Loading... | |
58 | 62 |
59 private: | 63 private: |
60 PrefService* pref_service_; | 64 PrefService* pref_service_; |
61 | 65 |
62 DISALLOW_COPY_AND_ASSIGN(LanguageModel); | 66 DISALLOW_COPY_AND_ASSIGN(LanguageModel); |
63 }; | 67 }; |
64 | 68 |
65 } // namespace translate | 69 } // namespace translate |
66 | 70 |
67 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ | 71 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
OLD | NEW |