Commit ab84faea authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

SequenceBound: migrate from Post() to AsyncCall() in media classes.

Bug: 1140588
Change-Id: I2c55eeae2125a4c4dea4683a2a017723c3f14e22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2488320Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820173}
parent e063f324
...@@ -454,8 +454,10 @@ void CdmFileImpl::Read(ReadCallback callback) { ...@@ -454,8 +454,10 @@ void CdmFileImpl::Read(ReadCallback callback) {
// |this|, and if |this| is destructed it will destroy the file reader on the // |this|, and if |this| is destructed it will destroy the file reader on the
// IO thread. // IO thread.
file_reader_ = base::SequenceBound<FileReader>(GetIOThreadTaskRunner({})); file_reader_ = base::SequenceBound<FileReader>(GetIOThreadTaskRunner({}));
file_reader_.Post(FROM_HERE, &FileReader::Read, file_system_context_, // TODO(dcheng): Migrate this to use Then()?
CreateFileSystemURL(file_name_), std::move(read_done_cb)); file_reader_.AsyncCall(&FileReader::Read)
.WithArgs(file_system_context_, CreateFileSystemURL(file_name_),
std::move(read_done_cb));
} }
void CdmFileImpl::ReadDone(bool success, std::vector<uint8_t> data) { void CdmFileImpl::ReadDone(bool success, std::vector<uint8_t> data) {
...@@ -601,9 +603,10 @@ void CdmFileImpl::OnTempFileIsEmpty(scoped_refptr<net::IOBuffer> buffer, ...@@ -601,9 +603,10 @@ void CdmFileImpl::OnTempFileIsEmpty(scoped_refptr<net::IOBuffer> buffer,
// base::Unretained() is OK as |file_writer_| is owned by |this|, and if // base::Unretained() is OK as |file_writer_| is owned by |this|, and if
// |this| is destructed it will destroy |file_writer_| on the IO thread. // |this| is destructed it will destroy |file_writer_| on the IO thread.
file_writer_ = base::SequenceBound<FileWriter>(GetIOThreadTaskRunner({})); file_writer_ = base::SequenceBound<FileWriter>(GetIOThreadTaskRunner({}));
file_writer_.Post(FROM_HERE, &FileWriter::Write, file_system_context_, // TODO(dcheng): Migrate this to use Then()?
CreateFileSystemURL(temp_file_name_), std::move(buffer), file_writer_.AsyncCall(&FileWriter::Write)
bytes_to_write, std::move(write_done_cb)); .WithArgs(file_system_context_, CreateFileSystemURL(temp_file_name_),
std::move(buffer), bytes_to_write, std::move(write_done_cb));
} }
void CdmFileImpl::WriteDone(bool success) { void CdmFileImpl::WriteDone(bool success) {
......
...@@ -37,12 +37,11 @@ class WeakLearningTaskController : public LearningTaskController { ...@@ -37,12 +37,11 @@ class WeakLearningTaskController : public LearningTaskController {
for (auto& id : outstanding_observations_) { for (auto& id : outstanding_observations_) {
const base::Optional<TargetValue>& default_value = id.second; const base::Optional<TargetValue>& default_value = id.second;
if (default_value) { if (default_value) {
controller_->Post(FROM_HERE, controller_->AsyncCall(&LearningTaskController::CompleteObservation)
&LearningTaskController::CompleteObservation, .WithArgs(id.first, *default_value);
id.first, *default_value);
} else { } else {
controller_->Post(FROM_HERE, &LearningTaskController::CancelObservation, controller_->AsyncCall(&LearningTaskController::CancelObservation)
id.first); .WithArgs(id.first);
} }
} }
} }
...@@ -59,8 +58,8 @@ class WeakLearningTaskController : public LearningTaskController { ...@@ -59,8 +58,8 @@ class WeakLearningTaskController : public LearningTaskController {
// We don't send along the default value because LearningTaskControllerImpl // We don't send along the default value because LearningTaskControllerImpl
// doesn't support it. Since all client calls eventually come through us // doesn't support it. Since all client calls eventually come through us
// anyway, it seems okay to handle it here. // anyway, it seems okay to handle it here.
controller_->Post(FROM_HERE, &LearningTaskController::BeginObservation, id, controller_->AsyncCall(&LearningTaskController::BeginObservation)
features, base::nullopt, source_id); .WithArgs(id, features, base::nullopt, source_id);
} }
void CompleteObservation(base::UnguessableToken id, void CompleteObservation(base::UnguessableToken id,
...@@ -68,16 +67,16 @@ class WeakLearningTaskController : public LearningTaskController { ...@@ -68,16 +67,16 @@ class WeakLearningTaskController : public LearningTaskController {
if (!weak_session_) if (!weak_session_)
return; return;
outstanding_observations_.erase(id); outstanding_observations_.erase(id);
controller_->Post(FROM_HERE, &LearningTaskController::CompleteObservation, controller_->AsyncCall(&LearningTaskController::CompleteObservation)
id, completion); .WithArgs(id, completion);
} }
void CancelObservation(base::UnguessableToken id) override { void CancelObservation(base::UnguessableToken id) override {
if (!weak_session_) if (!weak_session_)
return; return;
outstanding_observations_.erase(id); outstanding_observations_.erase(id);
controller_->Post(FROM_HERE, &LearningTaskController::CancelObservation, controller_->AsyncCall(&LearningTaskController::CancelObservation)
id); .WithArgs(id);
} }
void UpdateDefaultTarget( void UpdateDefaultTarget(
...@@ -93,8 +92,8 @@ class WeakLearningTaskController : public LearningTaskController { ...@@ -93,8 +92,8 @@ class WeakLearningTaskController : public LearningTaskController {
void PredictDistribution(const FeatureVector& features, void PredictDistribution(const FeatureVector& features,
PredictionCB callback) override { PredictionCB callback) override {
controller_->Post(FROM_HERE, &LearningTaskController::PredictDistribution, controller_->AsyncCall(&LearningTaskController::PredictDistribution)
features, std::move(callback)); .WithArgs(features, std::move(callback));
} }
base::WeakPtr<LearningSessionImpl> weak_session_; base::WeakPtr<LearningSessionImpl> weak_session_;
......
...@@ -34,9 +34,8 @@ class LearningSessionImplTest : public testing::Test { ...@@ -34,9 +34,8 @@ class LearningSessionImplTest : public testing::Test {
// As a complete hack, call the only public method on fp so that // As a complete hack, call the only public method on fp so that
// we can verify that it was given to us by the session. // we can verify that it was given to us by the session.
if (!feature_provider_.is_null()) { if (!feature_provider_.is_null()) {
feature_provider_.Post(FROM_HERE, &FeatureProvider::AddFeatures, feature_provider_.AsyncCall(&FeatureProvider::AddFeatures)
FeatureVector(), .WithArgs(FeatureVector(), FeatureProvider::FeatureVectorCB());
FeatureProvider::FeatureVectorCB());
} }
} }
......
...@@ -35,10 +35,12 @@ void LearningTaskControllerHelper::BeginObservation( ...@@ -35,10 +35,12 @@ void LearningTaskControllerHelper::BeginObservation(
// Start feature prediction, so that we capture the current values. // Start feature prediction, so that we capture the current values.
if (!feature_provider_.is_null()) { if (!feature_provider_.is_null()) {
feature_provider_.Post( // TODO(dcheng): Convert this to use Then() helper.
FROM_HERE, &FeatureProvider::AddFeatures, std::move(features), feature_provider_.AsyncCall(&FeatureProvider::AddFeatures)
base::BindOnce(&LearningTaskControllerHelper::OnFeaturesReadyTrampoline, .WithArgs(std::move(features),
task_runner_, AsWeakPtr(), id)); base::BindOnce(
&LearningTaskControllerHelper::OnFeaturesReadyTrampoline,
task_runner_, AsWeakPtr(), id));
} else { } else {
pending_example.example.features = std::move(features); pending_example.example.features = std::move(features);
pending_example.features_done = true; pending_example.features_done = true;
......
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