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

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

Issue 56353002: [GCM] Add RMQ storage and MCS message passing support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "google_apis/gcm/base/mcs_message.h"
6
7 #include "base/logging.h"
8 #include "google_apis/gcm/base/mcs_util.h"
9
10 namespace gcm {
11
12 MCSMessage::Core::Core() {}
13
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();
19 }
20
21 MCSMessage::Core::Core(
22 uint8 tag,
23 scoped_ptr<const google::protobuf::MessageLite> protobuf) {
24 protobuf_ = protobuf.Pass();
25 }
26
27 MCSMessage::Core::~Core() {}
28
29 const google::protobuf::MessageLite& MCSMessage::Core::Get() const {
30 return *protobuf_;
31 }
32
33 MCSMessage::MCSMessage() : tag_(0), size_(0) {}
34
35 MCSMessage::MCSMessage(const google::protobuf::MessageLite& protobuf)
36 : tag_(GetMCSProtoTag(protobuf)),
37 size_(protobuf.ByteSize()),
38 core_(new Core(tag_, protobuf)) {
39 }
40
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));
47 }
48
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()));
55 }
56
57 MCSMessage::~MCSMessage() {
58 }
59
60 bool MCSMessage::IsValid() const {
61 return core_.get();
62 }
63
64 std::string MCSMessage::SerializeAsString() const {
65 return core_->Get().SerializeAsString();
66 }
67
68 const google::protobuf::MessageLite& MCSMessage::GetProtobuf() const {
69 return core_->Get();
70 }
71
72 scoped_ptr<google::protobuf::MessageLite> MCSMessage::CloneProtobuf() const {
73 scoped_ptr<google::protobuf::MessageLite> owned_protobuf(GetProtobuf().New());
fgorski 2013/11/01 20:26:10 why did you call it owned_? did you mean cloned_ o
Nicolas Zea 2013/11/01 21:18:49 Yeah, it was just to Pass() it later. Cloned makes
74 owned_protobuf->CheckTypeAndMergeFrom(GetProtobuf());
75 return owned_protobuf.Pass();
76 }
77
78 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698