| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/socket_stream_host.h" | 5 #include "chrome/browser/renderer_host/socket_stream_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/net/url_request_context_getter.h" | 9 #include "chrome/browser/net/url_request_context_getter.h" |
| 10 #include "chrome/common/net/socket_stream.h" | 10 #include "chrome/common/net/socket_stream.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "net/socket_stream/socket_stream.h" | 12 #include "net/socket_stream/socket_stream_job.h" |
| 13 | 13 |
| 14 static const char* kSocketHostKey = "socketHost"; | 14 static const char* kSocketHostKey = "socketHost"; |
| 15 | 15 |
| 16 class SocketStreamInfo : public net::SocketStream::UserData { | 16 class SocketStreamInfo : public net::SocketStream::UserData { |
| 17 public: | 17 public: |
| 18 explicit SocketStreamInfo(SocketStreamHost* host) : host_(host) {} | 18 explicit SocketStreamInfo(SocketStreamHost* host) : host_(host) {} |
| 19 virtual ~SocketStreamInfo() {} | 19 virtual ~SocketStreamInfo() {} |
| 20 SocketStreamHost* host() const { return host_; } | 20 SocketStreamHost* host() const { return host_; } |
| 21 | 21 |
| 22 private: | 22 private: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 48 SocketStreamHost::~SocketStreamHost() { | 48 SocketStreamHost::~SocketStreamHost() { |
| 49 LOG(INFO) << "SocketStreamHost destructed socket_id=" << socket_id_; | 49 LOG(INFO) << "SocketStreamHost destructed socket_id=" << socket_id_; |
| 50 if (!receiver_->Send(new ViewMsg_SocketStream_Closed(socket_id_))) { | 50 if (!receiver_->Send(new ViewMsg_SocketStream_Closed(socket_id_))) { |
| 51 LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; | 51 LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; |
| 52 } | 52 } |
| 53 socket_->DetachDelegate(); | 53 socket_->DetachDelegate(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void SocketStreamHost::Connect(const GURL& url) { | 56 void SocketStreamHost::Connect(const GURL& url) { |
| 57 LOG(INFO) << "SocketStreamHost::Connect url=" << url; | 57 LOG(INFO) << "SocketStreamHost::Connect url=" << url; |
| 58 socket_ = new net::SocketStream(url, delegate_); | 58 socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, delegate_); |
| 59 URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); | 59 URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); |
| 60 if (context_getter) | 60 if (context_getter) |
| 61 socket_->set_context(context_getter->GetURLRequestContext()); | 61 socket_->set_context(context_getter->GetURLRequestContext()); |
| 62 socket_->SetUserData(kSocketHostKey, new SocketStreamInfo(this)); | 62 socket_->SetUserData(kSocketHostKey, new SocketStreamInfo(this)); |
| 63 socket_->Connect(); | 63 socket_->Connect(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool SocketStreamHost::SendData(const std::vector<char>& data) { | 66 bool SocketStreamHost::SendData(const std::vector<char>& data) { |
| 67 LOG(INFO) << "SocketStreamHost::SendData"; | 67 LOG(INFO) << "SocketStreamHost::SendData"; |
| 68 if (!socket_) | 68 if (!socket_) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 | 84 |
| 85 bool SocketStreamHost::SentData(int amount_sent) { | 85 bool SocketStreamHost::SentData(int amount_sent) { |
| 86 return receiver_->Send(new ViewMsg_SocketStream_SentData( | 86 return receiver_->Send(new ViewMsg_SocketStream_SentData( |
| 87 socket_id_, amount_sent)); | 87 socket_id_, amount_sent)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool SocketStreamHost::ReceivedData(const char* data, int len) { | 90 bool SocketStreamHost::ReceivedData(const char* data, int len) { |
| 91 return receiver_->Send(new ViewMsg_SocketStream_ReceivedData( | 91 return receiver_->Send(new ViewMsg_SocketStream_ReceivedData( |
| 92 socket_id_, std::vector<char>(data, data + len))); | 92 socket_id_, std::vector<char>(data, data + len))); |
| 93 } | 93 } |
| OLD | NEW |