cc: Default value for use_distance_field_text was not set in the layer tree settings
[chromium-blink-merge.git] / components / pairing / proto_decoder.h
blobe36eb7fce06132e49f05e5a3da38ec27a35e66f1
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.
5 #ifndef COMPONENTS_PAIRING_PROTO_DECODER_H_
6 #define COMPONENTS_PAIRING_PROTO_DECODER_H_
8 #include <deque>
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 #include "components/pairing/message_buffer.h"
16 namespace net {
17 class IOBuffer;
20 namespace pairing_api {
21 class CompleteSetup;
22 class ConfigureHost;
23 class Error;
24 class HostStatus;
25 class PairDevices;
26 } // namespace pairing_api
28 namespace pairing_chromeos {
30 // A ProtoDecoder collects data from a series of IOBuffers and decodes Proto
31 // buffers from the data. The decoded messages are then forwarded to an
32 // observer.
33 class ProtoDecoder {
34 public:
35 typedef scoped_refptr<net::IOBuffer> IOBufferRefPtr;
36 class Observer {
37 public:
38 virtual ~Observer() {}
40 virtual void OnHostStatusMessage(
41 const pairing_api::HostStatus& message) = 0;
42 virtual void OnConfigureHostMessage(
43 const pairing_api::ConfigureHost& message) = 0;
44 virtual void OnPairDevicesMessage(
45 const pairing_api::PairDevices& message) = 0;
46 virtual void OnCompleteSetupMessage(
47 const pairing_api::CompleteSetup& message) = 0;
48 virtual void OnErrorMessage(
49 const pairing_api::Error& message) = 0;
51 protected:
52 Observer() {}
54 private:
55 DISALLOW_COPY_AND_ASSIGN(Observer);
58 explicit ProtoDecoder(Observer* observer);
59 ~ProtoDecoder();
61 // Decodes the data from an io_buffer, and sends out events for any complete
62 // messages.
63 bool DecodeIOBuffer(int size, IOBufferRefPtr io_buffer);
65 // Convenience functions for serializing messages into an IOBuffer.
66 static IOBufferRefPtr SendHostStatus(const pairing_api::HostStatus& message,
67 int* size);
68 static IOBufferRefPtr SendConfigureHost(
69 const pairing_api::ConfigureHost& message, int* size);
70 static IOBufferRefPtr SendPairDevices(const pairing_api::PairDevices& message,
71 int* size);
72 static IOBufferRefPtr SendCompleteSetup(
73 const pairing_api::CompleteSetup& message, int* size);
74 static IOBufferRefPtr SendError(const pairing_api::Error& message, int* size);
76 private:
77 static IOBufferRefPtr SendMessage(uint8_t message_type,
78 const std::string& message,
79 int* size);
81 Observer* observer_;
82 MessageBuffer message_buffer_;
83 int next_message_type_;
84 int next_message_size_;
86 DISALLOW_COPY_AND_ASSIGN(ProtoDecoder);
89 } // namespace pairing_chromeos
91 #endif // COMPONENTS_PAIRING_PROTO_DECODER_H_