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

Unified Diff: remoting/host/gnubby_socket.h

Issue 205493005: Do minimal processing of gnubby data. Add request timeouts and send error (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix parameter type Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/gnubby_socket.h
diff --git a/remoting/host/gnubby_socket.h b/remoting/host/gnubby_socket.h
new file mode 100644
index 0000000000000000000000000000000000000000..9356e94d2c43716fa49d5419bf2b5ae19f2d631d
--- /dev/null
+++ b/remoting/host/gnubby_socket.h
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_HOST_GNUBBY_SOCKET_H_
+#define REMOTING_HOST_GNUBBY_SOCKET_H_
+
+#include <string>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/threading/non_thread_safe.h"
+#include "base/timer/timer.h"
+#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
+
+namespace remoting {
+
+// Class that manages a socket used for gnubby requests.
+class GnubbySocket : public base::NonThreadSafe {
+ public:
+ GnubbySocket(scoped_ptr<net::StreamListenSocket> socket,
+ const base::Closure& timeout_callback);
+
Sergey Ulanov 2014/03/21 22:53:16 declare destructor here and define in .cc file
psj 2014/03/21 23:24:17 Done.
+ // Adds data to the current request.
+ void AddRequestData(const char* data, int data_len);
+
+ // Gets the current request data and clears it.
+ void GetAndClearRequestData(std::string* data_out);
+
+ // Returns true if the current request is complete.
+ bool IsRequestComplete() const;
+
+ // Returns true if the stated request size is larger than the allowed maximum.
+ bool IsRequestTooLarge() const;
+
+ // Sends response data to the socket.
+ void SendResponse(const std::string& data);
+
+ // Sends an SSH error code to the socket.
+ void SendSshError();
+
+ // Returns true if |socket| is the same one owned by this object.
+ bool IsSocket(net::StreamListenSocket* socket) const;
+
+ // Sets a timer for testing.
+ 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.
+
+ private:
+ // Returns the stated request length.
+ size_t GetRequestLength() const;
+
+ // Returns the response length bytes.
+ std::string GetResponseLengthAsBytes(const std::string& response) const;
+
+ // Resets the socket activity timer.
+ void ResetTimer();
+
+ // The socket.
+ scoped_ptr<net::StreamListenSocket> socket_;
+
+ // Request data.
+ std::vector<char> request_data_;
+
+ // The activity timer.
+ scoped_ptr<base::Timer> timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(GnubbySocket);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_GNUBBY_SOCKET_H_

Powered by Google App Engine
This is Rietveld 408576698