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

Side by Side Diff: components/pairing/proto_decoder.h

Issue 448273002: Add ProtoDecoder for sending messages between Host and Controller when pairing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 #ifndef COMPONENTS_PAIRING_PROTO_DECODER_H_
6 #define COMPONENTS_PAIRING_PROTO_DECODER_H_
7
8 #include <deque>
9
10 #include "base/logging.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14
15 namespace net {
16 class IOBuffer;
17 }
18
19 namespace pairing_api {
20 class CompleteSetup;
21 class ConfigureHost;
22 class Error;
23 class HostStatus;
24 class PairDevices;
25 } // namespace pairing_api
26
27 namespace pairing_chromeos {
28
29 class MessageBuffer;
30
31 // A ProtoDecoder collects data from a series of IOBuffers and decodes Proto
32 // buffers from the data. The decoded messages are then forwarded to an
33 // observer.
34 class ProtoDecoder {
35 public:
36 class Observer {
37 public:
38 virtual void OnHostStatusMessage(
achuithb 2014/08/11 22:04:31 Please add a public virtual dtor with an empty bod
Zachary Kuznia 2014/08/11 23:40:29 Done.
39 const pairing_api::HostStatus& message) = 0;
40 virtual void OnConfigureHostMessage(
41 const pairing_api::ConfigureHost& message) = 0;
42 virtual void OnPairDevicesMessage(
43 const pairing_api::PairDevices& message) = 0;
44 virtual void OnCompleteSetupMessage(
45 const pairing_api::CompleteSetup& message) = 0;
46 virtual void OnErrorMessage(
47 const pairing_api::Error& message) = 0;
48 };
49
50 explicit ProtoDecoder(Observer* observer);
51 ~ProtoDecoder();
52
53 // Decode the data from an io_buffer, and send out events for any complete
achuithb 2014/08/11 22:04:31 Decodes ..., and sends
Zachary Kuznia 2014/08/11 23:40:29 Done.
54 // messages.
55 bool DecodeIOBuffer(int size, scoped_refptr<net::IOBuffer> io_buffer);
achuithb 2014/08/11 22:04:31 consider using a typedef for scoped_refptr<net::IO
Zachary Kuznia 2014/08/11 23:40:29 Done.
56
57 // Convenience functions for serializing messages into an IOBuffer.
58 static scoped_refptr<net::IOBuffer> SendHostStatus(
59 const pairing_api::HostStatus& message, int* size);
60 static scoped_refptr<net::IOBuffer> SendConfigureHost(
61 const pairing_api::ConfigureHost& message, int* size);
62 static scoped_refptr<net::IOBuffer> SendPairDevices(
63 const pairing_api::PairDevices& message, int* size);
64 static scoped_refptr<net::IOBuffer> SendCompleteSetup(
65 const pairing_api::CompleteSetup& message, int* size);
66 static scoped_refptr<net::IOBuffer> SendError(
67 const pairing_api::Error& message, int* size);
68
69 private:
70 static scoped_refptr<net::IOBuffer> SendMessage(uint8_t message_type,
71 const std::string& message,
72 int* size);
73
74 Observer* observer_;
75 scoped_ptr<MessageBuffer> message_buffer_;
achuithb 2014/08/11 22:04:31 Why not just have a MessageBuffer member: MessageB
Zachary Kuznia 2014/08/11 23:40:29 Done.
76 int next_message_type_;
77 int next_message_size_;
78
79 DISALLOW_COPY_AND_ASSIGN(ProtoDecoder);
80 };
81
82 } // namespace pairing_chromeos
83
84 #endif // COMPONENTS_PAIRING_PROTO_DECODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698