Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 REMOTING_HOST_GNUBBY_SOCKET_H_ | |
| 6 #define REMOTING_HOST_GNUBBY_SOCKET_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/threading/non_thread_safe.h" | |
| 13 #include "base/timer/timer.h" | |
| 14 #include "net/socket/stream_listen_socket.h" | |
|
Sergey Ulanov
2014/03/21 02:09:37
nit: Forward-declare base::Timer and net::StreamLi
psj
2014/03/21 21:30:45
They are both used in scoped_ptr, so the full clas
Sergey Ulanov
2014/03/21 22:53:16
It still a pointer so you shouldn't need include.
psj
2014/03/21 23:24:17
Ah, OK. It seemed weird that a forward reference w
| |
| 15 | |
| 16 namespace remoting { | |
| 17 | |
| 18 // Class that manages a socket used for gnubby requests. | |
| 19 class GnubbySocket : public base::NonThreadSafe { | |
| 20 public: | |
| 21 GnubbySocket(scoped_ptr<net::StreamListenSocket> socket, | |
| 22 const base::Closure& timeout_callback); | |
| 23 | |
|
Sergey Ulanov
2014/03/21 22:53:16
declare destructor here and define in .cc file
psj
2014/03/21 23:24:17
Done.
| |
| 24 // Adds data to the current request. | |
| 25 void AddRequestData(const char* data, int data_len); | |
| 26 | |
| 27 // Gets the current request data and clears it. | |
| 28 void GetAndClearRequestData(std::string* data_out); | |
| 29 | |
| 30 // Returns true if the current request is complete. | |
| 31 bool IsRequestComplete() const; | |
| 32 | |
| 33 // Returns true if the stated request size is larger than the allowed maximum. | |
| 34 bool IsRequestTooLarge() const; | |
| 35 | |
| 36 // Sends response data to the socket. | |
| 37 void SendResponse(const std::string& data); | |
| 38 | |
| 39 // Sends an SSH error code to the socket. | |
| 40 void SendSshError(); | |
| 41 | |
| 42 // Returns true if |socket| is the same one owned by this object. | |
| 43 bool IsSocket(net::StreamListenSocket* socket) const; | |
| 44 | |
| 45 // Sets a timer for testing. | |
| 46 void SetTimerForTesting(base::Timer*); | |
|
Sergey Ulanov
2014/03/21 02:09:37
use scoped_ptr<> to pass ownership here. Also the
psj
2014/03/21 21:30:45
Done and done.
| |
| 47 | |
| 48 private: | |
| 49 // Returns the stated request length. | |
| 50 size_t GetRequestLength() const; | |
| 51 | |
| 52 // Returns the response length bytes. | |
| 53 std::string GetResponseLengthAsBytes(const std::string& response) const; | |
| 54 | |
| 55 // Resets the socket activity timer. | |
| 56 void ResetTimer(); | |
| 57 | |
| 58 // The socket. | |
| 59 scoped_ptr<net::StreamListenSocket> socket_; | |
| 60 | |
| 61 // Request data. | |
| 62 std::vector<char> request_data_; | |
| 63 | |
| 64 // The activity timer. | |
| 65 scoped_ptr<base::Timer> timer_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(GnubbySocket); | |
| 68 }; | |
| 69 | |
| 70 } // namespace remoting | |
| 71 | |
| 72 #endif // REMOTING_HOST_GNUBBY_SOCKET_H_ | |
| OLD | NEW |