Commit 0a07473c authored by Michael Crouse's avatar Michael Crouse Committed by Chromium LUCI CQ

[TFLite] Cleaning up code to enable TFLite build.

Current usages do not run on the trybot, this change moves
the code towards compiling and running successfully.

Bug: 1165517
Change-Id: Ic9f06e296b9b5c4158923c3ba37f9a307a170776
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2623530Reviewed-by: default avatarSophie Chang <sophiechang@chromium.org>
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842349}
parent 9c0d79ae
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/tflite_experiment/tflite_experiment_keyed_service.h" #include "chrome/browser/tflite_experiment/tflite_experiment_keyed_service.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/task/thread_pool/thread_pool_instance.h" #include "base/task/thread_pool/thread_pool_instance.h"
...@@ -110,7 +111,8 @@ class TFLiteExperimentKeyedServiceBrowserTest : public InProcessBrowserTest { ...@@ -110,7 +111,8 @@ class TFLiteExperimentKeyedServiceBrowserTest : public InProcessBrowserTest {
// Set TFLite model path. // Set TFLite model path.
base::PathService::Get(chrome::DIR_TEST_DATA, &g_test_data_directory); base::PathService::Get(chrome::DIR_TEST_DATA, &g_test_data_directory);
g_test_data_directory = g_test_data_directory.Append(kTFLiteModelName); g_test_data_directory =
g_test_data_directory.Append(FILE_PATH_LITERAL(kTFLiteModelName));
cmd->AppendSwitchASCII(tflite_experiment::switches::kTFLiteModelPath, cmd->AppendSwitchASCII(tflite_experiment::switches::kTFLiteModelPath,
g_test_data_directory.value()); g_test_data_directory.value());
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#include "chrome/browser/tflite_experiment/tflite_experiment_observer.h" #include "chrome/browser/tflite_experiment/tflite_experiment_observer.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/metrics/histogram_macros_local.h" #include "base/metrics/histogram_macros_local.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tflite_experiment/tflite_experiment_keyed_service.h" #include "chrome/browser/tflite_experiment/tflite_experiment_keyed_service.h"
#include "chrome/browser/tflite_experiment/tflite_experiment_keyed_service_factory.h" #include "chrome/browser/tflite_experiment/tflite_experiment_keyed_service_factory.h"
...@@ -124,7 +127,11 @@ void TFLiteExperimentObserver::Log(base::Optional<std::string> log_path, ...@@ -124,7 +127,11 @@ void TFLiteExperimentObserver::Log(base::Optional<std::string> log_path,
const std::string& data) { const std::string& data) {
if (!log_path) if (!log_path)
return; return;
#if defined(OS_WIN)
base::FilePath log_file = base::FilePath(base::UTF8ToWide(log_path.value()));
#else
base::FilePath log_file = base::FilePath(log_path.value()); base::FilePath log_file = base::FilePath(log_path.value());
#endif
base::AppendToFile(log_file, data.c_str(), data.size()); base::AppendToFile(log_file, data.c_str(), data.size());
} }
...@@ -133,7 +140,11 @@ void TFLiteExperimentObserver::LogWriteHeader( ...@@ -133,7 +140,11 @@ void TFLiteExperimentObserver::LogWriteHeader(
base::Optional<std::string> log_path) { base::Optional<std::string> log_path) {
if (!log_path) if (!log_path)
return; return;
#if defined(OS_WIN)
base::FilePath log_file = base::FilePath(base::UTF8ToWide(log_path.value()));
#else
base::FilePath log_file = base::FilePath(log_path.value()); base::FilePath log_file = base::FilePath(log_path.value());
#endif
base::WriteFile(log_file, "", 0); base::WriteFile(log_file, "", 0);
} }
......
...@@ -14,6 +14,7 @@ source_set("machine_learning") { ...@@ -14,6 +14,7 @@ source_set("machine_learning") {
":metrics", ":metrics",
"//base", "//base",
"//chrome:strings", "//chrome:strings",
"//chrome/common:buildflags",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
] ]
...@@ -69,6 +70,8 @@ source_set("unit_tests") { ...@@ -69,6 +70,8 @@ source_set("unit_tests") {
":metrics", ":metrics",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//chrome/common:buildflags",
"//chrome/common:constants",
"//chrome/services/machine_learning/public/cpp:cpp", "//chrome/services/machine_learning/public/cpp:cpp",
"//chrome/services/machine_learning/public/cpp:test_support", "//chrome/services/machine_learning/public/cpp:test_support",
"//testing/gtest", "//testing/gtest",
......
...@@ -6,10 +6,14 @@ ...@@ -6,10 +6,14 @@
#include <string> #include <string>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -35,17 +39,19 @@ class InProcessTFLitePredictorTest : public ::testing::Test { ...@@ -35,17 +39,19 @@ class InProcessTFLitePredictorTest : public ::testing::Test {
InProcessTFLitePredictorTest() = default; InProcessTFLitePredictorTest() = default;
~InProcessTFLitePredictorTest() override = default; ~InProcessTFLitePredictorTest() override = default;
// Returns TFLite test model path // Returns TFLite test model path.
std::string GetTFLiteTestPath() { std::string GetTFLiteTestPath() {
// Location of generated test data (<(PROGRAM_DIR)/test_data). base::FilePath model_file_path;
base::FilePath g_gen_test_data_directory;
base::PathService::Get(chrome::DIR_GEN_TEST_DATA, EXPECT_TRUE(
&g_gen_test_data_directory); base::PathService::Get(base::DIR_SOURCE_ROOT, &model_file_path));
g_gen_test_data_directory =
g_gen_test_data_directory.Append("simple_test.tflite");
return g_gen_test_data_directory.value().c_str(); model_file_path = model_file_path.Append(FILE_PATH_LITERAL("chrome"))
.Append(FILE_PATH_LITERAL("test"))
.Append(FILE_PATH_LITERAL("data"))
.Append(FILE_PATH_LITERAL("simple_test.tflite"));
EXPECT_TRUE(base::PathExists(model_file_path));
return model_file_path.value().c_str();
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment