- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / net / probe_message.h
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.
4
5 #ifndef CHROME_BROWSER_NET_PROBE_MESSAGE_H_
6 #define CHROME_BROWSER_NET_PROBE_MESSAGE_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "chrome/browser/net/probe_message.pb.h"
13
14 namespace chrome_browser_net {
15
16 // Packet format between client and server is defined in probe_message.proto.
17 class ProbeMessage {
18  public:
19   ProbeMessage();
20
21   // Generate a ProbeRequest packet.
22   void GenerateProbeRequest(const ProbePacket_Token& received_token,
23                             uint32 group_id,
24                             uint32 probe_size,
25                             uint32 pacing_interval_micros,
26                             uint32 number_probe_packets,
27                             ProbePacket* output);
28   // Make an encoded packet (string) from a ProbePacket object.
29   std::string MakeEncodedPacket(const ProbePacket& packet) const;
30   // Fill some common fields in the packet header.
31   void SetPacketHeader(ProbePacket_Type packet_type,
32                        ProbePacket* probe_packet) const;
33   // Parse the input string (which is an encoded packet) and save the result to
34   // packet. Return true if there is no error and false otherwise.
35   bool ParseInput(const std::string& input, ProbePacket* packet) const;
36
37  private:
38   // For unittest.
39   friend class ProbeMessageTest;
40   FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestChecksum);
41   FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestEncode);
42   FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestGenerateProbeRequest);
43   FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestSetPacketHeader);
44
45   // Compute the checksum of the padding string.
46   uint32 Checksum(const std::string& str) const;
47
48   // Encode the packet with kEncodingString. This is also used for decoding.
49   std::string Encode(const std::string& input) const;
50
51   static const uint32 kVersion;
52   static const uint32 kMaxNumberProbePackets;
53   static const uint32 kMaxProbePacketBytes;
54   static const uint32 kMaxPacingIntervalMicros;
55   static const char kEncodingString[];
56
57   DISALLOW_COPY_AND_ASSIGN(ProbeMessage);
58 };
59 }       // namespace chrome_browser_net
60 #endif  // CHROME_BROWSER_NET_PROBE_MESSAGE_H_