| 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..c8dc0e0ac13f44eab8378a098327d2c98c6a2e31
|
| --- /dev/null
|
| +++ b/components/translate/core/browser/language_model.h
|
| @@ -0,0 +1,64 @@
|
| +// 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
|
| + // and 1 (can be understood as the probability that the next page the user
|
| + // opens is in this language). Frequencies over all LanguageInfos from
|
| + // GetTopLanguages() sum to 1.
|
| + float frequency;
|
| +
|
| + bool operator==(const LanguageInfo& m) const {
|
| + return language_code == m.language_code;
|
| + }
|
| + };
|
| +
|
| + 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_
|
|
|