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

Side by Side Diff: components/translate/core/browser/language_model.h

Issue 2396783002: Add LanguageModel, a keyed service that collects language info from CLD. (Closed)
Patch Set: Created 4 years, 2 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
(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 // The current estimated frequency of the language share, a number between 0
Bernhard Bauer 2016/10/05 14:48:16 Nit: empty line before blocks of comments please,
jkrcal 2016/10/05 15:14:47 Done.
30 // and 1 (can be understood as the probability that the next page the user
31 // opens is in this language).
Bernhard Bauer 2016/10/05 14:48:16 Does that mean that the frequencies should sum to
jkrcal 2016/10/05 15:14:46 Yes, added a comment. The sum is not guaranteed to
32 float frequency;
33
34 bool operator==(const LanguageInfo& m) const {
35 return language_code == m.language_code && frequency == m.frequency;
36 }
37 };
38
39 explicit LanguageModel(PrefService* pref_service);
40 ~LanguageModel() override;
41
42 // Registers profile prefs for the model.
43 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
44
45 // Returns a list of the languages currently tracked by the model, sorted by
46 // frequency in decreasing order.
47 std::vector<LanguageInfo> GetTopLanguages() const;
48 // Returns the estimated frequency for the given language or 0 if the language
49 // is not among the top languages kept in the model.
50 float GetLanguageFrequency(const std::string& language_code) const;
51
52 // Informs the model that a page with the given language has been visited.
53 void OnPageVisited(const std::string& language_code);
54
55 private:
56 PrefService* pref_service_;
57 };
58
59 } // namespace translate
60
61 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698