@@ -56,38 +56,35 @@ class Helper {
5656
5757 void OnValidatedDataReady (bool success,
5858 const std::string& key,
59- std::string* data) {
59+ std::optional<std:: string> data) {
6060 if (success) {
61- assert (data != nullptr );
61+ assert (data != std:: nullopt );
6262 retrieved_ (success, key, *data);
6363 delete this ;
6464 } else {
6565 // Validating storage returns (false, key, stale-data) for valid but stale
6666 // data. If |data| is empty, however, then it's either missing or invalid.
67- if (data != nullptr && !data->empty ()) {
68- stale_data_ = * data;
67+ if (data. has_value () && !data->empty ()) {
68+ stale_data_ = std::move ( data). value () ;
6969 }
7070 source_.Get (key, *fresh_data_ready_);
7171 }
72- delete data;
7372 }
7473
7574 void OnFreshDataReady (bool success,
7675 const std::string& key,
77- std::string* data) {
76+ std::optional<std:: string> data) {
7877 if (success) {
79- assert (data != nullptr );
78+ assert (data. has_value () );
8079 retrieved_ (true , key, *data);
81- storage_->Put (key, data);
82- data = nullptr ; // Deleted by Storage::Put().
80+ storage_->Put (key, std::move (data).value ());
8381 } else if (!stale_data_.empty ()) {
8482 // Reuse the stale data if a download fails. It's better to have slightly
8583 // outdated validation rules than to suddenly lose validation ability.
8684 retrieved_ (true , key, stale_data_);
8785 } else {
8886 retrieved_ (false , key, std::string ());
8987 }
90- delete data;
9188 delete this ;
9289 }
9390
0 commit comments