OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/idltest/idltest_api.h" | 5 #include "chrome/browser/extensions/api/idltest/idltest_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
| 11 #include "base/memory/ptr_util.h" |
9 #include "base/values.h" | 12 #include "base/values.h" |
10 | 13 |
11 using base::BinaryValue; | 14 using base::BinaryValue; |
12 | 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 base::ListValue* CopyBinaryValueToIntegerList(const BinaryValue* input) { | 18 std::unique_ptr<base::ListValue> CopyBinaryValueToIntegerList( |
16 base::ListValue* output = new base::ListValue(); | 19 const BinaryValue* input) { |
| 20 std::unique_ptr<base::ListValue> output(new base::ListValue()); |
17 const char* input_buffer = input->GetBuffer(); | 21 const char* input_buffer = input->GetBuffer(); |
18 for (size_t i = 0; i < input->GetSize(); i++) { | 22 for (size_t i = 0; i < input->GetSize(); i++) { |
19 output->Append(new base::FundamentalValue(input_buffer[i])); | 23 output->Append(new base::FundamentalValue(input_buffer[i])); |
20 } | 24 } |
21 return output; | 25 return output; |
22 } | 26 } |
23 | 27 |
24 } // namespace | 28 } // namespace |
25 | 29 |
26 bool IdltestSendArrayBufferFunction::RunSync() { | 30 bool IdltestSendArrayBufferFunction::RunSync() { |
27 BinaryValue* input = NULL; | 31 BinaryValue* input = NULL; |
28 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); | 32 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); |
29 SetResult(CopyBinaryValueToIntegerList(input)); | 33 SetResult(CopyBinaryValueToIntegerList(input)); |
30 return true; | 34 return true; |
31 } | 35 } |
32 | 36 |
33 bool IdltestSendArrayBufferViewFunction::RunSync() { | 37 bool IdltestSendArrayBufferViewFunction::RunSync() { |
34 BinaryValue* input = NULL; | 38 BinaryValue* input = NULL; |
35 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); | 39 EXTENSION_FUNCTION_VALIDATE(args_ != NULL && args_->GetBinary(0, &input)); |
36 SetResult(CopyBinaryValueToIntegerList(input)); | 40 SetResult(CopyBinaryValueToIntegerList(input)); |
37 return true; | 41 return true; |
38 } | 42 } |
39 | 43 |
40 bool IdltestGetArrayBufferFunction::RunSync() { | 44 bool IdltestGetArrayBufferFunction::RunSync() { |
41 std::string hello = "hello world"; | 45 std::string hello = "hello world"; |
42 BinaryValue* output = | 46 BinaryValue* output = |
43 BinaryValue::CreateWithCopiedBuffer(hello.c_str(), hello.size()); | 47 BinaryValue::CreateWithCopiedBuffer(hello.c_str(), hello.size()); |
44 SetResult(output); | 48 SetResult(base::WrapUnique(output)); |
45 return true; | 49 return true; |
46 } | 50 } |
OLD | NEW |