| 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_TRANSLATE_RANKER_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ |
| 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 | 14 |
| 15 namespace chrome_intelligence { | 15 namespace chrome_intelligence { |
| 16 class TranslateRankerModel; | 16 class TranslateRankerModel; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace metrics { | 19 namespace metrics { |
| 20 class TranslateEventProto; | 20 class TranslateEventProto; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace translate { | 23 namespace translate { |
| 24 | 24 |
| 25 class TranslatePrefs; | 25 class TranslatePrefs; |
| 26 class TranslateURLFetcher; | 26 class TranslateURLFetcher; |
| 27 | 27 |
| 28 // Features used to enable ranker query, enforcement and logging. Note that | 28 // Features used to enable ranker query, enforcement and logging. Note that |
| 29 // enabling enforcement implies (forces) enabling queries. | 29 // enabling enforcement implies (forces) enabling queries. Enabling |
| 30 // DecisionOverride implies enabling Enforcement. |
| 30 extern const base::Feature kTranslateRankerQuery; | 31 extern const base::Feature kTranslateRankerQuery; |
| 31 extern const base::Feature kTranslateRankerEnforcement; | 32 extern const base::Feature kTranslateRankerEnforcement; |
| 32 extern const base::Feature kTranslateRankerLogging; | 33 extern const base::Feature kTranslateRankerLogging; |
| 34 extern const base::Feature kTranslateRankerDecisionOverride; |
| 33 | 35 |
| 34 // If enabled, downloads a translate ranker model and uses it to determine | 36 // If enabled, downloads a translate ranker model and uses it to determine |
| 35 // whether the user should be given a translation prompt or not. | 37 // whether the user should be given a translation prompt or not. |
| 36 class TranslateRanker { | 38 class TranslateRanker { |
| 37 public: | 39 public: |
| 38 ~TranslateRanker(); | 40 ~TranslateRanker(); |
| 39 | 41 |
| 40 // Returns true if query or enforcement is enabled. | 42 // Returns true if query or enforcement is enabled. |
| 41 static bool IsEnabled(); | 43 static bool IsEnabled(); |
| 42 | 44 |
| 43 // Returns true if translate events logging is enabled. | 45 // Returns true if translate events logging is enabled. |
| 44 static bool IsLoggingEnabled(); | 46 static bool IsLoggingEnabled(); |
| 45 | 47 |
| 46 // Returns true if querying is enabled. | 48 // Returns true if querying is enabled. |
| 47 static bool IsQueryEnabled(); | 49 static bool IsQueryEnabled(); |
| 48 | 50 |
| 49 // Returns true if enforcement is enabled. | 51 // Returns true if enforcement is enabled. |
| 50 static bool IsEnforcementEnabled(); | 52 static bool IsEnforcementEnabled(); |
| 51 | 53 |
| 54 // Returns true if heuristic decisions should be overriden. |
| 55 static bool IsDecisionOverrideEnabled(); |
| 56 |
| 52 // Returns the singleton TranslateRanker instance. | 57 // Returns the singleton TranslateRanker instance. |
| 53 static TranslateRanker* GetInstance(); | 58 static TranslateRanker* GetInstance(); |
| 54 | 59 |
| 55 // For testing only. Returns a TranslateRanker instance preloaded with a | 60 // For testing only. Returns a TranslateRanker instance preloaded with a |
| 56 // TranslateRankerModel as defined by |model_data|. | 61 // TranslateRankerModel as defined by |model_data|. |
| 57 static std::unique_ptr<TranslateRanker> CreateForTesting( | 62 static std::unique_ptr<TranslateRanker> CreateForTesting( |
| 58 const std::string& model_data); | 63 const std::string& model_data); |
| 59 | 64 |
| 60 // Initiates downloading of the assist model data. This is a NOP if the model | 65 // Initiates downloading of the assist model data. This is a NOP if the model |
| 61 // data has already been downloaded. | 66 // data has already been downloaded. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 FRIEND_TEST_ALL_PREFIXES(TranslateRankerTest, CalculateScore); | 124 FRIEND_TEST_ALL_PREFIXES(TranslateRankerTest, CalculateScore); |
| 120 | 125 |
| 121 friend struct base::DefaultSingletonTraits<TranslateRanker>; | 126 friend struct base::DefaultSingletonTraits<TranslateRanker>; |
| 122 | 127 |
| 123 DISALLOW_COPY_AND_ASSIGN(TranslateRanker); | 128 DISALLOW_COPY_AND_ASSIGN(TranslateRanker); |
| 124 }; | 129 }; |
| 125 | 130 |
| 126 } // namespace translate | 131 } // namespace translate |
| 127 | 132 |
| 128 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ | 133 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_RANKER_H_ |
| OLD | NEW |