Index: components/machine_intelligence/ranker_model_loader.h |
diff --git a/components/translate/core/browser/ranker_model_loader.h b/components/machine_intelligence/ranker_model_loader.h |
similarity index 86% |
rename from components/translate/core/browser/ranker_model_loader.h |
rename to components/machine_intelligence/ranker_model_loader.h |
index 68445b74ecd8a13547d1a324f60409e44385bbe9..60afa10fc8b49a1573621584e30bafe9a5245ac8 100644 |
--- a/components/translate/core/browser/ranker_model_loader.h |
+++ b/components/machine_intelligence/ranker_model_loader.h |
@@ -2,8 +2,8 @@ |
// 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_RANKER_MODEL_LOADER_H_ |
-#define COMPONENTS_TRANSLATE_CORE_BROWSER_RANKER_MODEL_LOADER_H_ |
+#ifndef COMPONENTS_MACHINE_INTELLIGENCE_RANKER_MODEL_LOADER_H_ |
+#define COMPONENTS_MACHINE_INTELLIGENCE_RANKER_MODEL_LOADER_H_ |
#include <memory> |
#include <string> |
@@ -14,19 +14,17 @@ |
#include "base/memory/weak_ptr.h" |
#include "base/sequence_checker.h" |
#include "base/time/time.h" |
+#include "net/url_request/url_request_context_getter.h" |
#include "url/gurl.h" |
namespace base { |
class SequencedTaskRunner; |
} // namespace base |
-namespace chrome_intelligence { |
-class RankerModel; |
-} // namespace chrome_intelligence |
- |
-namespace translate { |
+namespace machine_intelligence { |
-class TranslateURLFetcher; |
+class RankerURLFetcher; |
+class RankerModel; |
// Enumeration denoting the outcome of an attempt to download the model. This |
// must be kept in sync with the RankerModelStatus enum in histograms.xml |
@@ -44,8 +42,8 @@ enum class RankerModelStatus { |
MAX |
}; |
-// If enabled, downloads a translate ranker model and uses it to determine |
-// whether the user should be given a translation prompt or not. |
+// Loads a ranker model. Will attempt to load the model from disk cache. If it |
+// fails, will attempt to download from the given URL. |
class RankerModelLoader { |
public: |
// Callback to validate a ranker model on behalf of the model loader client. |
@@ -53,13 +51,13 @@ class RankerModelLoader { |
// the features generated when ranking translation offerings. This will be |
// called on the sequence on which the model loader was constructed. |
using ValidateModelCallback = base::RepeatingCallback<RankerModelStatus( |
- const chrome_intelligence::RankerModel&)>; |
+ const machine_intelligence::RankerModel&)>; |
// Called to transfer ownership of a loaded model back to the model loader |
// client. This will be called on the sequence on which the model loader was |
// constructed. |
using OnModelAvailableCallback = base::RepeatingCallback<void( |
- std::unique_ptr<chrome_intelligence::RankerModel>)>; |
+ std::unique_ptr<machine_intelligence::RankerModel>)>; |
// |validate_model_callback| may be called on any sequence; it must be thread |
// safe. |
@@ -80,6 +78,7 @@ class RankerModelLoader { |
// generated by this loader. |
RankerModelLoader(ValidateModelCallback validate_model_callback, |
OnModelAvailableCallback on_model_available_callback, |
+ net::URLRequestContextGetter* request_context_getter, |
base::FilePath model_path, |
GURL model_url, |
std::string uma_prefix); |
@@ -130,15 +129,14 @@ class RankerModelLoader { |
// Called when |url_fetcher_| has finished loading |data| from |model_url_|. |
// |
- // This call signature is mandated by TranslateURLFetcher. |
+ // This call signature is mandated by RankerURLFetcher. |
// |
- // id - the id given to the TranslateURLFetcher on creation |
// success - true of the download was successful |
// data - the body of the downloads response |
- void OnURLFetched(int id, bool success, const std::string& data); |
+ void OnURLFetched(bool success, const std::string& data); |
// Parse |data| and return a validated model. Returns nullptr on failure. |
- std::unique_ptr<chrome_intelligence::RankerModel> CreateAndValidateModel( |
+ std::unique_ptr<machine_intelligence::RankerModel> CreateAndValidateModel( |
const std::string& data); |
// Helper function to log |model_status| to UMA and return it. |
@@ -146,7 +144,7 @@ class RankerModelLoader { |
// Validates that ranker model loader tasks are all performed on the same |
// sequence. |
- base::SequenceChecker sequence_checker_; |
+ SEQUENCE_CHECKER(sequence_checker_); |
// The task runner on which background tasks are performed. |
const scoped_refptr<base::SequencedTaskRunner> background_task_runner_; |
@@ -160,6 +158,9 @@ class RankerModelLoader { |
// constructed. |
const OnModelAvailableCallback on_model_available_cb_; |
+ // Request Context Getter used for RankerURLFetcher. |
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
+ |
// The path at which the model is (or should be) cached. |
const base::FilePath model_path_; |
@@ -171,7 +172,7 @@ class RankerModelLoader { |
const std::string uma_prefix_; |
// Used to download model data from |model_url_|. |
- std::unique_ptr<TranslateURLFetcher> url_fetcher_; |
+ std::unique_ptr<RankerURLFetcher> url_fetcher_; |
// The next time before which no new attempts to download the model should be |
// attempted. |
@@ -190,6 +191,6 @@ class RankerModelLoader { |
DISALLOW_COPY_AND_ASSIGN(RankerModelLoader); |
}; |
-} // namespace translate |
+} // namespace machine_intelligence |
-#endif // COMPONENTS_TRANSLATE_CORE_BROWSER_RANKER_MODEL_LOADER_H_ |
+#endif // COMPONENTS_MACHINE_INTELLIGENCE_RANKER_MODEL_LOADER_H_ |