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

Side by Side Diff: device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.cc

Issue 2287023002: device/bluetooth: Fix = operator and copy constructor of BluetoothServiceAttributeValueBlueZ (Closed)
Patch Set: change bug number Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h" 5 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 11
12 namespace bluez { 12 namespace bluez {
13 13
14 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ() 14 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ()
15 : type_(NULLTYPE), size_(0) {} 15 : type_(NULLTYPE), size_(0), value_(base::Value::CreateNullValue()) {}
16 16
17 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( 17 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
18 Type type, 18 Type type,
19 size_t size, 19 size_t size,
20 std::unique_ptr<base::Value> value) 20 std::unique_ptr<base::Value> value)
21 : type_(type), size_(size), value_(std::move(value)) { 21 : type_(type), size_(size), value_(std::move(value)) {
22 CHECK_NE(type, SEQUENCE); 22 CHECK_NE(type, SEQUENCE);
23 } 23 }
24 24
25 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( 25 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
26 std::unique_ptr<Sequence> sequence) 26 std::unique_ptr<Sequence> sequence)
27 : type_(SEQUENCE), 27 : type_(SEQUENCE),
28 size_(sequence->size()), 28 size_(sequence->size()),
29 sequence_(std::move(sequence)) {} 29 sequence_(std::move(sequence)) {}
30 30
31 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ( 31 BluetoothServiceAttributeValueBlueZ::BluetoothServiceAttributeValueBlueZ(
32 const BluetoothServiceAttributeValueBlueZ& attribute) { 32 const BluetoothServiceAttributeValueBlueZ& attribute) {
33 this->type_ = attribute.type_; 33 *this = attribute;
34 this->size_ = attribute.size_;
35
36 if (attribute.type_ == NULLTYPE) {
37 this->value_ = base::Value::CreateNullValue();
38 return;
39 }
40
41 if (attribute.type_ != SEQUENCE) {
42 this->value_ = base::WrapUnique(attribute.value_->DeepCopy());
43 return;
44 }
45
46 this->sequence_ = base::MakeUnique<Sequence>(*attribute.sequence_);
47 } 34 }
48 35
49 BluetoothServiceAttributeValueBlueZ BluetoothServiceAttributeValueBlueZ:: 36 BluetoothServiceAttributeValueBlueZ& BluetoothServiceAttributeValueBlueZ::
50 operator=(const BluetoothServiceAttributeValueBlueZ& attribute) { 37 operator=(const BluetoothServiceAttributeValueBlueZ& attribute) {
51 return BluetoothServiceAttributeValueBlueZ(attribute); 38 if (this != &attribute) {
39 type_ = attribute.type_;
40 size_ = attribute.size_;
41 if (attribute.type_ == SEQUENCE) {
42 value_ = nullptr;
43 sequence_ = base::MakeUnique<Sequence>(*attribute.sequence_);
44 } else {
45 value_ = attribute.value_->CreateDeepCopy();
46 sequence_ = nullptr;
47 }
48 }
49 return *this;
52 } 50 }
53 51
54 BluetoothServiceAttributeValueBlueZ::~BluetoothServiceAttributeValueBlueZ() {} 52 BluetoothServiceAttributeValueBlueZ::~BluetoothServiceAttributeValueBlueZ() {}
55 53
56 } // namespace bluez 54 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698