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

Side by Side Diff: google_apis/gcm/base/mcs_message.cc

Issue 1873663002: Convert //google_apis from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "google_apis/gcm/base/mcs_message.h" 5 #include "google_apis/gcm/base/mcs_message.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "google_apis/gcm/base/mcs_util.h" 10 #include "google_apis/gcm/base/mcs_util.h"
11 11
12 namespace gcm { 12 namespace gcm {
13 13
14 MCSMessage::Core::Core() {} 14 MCSMessage::Core::Core() {}
15 15
16 MCSMessage::Core::Core(uint8_t tag, 16 MCSMessage::Core::Core(uint8_t tag,
17 const google::protobuf::MessageLite& protobuf) { 17 const google::protobuf::MessageLite& protobuf) {
18 scoped_ptr<google::protobuf::MessageLite> owned_protobuf(protobuf.New()); 18 std::unique_ptr<google::protobuf::MessageLite> owned_protobuf(protobuf.New());
19 owned_protobuf->CheckTypeAndMergeFrom(protobuf); 19 owned_protobuf->CheckTypeAndMergeFrom(protobuf);
20 protobuf_ = std::move(owned_protobuf); 20 protobuf_ = std::move(owned_protobuf);
21 } 21 }
22 22
23 MCSMessage::Core::Core( 23 MCSMessage::Core::Core(
24 uint8_t tag, 24 uint8_t tag,
25 scoped_ptr<const google::protobuf::MessageLite> protobuf) { 25 std::unique_ptr<const google::protobuf::MessageLite> protobuf) {
26 protobuf_ = std::move(protobuf); 26 protobuf_ = std::move(protobuf);
27 } 27 }
28 28
29 MCSMessage::Core::~Core() {} 29 MCSMessage::Core::~Core() {}
30 30
31 const google::protobuf::MessageLite& MCSMessage::Core::Get() const { 31 const google::protobuf::MessageLite& MCSMessage::Core::Get() const {
32 return *protobuf_; 32 return *protobuf_;
33 } 33 }
34 34
35 MCSMessage::MCSMessage() : tag_(0), size_(0) {} 35 MCSMessage::MCSMessage() : tag_(0), size_(0) {}
36 36
37 MCSMessage::MCSMessage(const google::protobuf::MessageLite& protobuf) 37 MCSMessage::MCSMessage(const google::protobuf::MessageLite& protobuf)
38 : tag_(GetMCSProtoTag(protobuf)), 38 : tag_(GetMCSProtoTag(protobuf)),
39 size_(protobuf.ByteSize()), 39 size_(protobuf.ByteSize()),
40 core_(new Core(tag_, protobuf)) { 40 core_(new Core(tag_, protobuf)) {
41 } 41 }
42 42
43 MCSMessage::MCSMessage(uint8_t tag, 43 MCSMessage::MCSMessage(uint8_t tag,
44 const google::protobuf::MessageLite& protobuf) 44 const google::protobuf::MessageLite& protobuf)
45 : tag_(tag), size_(protobuf.ByteSize()), core_(new Core(tag_, protobuf)) { 45 : tag_(tag), size_(protobuf.ByteSize()), core_(new Core(tag_, protobuf)) {
46 DCHECK_EQ(tag, GetMCSProtoTag(protobuf)); 46 DCHECK_EQ(tag, GetMCSProtoTag(protobuf));
47 } 47 }
48 48
49 MCSMessage::MCSMessage(uint8_t tag, 49 MCSMessage::MCSMessage(
50 scoped_ptr<const google::protobuf::MessageLite> protobuf) 50 uint8_t tag,
51 std::unique_ptr<const google::protobuf::MessageLite> protobuf)
51 : tag_(tag), 52 : tag_(tag),
52 size_(protobuf->ByteSize()), 53 size_(protobuf->ByteSize()),
53 core_(new Core(tag_, std::move(protobuf))) { 54 core_(new Core(tag_, std::move(protobuf))) {
54 DCHECK_EQ(tag, GetMCSProtoTag(core_->Get())); 55 DCHECK_EQ(tag, GetMCSProtoTag(core_->Get()));
55 } 56 }
56 57
57 MCSMessage::MCSMessage(const MCSMessage& other) = default; 58 MCSMessage::MCSMessage(const MCSMessage& other) = default;
58 59
59 MCSMessage::~MCSMessage() { 60 MCSMessage::~MCSMessage() {
60 } 61 }
61 62
62 bool MCSMessage::IsValid() const { 63 bool MCSMessage::IsValid() const {
63 return core_.get() != NULL; 64 return core_.get() != NULL;
64 } 65 }
65 66
66 std::string MCSMessage::SerializeAsString() const { 67 std::string MCSMessage::SerializeAsString() const {
67 return core_->Get().SerializeAsString(); 68 return core_->Get().SerializeAsString();
68 } 69 }
69 70
70 const google::protobuf::MessageLite& MCSMessage::GetProtobuf() const { 71 const google::protobuf::MessageLite& MCSMessage::GetProtobuf() const {
71 return core_->Get(); 72 return core_->Get();
72 } 73 }
73 74
74 scoped_ptr<google::protobuf::MessageLite> MCSMessage::CloneProtobuf() const { 75 std::unique_ptr<google::protobuf::MessageLite> MCSMessage::CloneProtobuf()
75 scoped_ptr<google::protobuf::MessageLite> clone(GetProtobuf().New()); 76 const {
77 std::unique_ptr<google::protobuf::MessageLite> clone(GetProtobuf().New());
76 clone->CheckTypeAndMergeFrom(GetProtobuf()); 78 clone->CheckTypeAndMergeFrom(GetProtobuf());
77 return clone; 79 return clone;
78 } 80 }
79 81
80 } // namespace gcm 82 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698