Commit e8886050 authored by liberato@chromium.org's avatar liberato@chromium.org Committed by Commit Bot

Move ExperimentHelper to //media/blink

Change-Id: I831b6ffd1de72c70ffaba12e2d4ab6e7702be8c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857022Reviewed-by: default avatarThomas Guilbert <tguilbert@chromium.org>
Commit-Queue: Frank Liberato <liberato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705676}
parent cdd57771
......@@ -22,6 +22,8 @@ component("blink") {
"interval_map.h",
"key_system_config_selector.cc",
"key_system_config_selector.h",
"learning_experiment_helper.cc",
"learning_experiment_helper.h",
"lru.h",
"media_blink_export.h",
"multibuffer.cc",
......@@ -133,6 +135,7 @@ test("media_blink_unittests") {
"cache_util_unittest.cc",
"interval_map_unittest.cc",
"key_system_config_selector_unittest.cc",
"learning_experiment_helper_unittest.cc",
"lru_unittest.cc",
"mock_resource_fetch_context.cc",
"mock_resource_fetch_context.h",
......
......@@ -2,20 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/learning/common/experiment_helper.h"
#include "media/blink/learning_experiment_helper.h"
namespace media {
namespace learning {
ExperimentHelper::ExperimentHelper(
using learning::FeatureDictionary;
using learning::FeatureVector;
using learning::LearningTask;
using learning::LearningTaskController;
using learning::TargetValue;
LearningExperimentHelper::LearningExperimentHelper(
std::unique_ptr<LearningTaskController> controller)
: controller_(std::move(controller)) {}
ExperimentHelper::~ExperimentHelper() {
LearningExperimentHelper::~LearningExperimentHelper() {
CancelObservationIfNeeded();
}
void ExperimentHelper::BeginObservation(const FeatureDictionary& dictionary) {
void LearningExperimentHelper::BeginObservation(
const FeatureDictionary& dictionary) {
if (!controller_)
return;
......@@ -29,7 +35,8 @@ void ExperimentHelper::BeginObservation(const FeatureDictionary& dictionary) {
controller_->BeginObservation(observation_id_, features);
}
void ExperimentHelper::CompleteObservationIfNeeded(const TargetValue& target) {
void LearningExperimentHelper::CompleteObservationIfNeeded(
const TargetValue& target) {
if (!observation_id_)
return;
......@@ -37,7 +44,7 @@ void ExperimentHelper::CompleteObservationIfNeeded(const TargetValue& target) {
observation_id_ = base::UnguessableToken::Null();
}
void ExperimentHelper::CancelObservationIfNeeded() {
void LearningExperimentHelper::CancelObservationIfNeeded() {
if (!observation_id_)
return;
......@@ -45,5 +52,4 @@ void ExperimentHelper::CancelObservationIfNeeded() {
observation_id_ = base::UnguessableToken::Null();
}
} // namespace learning
} // namespace media
......@@ -2,53 +2,52 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_LEARNING_COMMON_EXPERIMENT_HELPER_H_
#define MEDIA_LEARNING_COMMON_EXPERIMENT_HELPER_H_
#ifndef MEDIA_BLINK_LEARNING_EXPERIMENT_HELPER_H_
#define MEDIA_BLINK_LEARNING_EXPERIMENT_HELPER_H_
#include <memory>
#include <string>
#include "base/component_export.h"
#include "base/macros.h"
#include "media/blink/media_blink_export.h"
#include "media/learning/common/feature_dictionary.h"
#include "media/learning/common/labelled_example.h"
#include "media/learning/common/learning_task.h"
#include "media/learning/common/learning_task_controller.h"
namespace media {
namespace learning {
// Helper for adding a learning experiment to existing code.
class COMPONENT_EXPORT(LEARNING_COMMON) ExperimentHelper {
class MEDIA_BLINK_EXPORT LearningExperimentHelper {
public:
// If |controller| is null, then everything else no-ops.
ExperimentHelper(std::unique_ptr<LearningTaskController> controller);
LearningExperimentHelper(
std::unique_ptr<learning::LearningTaskController> controller);
// Cancels any existing observation.
~ExperimentHelper();
~LearningExperimentHelper();
// Start a new observation. Any existing observation is cancelled. Does
// nothing if there's no controller.
void BeginObservation(const FeatureDictionary& dictionary);
void BeginObservation(const learning::FeatureDictionary& dictionary);
// Complete any pending observation. Does nothing if none is in progress.
void CompleteObservationIfNeeded(const TargetValue& target);
void CompleteObservationIfNeeded(const learning::TargetValue& target);
// Cancel any pending observation.
void CancelObservationIfNeeded();
private:
// May be null.
std::unique_ptr<LearningTaskController> controller_;
std::unique_ptr<learning::LearningTaskController> controller_;
// May be null if no observation is in flight. Must be null if |controller_|
// is null.
base::UnguessableToken observation_id_;
DISALLOW_COPY_AND_ASSIGN(ExperimentHelper);
DISALLOW_COPY_AND_ASSIGN(LearningExperimentHelper);
};
} // namespace learning
} // namespace media
#endif // MEDIA_LEARNING_COMMON_EXPERIMENT_HELPER_H_
#endif // MEDIA_BLINK_LEARNING_EXPERIMENT_HELPER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/learning/common/experiment_helper.h"
#include "media/blink/learning_experiment_helper.h"
#include <memory>
......@@ -10,10 +10,16 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using media::learning::FeatureDictionary;
using media::learning::FeatureValue;
using media::learning::FeatureVector;
using media::learning::LearningTask;
using media::learning::LearningTaskController;
using media::learning::ObservationCompletion;
using media::learning::TargetValue;
using testing::_;
namespace media {
namespace learning {
class MockLearningTaskController : public LearningTaskController {
public:
......@@ -36,7 +42,7 @@ class MockLearningTaskController : public LearningTaskController {
DISALLOW_COPY_AND_ASSIGN(MockLearningTaskController);
};
class ExperimentHelperTest : public testing::Test {
class LearningExperimentHelperTest : public testing::Test {
public:
void SetUp() override {
const std::string feature_name_1("feature 1");
......@@ -59,17 +65,17 @@ class ExperimentHelperTest : public testing::Test {
std::make_unique<MockLearningTaskController>(task_);
controller_raw_ = controller.get();
helper_ = std::make_unique<ExperimentHelper>(std::move(controller));
helper_ = std::make_unique<LearningExperimentHelper>(std::move(controller));
}
LearningTask task_;
MockLearningTaskController* controller_raw_ = nullptr;
std::unique_ptr<ExperimentHelper> helper_;
std::unique_ptr<LearningExperimentHelper> helper_;
FeatureDictionary dict_;
};
TEST_F(ExperimentHelperTest, BeginComplete) {
TEST_F(LearningExperimentHelperTest, BeginComplete) {
EXPECT_CALL(*controller_raw_, BeginObservation(_, _, _));
helper_->BeginObservation(dict_);
TargetValue target(123);
......@@ -86,30 +92,30 @@ TEST_F(ExperimentHelperTest, BeginComplete) {
helper_->CompleteObservationIfNeeded(target);
}
TEST_F(ExperimentHelperTest, BeginCancel) {
TEST_F(LearningExperimentHelperTest, BeginCancel) {
EXPECT_CALL(*controller_raw_, BeginObservation(_, _, _));
helper_->BeginObservation(dict_);
EXPECT_CALL(*controller_raw_, CancelObservation(_));
helper_->CancelObservationIfNeeded();
}
TEST_F(ExperimentHelperTest, CompleteWithoutBeginDoesNothing) {
TEST_F(LearningExperimentHelperTest, CompleteWithoutBeginDoesNothing) {
EXPECT_CALL(*controller_raw_, BeginObservation(_, _, _)).Times(0);
EXPECT_CALL(*controller_raw_, CompleteObservation(_, _)).Times(0);
EXPECT_CALL(*controller_raw_, CancelObservation(_)).Times(0);
helper_->CompleteObservationIfNeeded(TargetValue(123));
}
TEST_F(ExperimentHelperTest, CancelWithoutBeginDoesNothing) {
TEST_F(LearningExperimentHelperTest, CancelWithoutBeginDoesNothing) {
EXPECT_CALL(*controller_raw_, BeginObservation(_, _, _)).Times(0);
EXPECT_CALL(*controller_raw_, CompleteObservation(_, _)).Times(0);
EXPECT_CALL(*controller_raw_, CancelObservation(_)).Times(0);
helper_->CancelObservationIfNeeded();
}
TEST_F(ExperimentHelperTest, DoesNothingWithoutController) {
TEST_F(LearningExperimentHelperTest, DoesNothingWithoutController) {
// Make sure that nothing crashes if there's no controller.
ExperimentHelper helper(nullptr);
LearningExperimentHelper helper(nullptr);
// Begin / complete.
helper_->BeginObservation(dict_);
......@@ -124,5 +130,4 @@ TEST_F(ExperimentHelperTest, DoesNothingWithoutController) {
helper_->CancelObservationIfNeeded();
}
} // namespace learning
} // namespace media
......@@ -35,12 +35,12 @@
#include "media/base/simple_watch_timer.h"
#include "media/base/text_track.h"
#include "media/blink/buffered_data_source_host_impl.h"
#include "media/blink/learning_experiment_helper.h"
#include "media/blink/media_blink_export.h"
#include "media/blink/multibuffer_data_source.h"
#include "media/blink/video_frame_compositor.h"
#include "media/blink/webmediaplayer_params.h"
#include "media/filters/pipeline_controller.h"
#include "media/learning/common/experiment_helper.h"
#include "media/renderers/paint_canvas_video_renderer.h"
#include "services/media_session/public/cpp/media_position.h"
#include "third_party/blink/public/platform/media/webmediaplayer_delegate.h"
......@@ -1015,7 +1015,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
RendererFactorySelector::FactoryType reported_renderer_type_;
SimpleWatchTimer simple_watch_timer_;
learning::ExperimentHelper will_play_helper_;
LearningExperimentHelper will_play_helper_;
base::WeakPtr<WebMediaPlayerImpl> weak_this_;
base::WeakPtrFactory<WebMediaPlayerImpl> weak_factory_{this};
......
......@@ -24,8 +24,6 @@ component("common") {
defines = [ "IS_LEARNING_COMMON_IMPL" ]
sources = [
"experiment_helper.cc",
"experiment_helper.h",
"feature_dictionary.cc",
"feature_dictionary.h",
"feature_library.cc",
......@@ -52,7 +50,6 @@ component("common") {
source_set("unit_tests") {
testonly = true
sources = [
"experiment_helper_unittest.cc",
"feature_dictionary_unittest.cc",
"labelled_example_unittest.cc",
"media_learning_tasks_unittest.cc",
......
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