| Index: components/translate/core/browser/translate_ranker.h
|
| diff --git a/components/translate/core/browser/translate_ranker.h b/components/translate/core/browser/translate_ranker.h
|
| index bb2da8b15eeed42f8c87a201b2752d949a9ec73d..a2c22f72d6de3a7829aa0b0bfd7b4e9443d14587 100644
|
| --- a/components/translate/core/browser/translate_ranker.h
|
| +++ b/components/translate/core/browser/translate_ranker.h
|
| @@ -7,119 +7,56 @@
|
|
|
| #include <memory>
|
| #include <string>
|
| +#include <vector>
|
|
|
| -#include "base/feature_list.h"
|
| -#include "base/gtest_prod_util.h"
|
| -#include "base/memory/singleton.h"
|
| -
|
| -namespace chrome_intelligence {
|
| -class TranslateRankerModel;
|
| -}
|
| +#include "base/macros.h"
|
| +#include "components/keyed_service/core/keyed_service.h"
|
|
|
| namespace metrics {
|
| class TranslateEventProto;
|
| -}
|
| +} // namespace metrics
|
|
|
| namespace translate {
|
|
|
| class TranslatePrefs;
|
| -class TranslateURLFetcher;
|
| -
|
| -// Features used to enable ranker query, enforcement and logging. Note that
|
| -// enabling enforcement implies (forces) enabling queries.
|
| -extern const base::Feature kTranslateRankerQuery;
|
| -extern const base::Feature kTranslateRankerEnforcement;
|
| -extern const base::Feature kTranslateRankerLogging;
|
|
|
| // If enabled, downloads a translate ranker model and uses it to determine
|
| // whether the user should be given a translation prompt or not.
|
| -class TranslateRanker {
|
| +class TranslateRanker : public KeyedService {
|
| public:
|
| - ~TranslateRanker();
|
| -
|
| - // Returns true if query or enforcement is enabled.
|
| - static bool IsEnabled();
|
| + TranslateRanker() = default;
|
|
|
| // Returns true if translate events logging is enabled.
|
| - static bool IsLoggingEnabled();
|
| -
|
| - // Returns true if querying is enabled.
|
| - static bool IsQueryEnabled();
|
| + virtual bool IsLoggingEnabled() = 0;
|
|
|
| // Returns true if enforcement is enabled.
|
| - static bool IsEnforcementEnabled();
|
| -
|
| - // Returns the singleton TranslateRanker instance.
|
| - static TranslateRanker* GetInstance();
|
| + virtual bool IsEnforcementEnabled() = 0;
|
|
|
| - // For testing only. Returns a TranslateRanker instance preloaded with a
|
| - // TranslateRankerModel as defined by |model_data|.
|
| - static std::unique_ptr<TranslateRanker> CreateForTesting(
|
| - const std::string& model_data);
|
| + // Returns true if querying is enabled. This is implicitly true if either
|
| + // enforcement or logging are enabled, but can also be enabled independently.
|
| + virtual bool IsQueryEnabled() = 0;
|
|
|
| - // Initiates downloading of the assist model data. This is a NOP if the model
|
| - // data has already been downloaded.
|
| - void FetchModelData();
|
| + // Returns the version id for the ranker model.
|
| + virtual int GetModelVersion() const = 0;
|
|
|
| // Returns true if executing the ranker model in the translation prompt
|
| // context described by |translate_prefs|, |src_lang|, |dst_lang| and possibly
|
| // other global browser context attributes suggests that the user should be
|
| // prompted as to whether translation should be performed.
|
| - bool ShouldOfferTranslation(const TranslatePrefs& translate_prefs,
|
| - const std::string& src_lang,
|
| - const std::string& dst_lang);
|
| -
|
| - // Returns the model version (a date stamp) or 0 if there is no valid model.
|
| - int GetModelVersion() const;
|
| + virtual bool ShouldOfferTranslation(const TranslatePrefs& translate_prefs,
|
| + const std::string& src_lang,
|
| + const std::string& dst_lang) = 0;
|
|
|
| // Caches the translate event.
|
| - void RecordTranslateEvent(
|
| - const metrics::TranslateEventProto& translate_event);
|
| + virtual void AddTranslateEvent(
|
| + const metrics::TranslateEventProto& translate_event) = 0;
|
|
|
| // Transfers cached translate events to the given vector pointer and clears
|
| // the cache.
|
| - void FlushTranslateEvents(
|
| - std::vector<metrics::TranslateEventProto>* translate_events);
|
| + virtual void FlushTranslateEvents(
|
| + std::vector<metrics::TranslateEventProto>* events) = 0;
|
|
|
| private:
|
| - // The ID which is assigned to the underlying URLFetcher.
|
| - static constexpr int kFetcherId = 2;
|
| -
|
| - TranslateRanker();
|
| -
|
| - // Exposed for testing via FRIEND_TEST.
|
| - double CalculateScore(int accept_count,
|
| - int decline_count,
|
| - int ignore_count,
|
| - const std::string& src_lang,
|
| - const std::string& dst_lang,
|
| - const std::string& app_locale,
|
| - const std::string& country);
|
| -
|
| - // Called when the model download has completed.
|
| - void ParseModel(int id, bool success, const std::string& model_data);
|
| -
|
| - // The translation ranker model.
|
| - std::unique_ptr<chrome_intelligence::TranslateRankerModel> model_;
|
| -
|
| - // A URL fetcher to download translation ranker model data.
|
| - std::unique_ptr<TranslateURLFetcher> model_fetcher_;
|
| -
|
| - // The next time before which no new attempts to download the model should be
|
| - // attempted.
|
| - base::Time next_earliest_download_time_;
|
| -
|
| - // Tracks the last time the translate ranker attempted to download its model.
|
| - // Used for UMA reporting of timing.
|
| - base::Time download_start_time_;
|
| -
|
| - // Saved cache of translate event protos.
|
| - std::vector<metrics::TranslateEventProto> translate_events_cache_;
|
| -
|
| - FRIEND_TEST_ALL_PREFIXES(TranslateRankerTest, CalculateScore);
|
| -
|
| - friend struct base::DefaultSingletonTraits<TranslateRanker>;
|
| -
|
| DISALLOW_COPY_AND_ASSIGN(TranslateRanker);
|
| };
|
|
|
|
|