Update cc/benchmarks to new Value API
Update downstream code to match.
Bug: 646113
Change-Id: Iba3c6d4846fd65408be1d8ea96022de2f7f76a42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4292220
Reviewed-by: Robert Flack <flackr@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Commit-Queue: Robert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1111076}
diff --git a/cc/benchmarks/invalidation_benchmark.cc b/cc/benchmarks/invalidation_benchmark.cc
index 0a93014..e71c946 100644
--- a/cc/benchmarks/invalidation_benchmark.cc
+++ b/cc/benchmarks/invalidation_benchmark.cc
@@ -30,22 +30,19 @@
} // namespace
InvalidationBenchmark::InvalidationBenchmark(
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback)
- : MicroBenchmark(std::move(callback)), seed_(0) {
- if (!settings.is_dict())
- return;
-
+ : MicroBenchmark(std::move(callback)) {
std::string mode_string = kDefaultInvalidationMode;
- auto* mode_string_from_settings = settings.FindStringKey("mode");
+ auto* mode_string_from_settings = settings.FindString("mode");
if (mode_string_from_settings)
mode_string = *mode_string_from_settings;
if (mode_string == "fixed_size") {
mode_ = FIXED_SIZE;
- auto width = settings.FindIntKey("width");
- auto height = settings.FindIntKey("height");
+ auto width = settings.FindInt("width");
+ auto height = settings.FindInt("height");
CHECK(width.has_value()) << "Must provide a width for fixed_size mode.";
CHECK(height.has_value()) << "Must provide a height for fixed_size mode.";
width_ = *width;
@@ -112,14 +109,12 @@
}
}
-bool InvalidationBenchmark::ProcessMessage(base::Value message) {
- if (!message.is_dict())
- return false;
-
- auto notify_done = message.FindBoolKey("notify_done");
+bool InvalidationBenchmark::ProcessMessage(base::Value::Dict message) {
+ auto notify_done = message.FindBool("notify_done");
if (notify_done.has_value()) {
- if (*notify_done)
- NotifyDone(base::Value());
+ if (notify_done.value()) {
+ NotifyDone(base::Value::Dict());
+ }
return true;
}
return false;
diff --git a/cc/benchmarks/invalidation_benchmark.h b/cc/benchmarks/invalidation_benchmark.h
index d367a579..444b124 100644
--- a/cc/benchmarks/invalidation_benchmark.h
+++ b/cc/benchmarks/invalidation_benchmark.h
@@ -19,14 +19,14 @@
// measurement.
class CC_EXPORT InvalidationBenchmark : public MicroBenchmark {
public:
- explicit InvalidationBenchmark(base::Value settings,
+ explicit InvalidationBenchmark(base::Value::Dict settings,
MicroBenchmark::DoneCallback callback);
~InvalidationBenchmark() override;
// Implements MicroBenchmark interface.
void DidUpdateLayers(LayerTreeHost* layer_tree_host) override;
void RunOnLayer(PictureLayer* layer) override;
- bool ProcessMessage(base::Value message) override;
+ bool ProcessMessage(base::Value::Dict message) override;
private:
enum Mode { FIXED_SIZE, LAYER, VIEWPORT, RANDOM };
@@ -36,7 +36,7 @@
Mode mode_;
int width_;
int height_;
- uint32_t seed_;
+ uint32_t seed_ = 0;
};
} // namespace cc
diff --git a/cc/benchmarks/micro_benchmark.cc b/cc/benchmarks/micro_benchmark.cc
index 46373b5..be84709 100644
--- a/cc/benchmarks/micro_benchmark.cc
+++ b/cc/benchmarks/micro_benchmark.cc
@@ -16,10 +16,7 @@
namespace cc {
MicroBenchmark::MicroBenchmark(DoneCallback callback)
- : callback_(std::move(callback)),
- is_done_(false),
- processed_for_benchmark_impl_(false),
- id_(0) {}
+ : callback_(std::move(callback)) {}
MicroBenchmark::~MicroBenchmark() = default;
@@ -29,14 +26,14 @@
void MicroBenchmark::DidUpdateLayers(LayerTreeHost* layer_tree_host) {}
-void MicroBenchmark::NotifyDone(base::Value result) {
+void MicroBenchmark::NotifyDone(base::Value::Dict result) {
std::move(callback_).Run(std::move(result));
is_done_ = true;
}
void MicroBenchmark::RunOnLayer(PictureLayer* layer) {}
-bool MicroBenchmark::ProcessMessage(base::Value message) {
+bool MicroBenchmark::ProcessMessage(base::Value::Dict message) {
return false;
}
diff --git a/cc/benchmarks/micro_benchmark.h b/cc/benchmarks/micro_benchmark.h
index 932c17cb..609aef7a 100644
--- a/cc/benchmarks/micro_benchmark.h
+++ b/cc/benchmarks/micro_benchmark.h
@@ -8,11 +8,11 @@
#include <memory>
#include "base/functional/callback.h"
+#include "base/values.h"
#include "cc/cc_export.h"
namespace base {
class SingleThreadTaskRunner;
-class Value;
} // namespace base
namespace cc {
@@ -22,7 +22,7 @@
class CC_EXPORT MicroBenchmark {
public:
- using DoneCallback = base::OnceCallback<void(base::Value)>;
+ using DoneCallback = base::OnceCallback<void(base::Value::Dict)>;
explicit MicroBenchmark(DoneCallback callback);
virtual ~MicroBenchmark();
@@ -34,23 +34,23 @@
virtual void RunOnLayer(PictureLayer* layer);
- virtual bool ProcessMessage(base::Value message);
+ virtual bool ProcessMessage(base::Value::Dict message);
bool ProcessedForBenchmarkImpl() const;
std::unique_ptr<MicroBenchmarkImpl> GetBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner);
protected:
- void NotifyDone(base::Value result);
+ void NotifyDone(base::Value::Dict result);
virtual std::unique_ptr<MicroBenchmarkImpl> CreateBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner);
private:
DoneCallback callback_;
- bool is_done_;
- bool processed_for_benchmark_impl_;
- int id_;
+ bool is_done_ = false;
+ bool processed_for_benchmark_impl_ = false;
+ int id_ = 0;
};
} // namespace cc
diff --git a/cc/benchmarks/micro_benchmark_controller.cc b/cc/benchmarks/micro_benchmark_controller.cc
index 3f86461..7fbc122 100644
--- a/cc/benchmarks/micro_benchmark_controller.cc
+++ b/cc/benchmarks/micro_benchmark_controller.cc
@@ -26,7 +26,7 @@
std::unique_ptr<MicroBenchmark> CreateBenchmark(
const std::string& name,
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback) {
if (name == "invalidation_benchmark") {
return std::make_unique<InvalidationBenchmark>(std::move(settings),
@@ -56,7 +56,7 @@
int MicroBenchmarkController::ScheduleRun(
const std::string& micro_benchmark_name,
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback) {
std::unique_ptr<MicroBenchmark> benchmark = CreateBenchmark(
micro_benchmark_name, std::move(settings), std::move(callback));
@@ -78,7 +78,7 @@
return id;
}
-bool MicroBenchmarkController::SendMessage(int id, base::Value message) {
+bool MicroBenchmarkController::SendMessage(int id, base::Value::Dict message) {
auto it = base::ranges::find(benchmarks_, id, &MicroBenchmark::id);
if (it == benchmarks_.end())
return false;
diff --git a/cc/benchmarks/micro_benchmark_controller.h b/cc/benchmarks/micro_benchmark_controller.h
index 42f5695..d6d5ae1 100644
--- a/cc/benchmarks/micro_benchmark_controller.h
+++ b/cc/benchmarks/micro_benchmark_controller.h
@@ -34,10 +34,11 @@
// Returns the id of the benchmark on success, 0 otherwise.
int ScheduleRun(const std::string& micro_benchmark_name,
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback);
+
// Returns true if the message was successfully delivered and handled.
- bool SendMessage(int id, base::Value message);
+ bool SendMessage(int id, base::Value::Dict message);
std::vector<std::unique_ptr<MicroBenchmarkImpl>> CreateImplBenchmarks() const;
diff --git a/cc/benchmarks/micro_benchmark_controller_unittest.cc b/cc/benchmarks/micro_benchmark_controller_unittest.cc
index ab72588..757303c 100644
--- a/cc/benchmarks/micro_benchmark_controller_unittest.cc
+++ b/cc/benchmarks/micro_benchmark_controller_unittest.cc
@@ -58,20 +58,20 @@
std::unique_ptr<FakeImplTaskRunnerProvider> impl_task_runner_provider_;
};
-void IncrementCallCount(int* count, base::Value value) {
+void IncrementCallCount(int* count, base::Value::Dict value) {
++(*count);
}
TEST_F(MicroBenchmarkControllerTest, ScheduleFail) {
int id = layer_tree_host_->ScheduleMicroBenchmark(
- "non_existant_benchmark", base::Value(), base::DoNothing());
+ "non_existant_benchmark", base::Value::Dict(), base::DoNothing());
EXPECT_EQ(id, 0);
}
TEST_F(MicroBenchmarkControllerTest, CommitScheduled) {
layer_tree_host_->reset_needs_commit();
int id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(), base::DoNothing());
+ "unittest_only_benchmark", base::Value::Dict(), base::DoNothing());
EXPECT_GT(id, 0);
EXPECT_TRUE(layer_tree_host_->needs_commit());
}
@@ -79,7 +79,7 @@
TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) {
int run_count = 0;
int id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(),
+ "unittest_only_benchmark", base::Value::Dict(),
base::BindOnce(&IncrementCallCount, base::Unretained(&run_count)));
EXPECT_GT(id, 0);
@@ -91,11 +91,11 @@
TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) {
int run_count = 0;
int id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(),
+ "unittest_only_benchmark", base::Value::Dict(),
base::BindOnce(&IncrementCallCount, base::Unretained(&run_count)));
EXPECT_GT(id, 0);
id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(),
+ "unittest_only_benchmark", base::Value::Dict(),
base::BindOnce(&IncrementCallCount, base::Unretained(&run_count)));
EXPECT_GT(id, 0);
@@ -104,11 +104,11 @@
EXPECT_EQ(2, run_count);
id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(),
+ "unittest_only_benchmark", base::Value::Dict(),
base::BindOnce(&IncrementCallCount, base::Unretained(&run_count)));
EXPECT_GT(id, 0);
id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(),
+ "unittest_only_benchmark", base::Value::Dict(),
base::BindOnce(&IncrementCallCount, base::Unretained(&run_count)));
EXPECT_GT(id, 0);
@@ -121,8 +121,8 @@
TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) {
int run_count = 0;
- base::Value settings(base::Value::Type::DICT);
- settings.SetBoolKey("run_benchmark_impl", true);
+ base::Value::Dict settings;
+ settings.Set("run_benchmark_impl", true);
// Schedule a main thread benchmark.
int id = layer_tree_host_->ScheduleMicroBenchmark(
@@ -146,8 +146,8 @@
TEST_F(MicroBenchmarkControllerTest, SendMessage) {
// Send valid message to invalid benchmark (id = 0)
- base::Value message(base::Value::Type::DICT);
- message.SetBoolKey("can_handle", true);
+ base::Value::Dict message;
+ message.Set("can_handle", true);
bool message_handled =
layer_tree_host_->SendMessageToMicroBenchmark(0, std::move(message));
EXPECT_FALSE(message_handled);
@@ -155,20 +155,20 @@
// Schedule a benchmark
int run_count = 0;
int id = layer_tree_host_->ScheduleMicroBenchmark(
- "unittest_only_benchmark", base::Value(),
+ "unittest_only_benchmark", base::Value::Dict(),
base::BindOnce(&IncrementCallCount, base::Unretained(&run_count)));
EXPECT_GT(id, 0);
// Send valid message to valid benchmark
- message = base::Value(base::Value::Type::DICT);
- message.SetBoolKey("can_handle", true);
+ message.clear();
+ message.Set("can_handle", true);
message_handled =
layer_tree_host_->SendMessageToMicroBenchmark(id, std::move(message));
EXPECT_TRUE(message_handled);
// Send invalid message to valid benchmark
- message = base::Value(base::Value::Type::DICT);
- message.SetBoolKey("can_handle", false);
+ message.clear();
+ message.Set("can_handle", false);
message_handled =
layer_tree_host_->SendMessageToMicroBenchmark(id, std::move(message));
EXPECT_FALSE(message_handled);
diff --git a/cc/benchmarks/micro_benchmark_impl.cc b/cc/benchmarks/micro_benchmark_impl.cc
index 917d8bb..0636bb5 100644
--- a/cc/benchmarks/micro_benchmark_impl.cc
+++ b/cc/benchmarks/micro_benchmark_impl.cc
@@ -29,7 +29,7 @@
void MicroBenchmarkImpl::DidCompleteCommit(LayerTreeHostImpl* host) {}
-void MicroBenchmarkImpl::NotifyDone(base::Value result) {
+void MicroBenchmarkImpl::NotifyDone(base::Value::Dict result) {
origin_task_runner_->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), std::move(result)));
is_done_ = true;
diff --git a/cc/benchmarks/micro_benchmark_impl.h b/cc/benchmarks/micro_benchmark_impl.h
index c4d27635..6e18c94 100644
--- a/cc/benchmarks/micro_benchmark_impl.h
+++ b/cc/benchmarks/micro_benchmark_impl.h
@@ -7,11 +7,11 @@
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
+#include "base/values.h"
#include "cc/cc_export.h"
namespace base {
class SingleThreadTaskRunner;
-class Value;
} // namespace base
namespace cc {
@@ -21,7 +21,7 @@
class PictureLayerImpl;
class CC_EXPORT MicroBenchmarkImpl {
public:
- using DoneCallback = base::OnceCallback<void(base::Value)>;
+ using DoneCallback = base::OnceCallback<void(base::Value::Dict)>;
explicit MicroBenchmarkImpl(
DoneCallback callback,
@@ -35,7 +35,7 @@
virtual void RunOnLayer(PictureLayerImpl* layer);
protected:
- void NotifyDone(base::Value result);
+ void NotifyDone(base::Value::Dict result);
private:
DoneCallback callback_;
diff --git a/cc/benchmarks/rasterize_and_record_benchmark.cc b/cc/benchmarks/rasterize_and_record_benchmark.cc
index 29542cd..e837a8c 100644
--- a/cc/benchmarks/rasterize_and_record_benchmark.cc
+++ b/cc/benchmarks/rasterize_and_record_benchmark.cc
@@ -33,21 +33,16 @@
} // namespace
RasterizeAndRecordBenchmark::RasterizeAndRecordBenchmark(
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback)
: MicroBenchmark(std::move(callback)),
record_repeat_count_(kDefaultRecordRepeatCount),
- rasterize_repeat_count_(kDefaultRasterizeRepeatCount),
- main_thread_benchmark_done_(false),
- layer_tree_host_(nullptr) {
- if (!settings.is_dict())
- return;
-
- auto record_repeat_count = settings.FindIntKey("record_repeat_count");
+ rasterize_repeat_count_(kDefaultRasterizeRepeatCount) {
+ auto record_repeat_count = settings.FindInt("record_repeat_count");
if (record_repeat_count.has_value())
record_repeat_count_ = *record_repeat_count;
- auto rasterize_repeat_count = settings.FindIntKey("rasterize_repeat_count");
+ auto rasterize_repeat_count = settings.FindInt("rasterize_repeat_count");
if (rasterize_repeat_count.has_value())
rasterize_repeat_count_ = *rasterize_repeat_count;
}
@@ -72,38 +67,32 @@
layer_tree_host->client()->RunPaintBenchmark(record_repeat_count_,
paint_benchmark_result);
- DCHECK(results_.is_none());
- results_ = base::Value(base::Value::Type::DICT);
- results_.SetIntKey("pixels_recorded", record_results_.pixels_recorded);
- results_.SetIntKey("paint_op_memory_usage",
- static_cast<int>(record_results_.paint_op_memory_usage));
- results_.SetIntKey("paint_op_count",
- static_cast<int>(record_results_.paint_op_count));
- results_.SetDoubleKey("record_time_ms",
- paint_benchmark_result.record_time_ms);
- results_.SetDoubleKey("record_time_caching_disabled_ms",
- paint_benchmark_result.record_time_caching_disabled_ms);
- results_.SetDoubleKey(
+ DCHECK(results_.empty());
+ results_.Set("pixels_recorded", record_results_.pixels_recorded);
+ results_.Set("paint_op_memory_usage",
+ static_cast<int>(record_results_.paint_op_memory_usage));
+ results_.Set("paint_op_count",
+ static_cast<int>(record_results_.paint_op_count));
+ results_.Set("record_time_ms", paint_benchmark_result.record_time_ms);
+ results_.Set("record_time_caching_disabled_ms",
+ paint_benchmark_result.record_time_caching_disabled_ms);
+ results_.Set(
"record_time_subsequence_caching_disabled_ms",
paint_benchmark_result.record_time_subsequence_caching_disabled_ms);
- results_.SetDoubleKey(
- "raster_invalidation_and_convert_time_ms",
- paint_benchmark_result.raster_invalidation_and_convert_time_ms);
- results_.SetDoubleKey(
- "paint_artifact_compositor_update_time_ms",
- paint_benchmark_result.paint_artifact_compositor_update_time_ms);
- results_.SetIntKey(
- "painter_memory_usage",
- static_cast<int>(paint_benchmark_result.painter_memory_usage));
+ results_.Set("raster_invalidation_and_convert_time_ms",
+ paint_benchmark_result.raster_invalidation_and_convert_time_ms);
+ results_.Set("paint_artifact_compositor_update_time_ms",
+ paint_benchmark_result.paint_artifact_compositor_update_time_ms);
+ results_.Set("painter_memory_usage",
+ static_cast<int>(paint_benchmark_result.painter_memory_usage));
main_thread_benchmark_done_ = true;
}
void RasterizeAndRecordBenchmark::RecordRasterResults(
- base::Value results_value) {
+ base::Value::Dict results_value) {
DCHECK(main_thread_benchmark_done_);
- DCHECK(results_value.is_dict());
- results_.MergeDictionary(&results_value);
+ results_.Merge(std::move(results_value));
NotifyDone(std::move(results_));
}
diff --git a/cc/benchmarks/rasterize_and_record_benchmark.h b/cc/benchmarks/rasterize_and_record_benchmark.h
index 1d595a0c..524fd60 100644
--- a/cc/benchmarks/rasterize_and_record_benchmark.h
+++ b/cc/benchmarks/rasterize_and_record_benchmark.h
@@ -25,7 +25,7 @@
class RasterizeAndRecordBenchmark : public MicroBenchmark {
public:
- explicit RasterizeAndRecordBenchmark(base::Value settings,
+ explicit RasterizeAndRecordBenchmark(base::Value::Dict settings,
MicroBenchmark::DoneCallback callback);
~RasterizeAndRecordBenchmark() override;
@@ -37,7 +37,7 @@
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) override;
private:
- void RecordRasterResults(base::Value results);
+ void RecordRasterResults(base::Value::Dict results);
struct RecordResults {
int pixels_recorded = 0;
@@ -48,12 +48,12 @@
RecordResults record_results_;
int record_repeat_count_;
int rasterize_repeat_count_;
- base::Value results_;
+ base::Value::Dict results_;
// The following is used in DCHECKs.
- bool main_thread_benchmark_done_;
+ bool main_thread_benchmark_done_ = false;
- raw_ptr<LayerTreeHost> layer_tree_host_;
+ raw_ptr<LayerTreeHost> layer_tree_host_ = nullptr;
base::WeakPtrFactory<RasterizeAndRecordBenchmark> weak_ptr_factory_{this};
};
diff --git a/cc/benchmarks/rasterize_and_record_benchmark_impl.cc b/cc/benchmarks/rasterize_and_record_benchmark_impl.cc
index 4ba43ce..2d3efd2 100644
--- a/cc/benchmarks/rasterize_and_record_benchmark_impl.cc
+++ b/cc/benchmarks/rasterize_and_record_benchmark_impl.cc
@@ -160,31 +160,30 @@
layer->RunMicroBenchmark(this);
}
- base::Value result(base::Value::Type::DICT);
- result.SetDoubleKey("rasterize_time_ms",
- rasterize_results_.total_best_time.InMillisecondsF());
- result.SetIntKey("pixels_rasterized", rasterize_results_.pixels_rasterized);
- result.SetIntKey("pixels_rasterized_with_non_solid_color",
- rasterize_results_.pixels_rasterized_with_non_solid_color);
- result.SetIntKey("pixels_rasterized_as_opaque",
- rasterize_results_.pixels_rasterized_as_opaque);
- result.SetIntKey("total_layers", rasterize_results_.total_layers);
- result.SetIntKey("total_picture_layers",
- rasterize_results_.total_picture_layers);
- result.SetIntKey("total_picture_layers_with_no_content",
- rasterize_results_.total_picture_layers_with_no_content);
- result.SetIntKey("total_picture_layers_off_screen",
- rasterize_results_.total_picture_layers_off_screen);
+ base::Value::Dict result;
+ result.Set("rasterize_time_ms",
+ rasterize_results_.total_best_time.InMillisecondsF());
+ result.Set("pixels_rasterized", rasterize_results_.pixels_rasterized);
+ result.Set("pixels_rasterized_with_non_solid_color",
+ rasterize_results_.pixels_rasterized_with_non_solid_color);
+ result.Set("pixels_rasterized_as_opaque",
+ rasterize_results_.pixels_rasterized_as_opaque);
+ result.Set("total_layers", rasterize_results_.total_layers);
+ result.Set("total_picture_layers", rasterize_results_.total_picture_layers);
+ result.Set("total_picture_layers_with_no_content",
+ rasterize_results_.total_picture_layers_with_no_content);
+ result.Set("total_picture_layers_off_screen",
+ rasterize_results_.total_picture_layers_off_screen);
- base::Value lcd_text_pixels(base::Value::Type::DICT);
+ base::Value::Dict lcd_text_pixels;
for (size_t i = 0; i < kLCDTextDisallowedReasonCount; i++) {
- lcd_text_pixels.SetIntKey(
+ lcd_text_pixels.Set(
LCDTextDisallowedReasonToString(
static_cast<LCDTextDisallowedReason>(i)),
rasterize_results_.visible_pixels_by_lcd_text_disallowed_reason[i]);
}
- result.SetKey("visible_pixels_by_lcd_text_disallowed_reason",
- std::move(lcd_text_pixels));
+ result.Set("visible_pixels_by_lcd_text_disallowed_reason",
+ std::move(lcd_text_pixels));
NotifyDone(std::move(result));
}
diff --git a/cc/benchmarks/unittest_only_benchmark.cc b/cc/benchmarks/unittest_only_benchmark.cc
index 4154e81..8096876 100644
--- a/cc/benchmarks/unittest_only_benchmark.cc
+++ b/cc/benchmarks/unittest_only_benchmark.cc
@@ -15,13 +15,10 @@
namespace cc {
-UnittestOnlyBenchmark::UnittestOnlyBenchmark(base::Value settings,
+UnittestOnlyBenchmark::UnittestOnlyBenchmark(base::Value::Dict settings,
DoneCallback callback)
: MicroBenchmark(std::move(callback)), create_impl_benchmark_(false) {
- if (!settings.is_dict())
- return;
-
- auto run_benchmark_impl = settings.FindBoolKey("run_benchmark_impl");
+ auto run_benchmark_impl = settings.FindBool("run_benchmark_impl");
if (run_benchmark_impl.has_value())
create_impl_benchmark_ = *run_benchmark_impl;
}
@@ -31,18 +28,14 @@
}
void UnittestOnlyBenchmark::DidUpdateLayers(LayerTreeHost* layer_tree_host) {
- NotifyDone(base::Value());
+ NotifyDone(base::Value::Dict());
}
-bool UnittestOnlyBenchmark::ProcessMessage(base::Value message) {
- auto can_handle = message.FindBoolKey("can_handle");
- if (can_handle.has_value() && *can_handle) {
- return true;
- }
- return false;
+bool UnittestOnlyBenchmark::ProcessMessage(base::Value::Dict message) {
+ return message.FindBool("can_handle").value_or(false);
}
-void UnittestOnlyBenchmark::RecordImplResults(base::Value results) {
+void UnittestOnlyBenchmark::RecordImplResults(base::Value::Dict results) {
NotifyDone(std::move(results));
}
diff --git a/cc/benchmarks/unittest_only_benchmark.h b/cc/benchmarks/unittest_only_benchmark.h
index 7e1c777..6a05d8bc 100644
--- a/cc/benchmarks/unittest_only_benchmark.h
+++ b/cc/benchmarks/unittest_only_benchmark.h
@@ -15,18 +15,18 @@
class CC_EXPORT UnittestOnlyBenchmark : public MicroBenchmark {
public:
- UnittestOnlyBenchmark(base::Value settings, DoneCallback callback);
+ UnittestOnlyBenchmark(base::Value::Dict settings, DoneCallback callback);
~UnittestOnlyBenchmark() override;
void DidUpdateLayers(LayerTreeHost* layer_tree_host) override;
- bool ProcessMessage(base::Value message) override;
+ bool ProcessMessage(base::Value::Dict message) override;
protected:
std::unique_ptr<MicroBenchmarkImpl> CreateBenchmarkImpl(
scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner) override;
private:
- void RecordImplResults(base::Value results);
+ void RecordImplResults(base::Value::Dict results);
bool create_impl_benchmark_;
base::WeakPtrFactory<UnittestOnlyBenchmark> weak_ptr_factory_{this};
diff --git a/cc/benchmarks/unittest_only_benchmark_impl.cc b/cc/benchmarks/unittest_only_benchmark_impl.cc
index d72c72b..9ede2f4 100644
--- a/cc/benchmarks/unittest_only_benchmark_impl.cc
+++ b/cc/benchmarks/unittest_only_benchmark_impl.cc
@@ -19,7 +19,7 @@
UnittestOnlyBenchmarkImpl::~UnittestOnlyBenchmarkImpl() = default;
void UnittestOnlyBenchmarkImpl::DidCompleteCommit(LayerTreeHostImpl* host) {
- NotifyDone(base::Value());
+ NotifyDone(base::Value::Dict());
}
} // namespace cc
diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc
index ab62bb4..1062511 100644
--- a/cc/trees/layer_tree_host.cc
+++ b/cc/trees/layer_tree_host.cc
@@ -1206,14 +1206,15 @@
int LayerTreeHost::ScheduleMicroBenchmark(
const std::string& benchmark_name,
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback) {
DCHECK(IsMainThread());
return micro_benchmark_controller_.ScheduleRun(
benchmark_name, std::move(settings), std::move(callback));
}
-bool LayerTreeHost::SendMessageToMicroBenchmark(int id, base::Value message) {
+bool LayerTreeHost::SendMessageToMicroBenchmark(int id,
+ base::Value::Dict message) {
DCHECK(IsMainThread());
return micro_benchmark_controller_.SendMessage(id, std::move(message));
}
diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h
index 70c70c4..5904fbd2 100644
--- a/cc/trees/layer_tree_host.h
+++ b/cc/trees/layer_tree_host.h
@@ -216,7 +216,7 @@
void SetPaintWorkletLayerPainter(
std::unique_ptr<PaintWorkletLayerPainter> painter);
- // Attachs a SwapPromise to the Layer tree, that passes through the
+ // Attaches a SwapPromise to the Layer tree, that passes through the
// LayerTreeHost and LayerTreeHostImpl with the next commit and frame
// submission, which can be used to observe that progress. This also
// causes a main frame to be requested.
@@ -255,7 +255,7 @@
// Called in response to a LayerTreeFrameSink request made to the client
// using LayerTreeHostClient::RequestNewLayerTreeFrameSink. The client will
// be informed of the LayerTreeFrameSink initialization status using
- // DidInitializaLayerTreeFrameSink or DidFailToInitializeLayerTreeFrameSink.
+ // DidInitializeLayerTreeFrameSink or DidFailToInitializeLayerTreeFrameSink.
// The request is completed when the host successfully initializes an
// LayerTreeFrameSink.
void SetLayerTreeFrameSink(
@@ -332,7 +332,7 @@
// while still allowing main frame lifecycle updates. |timeout|
// is the interval after which commits will restart if nothing stops
// deferring sooner. If multiple calls are made to StartDeferringCommits
- // while deferal is active, the first timeout continues to apply.
+ // while deferral is active, the first timeout continues to apply.
bool StartDeferringCommits(base::TimeDelta timeout,
PaintHoldingReason reason);
@@ -395,11 +395,11 @@
// Returns the id of the benchmark on success, 0 otherwise.
int ScheduleMicroBenchmark(const std::string& benchmark_name,
- base::Value settings,
+ base::Value::Dict settings,
MicroBenchmark::DoneCallback callback);
// Returns true if the message was successfully delivered and handled.
- bool SendMessageToMicroBenchmark(int id, base::Value message);
+ bool SendMessageToMicroBenchmark(int id, base::Value::Dict message);
// When the main thread informs the compositor thread that it is ready to
// commit, generally it would remain blocked until the main thread state is
diff --git a/content/renderer/gpu_benchmarking_extension.cc b/content/renderer/gpu_benchmarking_extension.cc
index d86ac90c2..f4766e6 100644
--- a/content/renderer/gpu_benchmarking_extension.cc
+++ b/content/renderer/gpu_benchmarking_extension.cc
@@ -281,7 +281,7 @@
}
void OnMicroBenchmarkCompleted(CallbackAndContext* callback_and_context,
- base::Value result) {
+ base::Value::Dict result) {
RunCallbackHelper(callback_and_context,
absl::optional<base::Value>(std::move(result)));
}
@@ -291,7 +291,7 @@
CallbackAndContext* callback_and_context,
gfx::CALayerResult error_code) {
RunCallbackHelper(callback_and_context,
- absl::optional<base::Value>((base::Value(error_code))));
+ absl::optional<base::Value>(base::Value(error_code)));
}
#endif
@@ -612,7 +612,7 @@
GpuBenchmarking::GpuBenchmarking(base::WeakPtr<RenderFrameImpl> frame)
: render_frame_(std::move(frame)) {}
-GpuBenchmarking::~GpuBenchmarking() {}
+GpuBenchmarking::~GpuBenchmarking() = default;
void GpuBenchmarking::EnsureRemoteInterface() {
if (!input_injector_) {
@@ -1326,9 +1326,12 @@
std::unique_ptr<base::Value> value =
V8ValueConverter::Create()->FromV8Value(arguments, v8_context);
DCHECK(value);
+ if (!value->is_dict()) {
+ return 0;
+ }
return context.layer_tree_host()->ScheduleMicroBenchmark(
- name, base::Value::FromUniquePtrValue(std::move(value)),
+ name, std::move(*value).TakeDict(),
base::BindOnce(&OnMicroBenchmarkCompleted,
base::RetainedRef(callback_and_context)));
}
@@ -1343,9 +1346,12 @@
std::unique_ptr<base::Value> value =
V8ValueConverter::Create()->FromV8Value(message, v8_context);
DCHECK(value);
+ if (!value->is_dict()) {
+ return false;
+ }
return context.layer_tree_host()->SendMessageToMicroBenchmark(
- id, base::Value::FromUniquePtrValue(std::move(value)));
+ id, std::move(*value).TakeDict());
}
bool GpuBenchmarking::HasGpuChannel() {