Chromium Code Reviews| Index: components/translate/core/browser/language_model.h |
| diff --git a/components/translate/core/browser/language_model.h b/components/translate/core/browser/language_model.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bf6d2225311cb43e03182182c56787a1967c1877 |
| --- /dev/null |
| +++ b/components/translate/core/browser/language_model.h |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| +#define COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "components/keyed_service/core/keyed_service.h" |
| + |
| +class PrefRegistrySimple; |
| +class PrefService; |
| + |
| +namespace translate { |
| + |
| +// Collects data about languages in which the user reads the web and provides |
| +// access to current estimated language preferences. The past behaviour is |
| +// discounted so that this model reflects changes in browsing habits. This model |
| +// does not have to contain all languages that ever appeared in user's browsing, |
| +// languages with insignificant frequency are removed, eventually. |
| +class LanguageModel : public KeyedService { |
| + public: |
| + struct LanguageInfo { |
| + // The ISO 639 language code. |
| + std::string language_code; |
| + // 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.
|
| + // and 1 (can be understood as the probability that the next page the user |
| + // 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
|
| + float frequency; |
| + |
| + bool operator==(const LanguageInfo& m) const { |
| + return language_code == m.language_code && frequency == m.frequency; |
| + } |
| + }; |
| + |
| + explicit LanguageModel(PrefService* pref_service); |
| + ~LanguageModel() override; |
| + |
| + // Registers profile prefs for the model. |
| + static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| + |
| + // Returns a list of the languages currently tracked by the model, sorted by |
| + // frequency in decreasing order. |
| + std::vector<LanguageInfo> GetTopLanguages() const; |
| + // Returns the estimated frequency for the given language or 0 if the language |
| + // is not among the top languages kept in the model. |
| + float GetLanguageFrequency(const std::string& language_code) const; |
| + |
| + // Informs the model that a page with the given language has been visited. |
| + void OnPageVisited(const std::string& language_code); |
| + |
| + private: |
| + PrefService* pref_service_; |
| +}; |
| + |
| +} // namespace translate |
| + |
| +#endif // COMPONENTS_TRANSLATE_CORE_BROWSER_LANGUAGE_MODEL_H_ |