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

Unified Diff: chrome/browser/renderer_host/socket_stream_host.cc

Issue 202058: WebSocket implementation in Chromium. (Closed)
Patch Set: update Created 11 years, 2 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
« no previous file with comments | « chrome/browser/renderer_host/socket_stream_host.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/socket_stream_host.cc
diff --git a/chrome/browser/renderer_host/socket_stream_host.cc b/chrome/browser/renderer_host/socket_stream_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc59bd60f85389480dc6317f69541aa4c2a284af
--- /dev/null
+++ b/chrome/browser/renderer_host/socket_stream_host.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/browser/renderer_host/socket_stream_host.h"
+
+#include "base/logging.h"
+#include "chrome/browser/profile.h"
+#include "chrome/common/net/socket_stream.h"
+#include "net/socket_stream/socket_stream.h"
+
+static const char* kSocketIdKey = "socketId";
+
+class SocketStreamId : public net::SocketStream::UserData {
+ public:
+ explicit SocketStreamId(int socket_id) : socket_id_(socket_id) {}
+ virtual ~SocketStreamId() {}
+ int socket_id() const { return socket_id_; }
+ private:
+ int socket_id_;
+};
+
+SocketStreamHost::SocketStreamHost(
+ net::SocketStream::Delegate* delegate, int socket_id)
+ : delegate_(delegate),
+ socket_id_(socket_id) {
+ DCHECK_NE(socket_id_, chrome_common_net::kNoSocketId);
+ LOG(INFO) << "SocketStreamHost: socket_id=" << socket_id_;
+}
+
+/* static */
+int SocketStreamHost::SocketIdFromSocketStream(net::SocketStream* socket) {
+ net::SocketStream::UserData* d = socket->GetUserData(kSocketIdKey);
+ if (d) {
+ SocketStreamId* socket_stream_id = static_cast<SocketStreamId*>(d);
+ return socket_stream_id->socket_id();
+ }
+ return chrome_common_net::kNoSocketId;
+}
+
+SocketStreamHost::~SocketStreamHost() {
+ LOG(INFO) << "SocketStreamHost destructed socket_id=" << socket_id_;
+ socket_->DetachDelegate();
+}
+
+void SocketStreamHost::Connect(const GURL& url) {
+ LOG(INFO) << "SocketStreamHost::Connect url=" << url;
+ socket_ = new net::SocketStream(url, delegate_);
+ socket_->set_context(Profile::GetDefaultRequestContext());
+ socket_->SetUserData(kSocketIdKey, new SocketStreamId(socket_id_));
+ socket_->Connect();
+}
+
+bool SocketStreamHost::SendData(const std::vector<char>& data) {
+ LOG(INFO) << "SocketStreamHost::SendData";
+ if (!socket_)
+ return false;
+ return socket_->SendData(&data[0], data.size());
+}
+
+void SocketStreamHost::Close() {
+ LOG(INFO) << "SocketStreamHost::Close";
+ if (!socket_)
+ return;
+ return socket_->Close();
+}
« no previous file with comments | « chrome/browser/renderer_host/socket_stream_host.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698