Commit d7cc06cf authored by Sadrul Habib Chowdhury's avatar Sadrul Habib Chowdhury Committed by Commit Bot

cc benchmark: minor code cleanup.

. Use OnceCallback for the 'benchmark done' callback.
. Remove an unncessary callback-runner function.

BUG=none

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: Ib990293e05960755844fd1e5156e459b187c2e1c
Reviewed-on: https://chromium-review.googlesource.com/887163
Commit-Queue: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532083}
parent 7d2215a3
...@@ -29,8 +29,8 @@ const char* kDefaultInvalidationMode = "viewport"; ...@@ -29,8 +29,8 @@ const char* kDefaultInvalidationMode = "viewport";
InvalidationBenchmark::InvalidationBenchmark( InvalidationBenchmark::InvalidationBenchmark(
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback) MicroBenchmark::DoneCallback callback)
: MicroBenchmark(callback), seed_(0) { : MicroBenchmark(std::move(callback)), seed_(0) {
base::DictionaryValue* settings = nullptr; base::DictionaryValue* settings = nullptr;
value->GetAsDictionary(&settings); value->GetAsDictionary(&settings);
if (!settings) if (!settings)
......
...@@ -22,7 +22,7 @@ class LayerTreeHost; ...@@ -22,7 +22,7 @@ class LayerTreeHost;
class CC_EXPORT InvalidationBenchmark : public MicroBenchmark { class CC_EXPORT InvalidationBenchmark : public MicroBenchmark {
public: public:
explicit InvalidationBenchmark(std::unique_ptr<base::Value> value, explicit InvalidationBenchmark(std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback); MicroBenchmark::DoneCallback callback);
~InvalidationBenchmark() override; ~InvalidationBenchmark() override;
// Implements MicroBenchmark interface. // Implements MicroBenchmark interface.
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
namespace cc { namespace cc {
MicroBenchmark::MicroBenchmark(const DoneCallback& callback) MicroBenchmark::MicroBenchmark(DoneCallback callback)
: callback_(callback), : callback_(std::move(callback)),
is_done_(false), is_done_(false),
processed_for_benchmark_impl_(false), processed_for_benchmark_impl_(false),
id_(0) {} id_(0) {}
...@@ -30,7 +30,7 @@ bool MicroBenchmark::IsDone() const { ...@@ -30,7 +30,7 @@ bool MicroBenchmark::IsDone() const {
void MicroBenchmark::DidUpdateLayers(LayerTreeHost* layer_tree_host) {} void MicroBenchmark::DidUpdateLayers(LayerTreeHost* layer_tree_host) {}
void MicroBenchmark::NotifyDone(std::unique_ptr<base::Value> result) { void MicroBenchmark::NotifyDone(std::unique_ptr<base::Value> result) {
callback_.Run(std::move(result)); std::move(callback_).Run(std::move(result));
is_done_ = true; is_done_ = true;
} }
......
...@@ -23,9 +23,9 @@ class PictureLayer; ...@@ -23,9 +23,9 @@ class PictureLayer;
class MicroBenchmarkImpl; class MicroBenchmarkImpl;
class CC_EXPORT MicroBenchmark { class CC_EXPORT MicroBenchmark {
public: public:
typedef base::Callback<void(std::unique_ptr<base::Value>)> DoneCallback; using DoneCallback = base::OnceCallback<void(std::unique_ptr<base::Value>)>;
explicit MicroBenchmark(const DoneCallback& callback); explicit MicroBenchmark(DoneCallback callback);
virtual ~MicroBenchmark(); virtual ~MicroBenchmark();
bool IsDone() const; bool IsDone() const;
......
...@@ -27,14 +27,16 @@ namespace { ...@@ -27,14 +27,16 @@ namespace {
std::unique_ptr<MicroBenchmark> CreateBenchmark( std::unique_ptr<MicroBenchmark> CreateBenchmark(
const std::string& name, const std::string& name,
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback) { MicroBenchmark::DoneCallback callback) {
if (name == "invalidation_benchmark") { if (name == "invalidation_benchmark") {
return std::make_unique<InvalidationBenchmark>(std::move(value), callback); return std::make_unique<InvalidationBenchmark>(std::move(value),
std::move(callback));
} else if (name == "rasterize_and_record_benchmark") { } else if (name == "rasterize_and_record_benchmark") {
return std::make_unique<RasterizeAndRecordBenchmark>(std::move(value), return std::make_unique<RasterizeAndRecordBenchmark>(std::move(value),
callback); std::move(callback));
} else if (name == "unittest_only_benchmark") { } else if (name == "unittest_only_benchmark") {
return std::make_unique<UnittestOnlyBenchmark>(std::move(value), callback); return std::make_unique<UnittestOnlyBenchmark>(std::move(value),
std::move(callback));
} }
return nullptr; return nullptr;
} }
...@@ -54,9 +56,9 @@ MicroBenchmarkController::~MicroBenchmarkController() = default; ...@@ -54,9 +56,9 @@ MicroBenchmarkController::~MicroBenchmarkController() = default;
int MicroBenchmarkController::ScheduleRun( int MicroBenchmarkController::ScheduleRun(
const std::string& micro_benchmark_name, const std::string& micro_benchmark_name,
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback) { MicroBenchmark::DoneCallback callback) {
std::unique_ptr<MicroBenchmark> benchmark = std::unique_ptr<MicroBenchmark> benchmark = CreateBenchmark(
CreateBenchmark(micro_benchmark_name, std::move(value), callback); micro_benchmark_name, std::move(value), std::move(callback));
if (benchmark.get()) { if (benchmark.get()) {
int id = GetNextIdAndIncrement(); int id = GetNextIdAndIncrement();
benchmark->set_id(id); benchmark->set_id(id);
......
...@@ -31,7 +31,7 @@ class CC_EXPORT MicroBenchmarkController { ...@@ -31,7 +31,7 @@ class CC_EXPORT MicroBenchmarkController {
// Returns the id of the benchmark on success, 0 otherwise. // Returns the id of the benchmark on success, 0 otherwise.
int ScheduleRun(const std::string& micro_benchmark_name, int ScheduleRun(const std::string& micro_benchmark_name,
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback); MicroBenchmark::DoneCallback callback);
// Returns true if the message was successfully delivered and handled. // Returns true if the message was successfully delivered and handled.
bool SendMessage(int id, std::unique_ptr<base::Value> value); bool SendMessage(int id, std::unique_ptr<base::Value> value);
......
...@@ -14,18 +14,10 @@ ...@@ -14,18 +14,10 @@
namespace cc { namespace cc {
namespace {
void RunCallback(const MicroBenchmarkImpl::DoneCallback& callback,
std::unique_ptr<base::Value> result) {
callback.Run(std::move(result));
}
}
MicroBenchmarkImpl::MicroBenchmarkImpl( MicroBenchmarkImpl::MicroBenchmarkImpl(
const DoneCallback& callback, DoneCallback callback,
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner)
: callback_(callback), : callback_(std::move(callback)),
is_done_(false), is_done_(false),
origin_task_runner_(origin_task_runner) {} origin_task_runner_(origin_task_runner) {}
...@@ -39,7 +31,7 @@ void MicroBenchmarkImpl::DidCompleteCommit(LayerTreeHostImpl* host) {} ...@@ -39,7 +31,7 @@ void MicroBenchmarkImpl::DidCompleteCommit(LayerTreeHostImpl* host) {}
void MicroBenchmarkImpl::NotifyDone(std::unique_ptr<base::Value> result) { void MicroBenchmarkImpl::NotifyDone(std::unique_ptr<base::Value> result) {
origin_task_runner_->PostTask( origin_task_runner_->PostTask(
FROM_HERE, base::BindOnce(RunCallback, callback_, base::Passed(&result))); FROM_HERE, base::BindOnce(std::move(callback_), base::Passed(&result)));
is_done_ = true; is_done_ = true;
} }
......
...@@ -22,10 +22,10 @@ class LayerImpl; ...@@ -22,10 +22,10 @@ class LayerImpl;
class PictureLayerImpl; class PictureLayerImpl;
class CC_EXPORT MicroBenchmarkImpl { class CC_EXPORT MicroBenchmarkImpl {
public: public:
typedef base::Callback<void(std::unique_ptr<base::Value>)> DoneCallback; using DoneCallback = base::OnceCallback<void(std::unique_ptr<base::Value>)>;
explicit MicroBenchmarkImpl( explicit MicroBenchmarkImpl(
const DoneCallback& callback, DoneCallback callback,
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner); scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner);
virtual ~MicroBenchmarkImpl(); virtual ~MicroBenchmarkImpl();
......
...@@ -68,8 +68,8 @@ RecordingModeToPaintingControlSetting(RecordingSource::RecordingMode mode) { ...@@ -68,8 +68,8 @@ RecordingModeToPaintingControlSetting(RecordingSource::RecordingMode mode) {
RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark( RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark(
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback) MicroBenchmark::DoneCallback callback)
: MicroBenchmark(callback), : MicroBenchmark(std::move(callback)),
record_repeat_count_(kDefaultRecordRepeatCount), record_repeat_count_(kDefaultRecordRepeatCount),
settings_(std::move(value)), settings_(std::move(value)),
main_thread_benchmark_done_(false), main_thread_benchmark_done_(false),
......
...@@ -27,9 +27,8 @@ class LayerTreeHost; ...@@ -27,9 +27,8 @@ class LayerTreeHost;
class RasterizeAndRecordBenchmark : public MicroBenchmark { class RasterizeAndRecordBenchmark : public MicroBenchmark {
public: public:
explicit RasterizeAndRecordBenchmark( explicit RasterizeAndRecordBenchmark(std::unique_ptr<base::Value> value,
std::unique_ptr<base::Value> value, MicroBenchmark::DoneCallback callback);
const MicroBenchmark::DoneCallback& callback);
~RasterizeAndRecordBenchmark() override; ~RasterizeAndRecordBenchmark() override;
// Implements MicroBenchmark interface. // Implements MicroBenchmark interface.
......
...@@ -126,8 +126,8 @@ class FixedInvalidationPictureLayerTilingClient ...@@ -126,8 +126,8 @@ class FixedInvalidationPictureLayerTilingClient
RasterizeAndRecordBenchmarkImpl::RasterizeAndRecordBenchmarkImpl( RasterizeAndRecordBenchmarkImpl::RasterizeAndRecordBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner, scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner,
base::Value* value, base::Value* value,
const MicroBenchmarkImpl::DoneCallback& callback) MicroBenchmarkImpl::DoneCallback callback)
: MicroBenchmarkImpl(callback, origin_task_runner), : MicroBenchmarkImpl(std::move(callback), origin_task_runner),
rasterize_repeat_count_(kDefaultRasterizeRepeatCount) { rasterize_repeat_count_(kDefaultRasterizeRepeatCount) {
base::DictionaryValue* settings = nullptr; base::DictionaryValue* settings = nullptr;
value->GetAsDictionary(&settings); value->GetAsDictionary(&settings);
......
...@@ -26,7 +26,7 @@ class RasterizeAndRecordBenchmarkImpl : public MicroBenchmarkImpl { ...@@ -26,7 +26,7 @@ class RasterizeAndRecordBenchmarkImpl : public MicroBenchmarkImpl {
explicit RasterizeAndRecordBenchmarkImpl( explicit RasterizeAndRecordBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner, scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner,
base::Value* value, base::Value* value,
const MicroBenchmarkImpl::DoneCallback& callback); MicroBenchmarkImpl::DoneCallback callback);
~RasterizeAndRecordBenchmarkImpl() override; ~RasterizeAndRecordBenchmarkImpl() override;
// Implements MicroBenchmark interface. // Implements MicroBenchmark interface.
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
namespace cc { namespace cc {
UnittestOnlyBenchmark::UnittestOnlyBenchmark(std::unique_ptr<base::Value> value, UnittestOnlyBenchmark::UnittestOnlyBenchmark(std::unique_ptr<base::Value> value,
const DoneCallback& callback) DoneCallback callback)
: MicroBenchmark(callback), : MicroBenchmark(std::move(callback)),
create_impl_benchmark_(false), create_impl_benchmark_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
if (!value) if (!value)
......
...@@ -14,7 +14,7 @@ namespace cc { ...@@ -14,7 +14,7 @@ namespace cc {
class CC_EXPORT UnittestOnlyBenchmark : public MicroBenchmark { class CC_EXPORT UnittestOnlyBenchmark : public MicroBenchmark {
public: public:
UnittestOnlyBenchmark(std::unique_ptr<base::Value> value, UnittestOnlyBenchmark(std::unique_ptr<base::Value> value,
const DoneCallback& callback); DoneCallback callback);
~UnittestOnlyBenchmark() override; ~UnittestOnlyBenchmark() override;
void DidUpdateLayers(LayerTreeHost* layer_tree_host) override; void DidUpdateLayers(LayerTreeHost* layer_tree_host) override;
......
...@@ -12,8 +12,8 @@ namespace cc { ...@@ -12,8 +12,8 @@ namespace cc {
UnittestOnlyBenchmarkImpl::UnittestOnlyBenchmarkImpl( UnittestOnlyBenchmarkImpl::UnittestOnlyBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner, scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner,
base::Value* settings, base::Value* settings,
const DoneCallback& callback) DoneCallback callback)
: MicroBenchmarkImpl(callback, origin_task_runner) {} : MicroBenchmarkImpl(std::move(callback), origin_task_runner) {}
UnittestOnlyBenchmarkImpl::~UnittestOnlyBenchmarkImpl() = default; UnittestOnlyBenchmarkImpl::~UnittestOnlyBenchmarkImpl() = default;
......
...@@ -21,7 +21,7 @@ class CC_EXPORT UnittestOnlyBenchmarkImpl : public MicroBenchmarkImpl { ...@@ -21,7 +21,7 @@ class CC_EXPORT UnittestOnlyBenchmarkImpl : public MicroBenchmarkImpl {
UnittestOnlyBenchmarkImpl( UnittestOnlyBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner, scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner,
base::Value* settings, base::Value* settings,
const DoneCallback& callback); DoneCallback callback);
~UnittestOnlyBenchmarkImpl() override; ~UnittestOnlyBenchmarkImpl() override;
void DidCompleteCommit(LayerTreeHostImpl* host) override; void DidCompleteCommit(LayerTreeHostImpl* host) override;
......
...@@ -929,9 +929,9 @@ void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { ...@@ -929,9 +929,9 @@ void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
int LayerTreeHost::ScheduleMicroBenchmark( int LayerTreeHost::ScheduleMicroBenchmark(
const std::string& benchmark_name, const std::string& benchmark_name,
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback) { MicroBenchmark::DoneCallback callback) {
return micro_benchmark_controller_.ScheduleRun(benchmark_name, return micro_benchmark_controller_.ScheduleRun(
std::move(value), callback); benchmark_name, std::move(value), std::move(callback));
} }
bool LayerTreeHost::SendMessageToMicroBenchmark( bool LayerTreeHost::SendMessageToMicroBenchmark(
......
...@@ -222,7 +222,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient { ...@@ -222,7 +222,7 @@ class CC_EXPORT LayerTreeHost : public MutatorHostClient {
// Returns the id of the benchmark on success, 0 otherwise. // Returns the id of the benchmark on success, 0 otherwise.
int ScheduleMicroBenchmark(const std::string& benchmark_name, int ScheduleMicroBenchmark(const std::string& benchmark_name,
std::unique_ptr<base::Value> value, std::unique_ptr<base::Value> value,
const MicroBenchmark::DoneCallback& callback); MicroBenchmark::DoneCallback callback);
// Returns true if the message was successfully delivered and handled. // Returns true if the message was successfully delivered and handled.
bool SendMessageToMicroBenchmark(int id, std::unique_ptr<base::Value> value); bool SendMessageToMicroBenchmark(int id, std::unique_ptr<base::Value> value);
......
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