OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 | |
joedow
2016/05/03 22:28:29
Missing guard macro in the header file.
Hzj_jie
2016/05/04 02:11:56
Done.
| |
5 #include <memory> | |
6 | |
7 #include "base/atomicops.h" | |
8 #include "remoting/protocol/audio_stub.h" | |
9 #include "remoting/protocol/client_stub.h" | |
10 #include "remoting/protocol/host_stub.h" | |
11 #include "remoting/protocol/video_stub.h" | |
12 | |
13 namespace base { | |
14 class Time; | |
15 | |
16 #ifndef ARCH_CPU_64_BITS | |
17 class Lock; | |
18 #endif // ifndef ARCH_CPU_64_BITS | |
19 | |
20 } // namespace ::base | |
21 | |
22 namespace google { | |
23 namespace protobuf { | |
24 class MessageLite; | |
25 } // namespace protobuf | |
26 } // namespace ::google | |
27 | |
28 namespace remoting { | |
29 | |
30 namespace protocol { | |
31 class FakeConnectionToClient; | |
32 } // namespace protocol | |
33 | |
34 namespace test { | |
35 | |
joedow
2016/05/03 22:28:29
This file should probably get broken down a bit mo
Hzj_jie
2016/05/04 02:11:56
Done.
| |
36 template <typename T> | |
37 class NoBarrierAtomic { | |
38 public: | |
39 T operator++() { | |
40 return base::subtle::NoBarrier_AtomicIncrement(&i_, 1) - 1; | |
41 } | |
42 | |
43 T operator++(int) { | |
44 return base::subtle::NoBarrier_AtomicIncrement(&i_, 1); | |
45 } | |
46 | |
47 T operator--() { | |
48 return base::subtle::NoBarrier_AtomicIncrement(&i_, -1) - 1; | |
49 } | |
50 | |
51 T operator--(int) { | |
52 return base::subtle::NoBarrier_AtomicIncrement(&i_, -1); | |
53 } | |
54 | |
55 T operator+=(T other) { | |
56 return base::subtle::NoBarrier_AtomicIncrement(&i_, other); | |
57 } | |
58 | |
59 T operator-=(T other) { | |
60 return base::subtle::NoBarrier_AtomicIncrement(&i_, -other); | |
61 } | |
62 | |
63 T operator*() const { | |
64 return base::subtle::NoBarrier_Load(&i_); | |
65 } | |
66 | |
67 private: | |
68 volatile T i_; | |
69 }; | |
70 | |
71 class NoBarrierAtomicInt32 : public NoBarrierAtomic<base::subtle::Atomic32> {}; | |
72 #ifdef ARCH_CPU_64_BITS | |
73 class NoBarrierAtomicInt64 : public NoBarrierAtomic<base::subtle::Atomic64> {}; | |
74 #else // ifdef ARCH_CPU_64_BITS | |
75 | |
76 // A barriered, lock based implementation | |
77 class NoBarrierAtomicInt64 { | |
78 public: | |
79 int64_t operator++(); | |
80 int64_t operator++(int); | |
81 int64_t operator--(); | |
82 int64_t operator--(int); | |
83 int64_t operator+=(int64_t other); | |
84 int64_t operator-=(int64_t other); | |
85 int64_t operator*() const; | |
86 | |
87 private: | |
88 volatile int64_t i_; | |
89 mutable base::Lock lock_; // field is used in operator*() const | |
90 }; | |
91 #endif // ifdef ARCH_CPU_64_BITS | |
92 | |
93 class MessageCounter { | |
94 public: | |
95 MessageCounter(); | |
96 | |
97 int message_count() const; | |
98 int64_t message_size() const; | |
99 int last_message_size() const; | |
100 double DurationSeconds() const; | |
101 double MessagesPerSecond() const; | |
102 double SizePerSecond() const; | |
103 double AverageMessageSize() const; | |
104 | |
105 void LogMessage(const ::google::protobuf::MessageLite& message); | |
106 | |
107 private: | |
108 NoBarrierAtomicInt32 count_; | |
109 NoBarrierAtomicInt64 size_; | |
110 int last_size_; | |
111 base::Time start_time_; | |
112 }; | |
113 | |
114 class CounterClientStub : public protocol::ClientStub, public MessageCounter { | |
115 public: | |
116 void DeliverHostMessage(const protocol::ExtensionMessage& message) override; | |
117 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override {} | |
118 void SetCapabilities(const protocol::Capabilities& capabilities) override {} | |
119 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override {} | |
120 void SetPairingResponse(const protocol::PairingResponse& response) override {} | |
121 void SetVideoLayout(const protocol::VideoLayout& video_layout) override {} | |
122 }; | |
123 | |
124 class CounterHostStub : public protocol::HostStub, public MessageCounter { | |
125 public: | |
126 void ControlAudio(const protocol::AudioControl& audio_control) override {} | |
127 void ControlVideo(const protocol::VideoControl& video_control) override {} | |
128 void DeliverClientMessage( | |
129 const protocol::ExtensionMessage& message) override; | |
130 void NotifyClientResolution( | |
131 const protocol::ClientResolution& resolution) override {} | |
132 void RequestPairing( | |
133 const protocol::PairingRequest& pairing_request) override {} | |
134 void SetCapabilities(const protocol::Capabilities& capabilities) override {} | |
135 }; | |
136 | |
137 class CounterAudioStub : public protocol::AudioStub, public MessageCounter { | |
138 public: | |
139 void ProcessAudioPacket(std::unique_ptr<AudioPacket> audio_packet, | |
140 const base::Closure& done) override; | |
141 }; | |
142 | |
143 class CounterVideoStub : public protocol::VideoStub, public MessageCounter { | |
144 public: | |
145 CounterVideoStub(protocol::FakeConnectionToClient* connection); | |
146 void ProcessVideoPacket(std::unique_ptr<VideoPacket> video_packet, | |
147 const base::Closure& done) override; | |
148 | |
149 private: | |
150 protocol::FakeConnectionToClient* connection_ = nullptr; | |
joedow
2016/05/03 22:28:29
DISALLOW_COPY_AND_ASSIGN(...)?
Hzj_jie
2016/05/04 02:11:56
I have disallowed copy and assign for MessageCount
| |
151 }; | |
152 | |
153 } // namespace test | |
154 } // namespace remoting | |
OLD | NEW |