Roll src/third_party/WebKit 3529d49:06e8485 (svn 202554:202555)
[chromium-blink-merge.git] / google_apis / gcm / base / mcs_message.cc
blobf0c130baf89facd0f2c9904af8f14cdcfca87f3f
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
3 // found in the LICENSE file.
5 #include "google_apis/gcm/base/mcs_message.h"
7 #include "base/logging.h"
8 #include "google_apis/gcm/base/mcs_util.h"
10 namespace gcm {
12 MCSMessage::Core::Core() {}
14 MCSMessage::Core::Core(uint8 tag,
15 const google::protobuf::MessageLite& protobuf) {
16 scoped_ptr<google::protobuf::MessageLite> owned_protobuf(protobuf.New());
17 owned_protobuf->CheckTypeAndMergeFrom(protobuf);
18 protobuf_ = owned_protobuf.Pass();
21 MCSMessage::Core::Core(
22 uint8 tag,
23 scoped_ptr<const google::protobuf::MessageLite> protobuf) {
24 protobuf_ = protobuf.Pass();
27 MCSMessage::Core::~Core() {}
29 const google::protobuf::MessageLite& MCSMessage::Core::Get() const {
30 return *protobuf_;
33 MCSMessage::MCSMessage() : tag_(0), size_(0) {}
35 MCSMessage::MCSMessage(const google::protobuf::MessageLite& protobuf)
36 : tag_(GetMCSProtoTag(protobuf)),
37 size_(protobuf.ByteSize()),
38 core_(new Core(tag_, protobuf)) {
41 MCSMessage::MCSMessage(uint8 tag,
42 const google::protobuf::MessageLite& protobuf)
43 : tag_(tag),
44 size_(protobuf.ByteSize()),
45 core_(new Core(tag_, protobuf)) {
46 DCHECK_EQ(tag, GetMCSProtoTag(protobuf));
49 MCSMessage::MCSMessage(uint8 tag,
50 scoped_ptr<const google::protobuf::MessageLite> protobuf)
51 : tag_(tag),
52 size_(protobuf->ByteSize()),
53 core_(new Core(tag_, protobuf.Pass())) {
54 DCHECK_EQ(tag, GetMCSProtoTag(core_->Get()));
57 MCSMessage::~MCSMessage() {
60 bool MCSMessage::IsValid() const {
61 return core_.get() != NULL;
64 std::string MCSMessage::SerializeAsString() const {
65 return core_->Get().SerializeAsString();
68 const google::protobuf::MessageLite& MCSMessage::GetProtobuf() const {
69 return core_->Get();
72 scoped_ptr<google::protobuf::MessageLite> MCSMessage::CloneProtobuf() const {
73 scoped_ptr<google::protobuf::MessageLite> clone(GetProtobuf().New());
74 clone->CheckTypeAndMergeFrom(GetProtobuf());
75 return clone.Pass();
78 } // namespace gcm