Browse Source

refactor: simplify code by using base::Value::EnsureList() (#41162)

Charles Kerr 1 year ago
parent
commit
08615b2d4e

+ 1 - 4
shell/browser/api/electron_api_web_request.cc

@@ -114,10 +114,7 @@ v8::Local<v8::Value> HttpResponseHeadersToV8(
         std::string filename = "\"" + header.filename() + "\"";
         value = decodedFilename + "; filename=" + filename;
       }
-      base::Value::List* values = response_headers.FindList(key);
-      if (!values)
-        values = &response_headers.Set(key, base::Value::List())->GetList();
-      values->Append(base::Value(value));
+      response_headers.EnsureList(key)->Append(value);
     }
   }
   return gin::ConvertToV8(v8::Isolate::GetCurrent(), response_headers);

+ 1 - 9
shell/browser/api/gpu_info_enumerator.cc

@@ -49,15 +49,7 @@ void GPUInfoEnumerator::EndGPUDevice() {
   auto& top_value = value_stack_.top();
   // GPUDevice can be more than one. So create a list of all.
   // The first one is the active GPU device.
-  if (base::Value* list_value = top_value.Find(kGPUDeviceKey)) {
-    DCHECK(list_value->is_list());
-    base::Value::List& list = list_value->GetList();
-    list.Append(std::move(current_));
-  } else {
-    base::Value::List gpus;
-    gpus.Append(std::move(current_));
-    top_value.Set(kGPUDeviceKey, std::move(gpus));
-  }
+  top_value.EnsureList(kGPUDeviceKey)->Append(std::move(current_));
   current_ = std::move(top_value);
   value_stack_.pop();
 }