Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: extensions/browser/api/hid/hid_api.cc

Issue 2025103003: ExtensionFunction: don't pass ownership of base::Value by raw pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/hid/hid_api.cc
diff --git a/extensions/browser/api/hid/hid_api.cc b/extensions/browser/api/hid/hid_api.cc
index bbf59b8746dd496b5024103737422cd4c59f72ba..b03ae8baaa7b704bd1e59158372d69b6c36e2dd3 100644
--- a/extensions/browser/api/hid/hid_api.cc
+++ b/extensions/browser/api/hid/hid_api.cc
@@ -7,8 +7,10 @@
#include <stdint.h>
#include <string>
+#include <utility>
#include <vector>
+#include "base/memory/ptr_util.h"
#include "device/core/device_client.h"
#include "device/hid/hid_connection.h"
#include "device/hid/hid_device_filter.h"
@@ -56,11 +58,12 @@ const char kErrorFailedToOpenDevice[] = "Failed to open HID device.";
const char kErrorConnectionNotFound[] = "Connection not established.";
const char kErrorTransfer[] = "Transfer failed.";
-base::Value* PopulateHidConnection(int connection_id,
- scoped_refptr<HidConnection> connection) {
+std::unique_ptr<base::Value> PopulateHidConnection(
+ int connection_id,
+ scoped_refptr<HidConnection> connection) {
hid::HidConnectInfo connection_value;
connection_value.connection_id = connection_id;
- return connection_value.ToValue().release();
+ return connection_value.ToValue();
}
void ConvertHidDeviceFilter(const hid::DeviceFilter& input,
@@ -119,7 +122,7 @@ ExtensionFunction::ResponseAction HidGetDevicesFunction::Run() {
void HidGetDevicesFunction::OnEnumerationComplete(
std::unique_ptr<base::ListValue> devices) {
- Respond(OneArgument(devices.release()));
+ Respond(OneArgument(std::move(devices)));
}
HidGetUserSelectedDevicesFunction::HidGetUserSelectedDevicesFunction() {
@@ -135,7 +138,7 @@ ExtensionFunction::ResponseAction HidGetUserSelectedDevicesFunction::Run() {
content::WebContents* web_contents = GetSenderWebContents();
if (!web_contents || !user_gesture()) {
- return RespondNow(OneArgument(new base::ListValue()));
+ return RespondNow(OneArgument(base::MakeUnique<base::ListValue>()));
}
bool multiple = false;
@@ -287,9 +290,10 @@ void HidReceiveFunction::OnFinished(bool success,
DCHECK_GE(size, 1u);
int report_id = reinterpret_cast<uint8_t*>(buffer->data())[0];
- Respond(TwoArguments(new base::FundamentalValue(report_id),
- base::BinaryValue::CreateWithCopiedBuffer(
- buffer->data() + 1, size - 1)));
+ Respond(
+ TwoArguments(base::MakeUnique<base::FundamentalValue>(report_id),
+ base::WrapUnique(base::BinaryValue::CreateWithCopiedBuffer(
+ buffer->data() + 1, size - 1))));
} else {
Respond(Error(kErrorTransfer));
}
@@ -346,8 +350,8 @@ void HidReceiveFeatureReportFunction::OnFinished(
scoped_refptr<net::IOBuffer> buffer,
size_t size) {
if (success) {
- Respond(OneArgument(
- base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), size)));
+ Respond(OneArgument(base::WrapUnique(
+ base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), size))));
} else {
Respond(Error(kErrorTransfer));
}

Powered by Google App Engine
This is Rietveld 408576698