Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/net/socket_stream.h" | 9 #include "chrome/common/net/socket_stream.h" |
| 10 #include "chrome/common/net/url_request_context_getter.h" | 10 #include "chrome/common/net/url_request_context_getter.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/render_messages_params.h" | |
| 12 #include "net/socket_stream/socket_stream_job.h" | 13 #include "net/socket_stream/socket_stream_job.h" |
| 13 | 14 |
|
Randy Smith (Not in Mondays)
2010/12/26 19:44:28
Nit: Remove extra blank line.
| |
| 15 | |
| 14 static const char* kSocketHostKey = "socketHost"; | 16 static const char* kSocketHostKey = "socketHost"; |
| 15 | 17 |
| 16 class SocketStreamInfo : public net::SocketStream::UserData { | 18 class SocketStreamInfo : public net::SocketStream::UserData { |
| 17 public: | 19 public: |
| 18 explicit SocketStreamInfo(SocketStreamHost* host) : host_(host) {} | 20 explicit SocketStreamInfo(SocketStreamHost* host) : host_(host) {} |
| 19 virtual ~SocketStreamInfo() {} | 21 virtual ~SocketStreamInfo() {} |
| 20 SocketStreamHost* host() const { return host_; } | 22 SocketStreamHost* host() const { return host_; } |
| 21 | 23 |
| 22 private: | 24 private: |
| 23 SocketStreamHost* host_; | 25 SocketStreamHost* host_; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 48 SocketStreamHost::~SocketStreamHost() { | 50 SocketStreamHost::~SocketStreamHost() { |
| 49 VLOG(1) << "SocketStreamHost destructed socket_id=" << socket_id_; | 51 VLOG(1) << "SocketStreamHost destructed socket_id=" << socket_id_; |
| 50 if (!receiver_->Send(new ViewMsg_SocketStream_Closed(socket_id_))) | 52 if (!receiver_->Send(new ViewMsg_SocketStream_Closed(socket_id_))) |
| 51 LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; | 53 LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; |
| 52 socket_->DetachDelegate(); | 54 socket_->DetachDelegate(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void SocketStreamHost::Connect(const GURL& url) { | 57 void SocketStreamHost::Connect(const GURL& url) { |
| 56 VLOG(1) << "SocketStreamHost::Connect url=" << url; | 58 VLOG(1) << "SocketStreamHost::Connect url=" << url; |
| 57 socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, delegate_); | 59 socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, delegate_); |
| 58 URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); | 60 |
| 59 if (context_getter) | 61 // We use request_id==0 and request_data.resource_type=ResourceType::LAST_TYPE |
| 60 socket_->set_context(context_getter->GetURLRequestContext()); | 62 // here. |
| 63 // ResourceMessageFilter::GetRequestContext() doesn't check request_id | |
| 64 // and only checks request_data.resource_type is ResourceType::MEDIA or not. | |
| 65 // TODO(ukai): merge WebSocketStreamHandleBridge into ResourceLoaderBridge, | |
| 66 // so that we can use the same request_id. | |
| 67 ViewHostMsg_Resource_Request request_data; | |
| 68 request_data.resource_type = ResourceType::LAST_TYPE; | |
| 69 URLRequestContext* context = receiver_->GetRequestContext(0, request_data); | |
| 70 if (!context) { | |
| 71 URLRequestContextGetter* context_getter = | |
| 72 Profile::GetDefaultRequestContext(); | |
| 73 if (context_getter) | |
| 74 context = context_getter->GetURLRequestContext(); | |
| 75 } | |
| 76 socket_->set_context(context); | |
| 61 socket_->SetUserData(kSocketHostKey, new SocketStreamInfo(this)); | 77 socket_->SetUserData(kSocketHostKey, new SocketStreamInfo(this)); |
| 62 socket_->Connect(); | 78 socket_->Connect(); |
| 63 } | 79 } |
| 64 | 80 |
| 65 bool SocketStreamHost::SendData(const std::vector<char>& data) { | 81 bool SocketStreamHost::SendData(const std::vector<char>& data) { |
| 66 VLOG(1) << "SocketStreamHost::SendData"; | 82 VLOG(1) << "SocketStreamHost::SendData"; |
| 67 return socket_ && socket_->SendData(&data[0], data.size()); | 83 return socket_ && socket_->SendData(&data[0], data.size()); |
| 68 } | 84 } |
| 69 | 85 |
| 70 void SocketStreamHost::Close() { | 86 void SocketStreamHost::Close() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 81 | 97 |
| 82 bool SocketStreamHost::SentData(int amount_sent) { | 98 bool SocketStreamHost::SentData(int amount_sent) { |
| 83 return receiver_->Send(new ViewMsg_SocketStream_SentData( | 99 return receiver_->Send(new ViewMsg_SocketStream_SentData( |
| 84 socket_id_, amount_sent)); | 100 socket_id_, amount_sent)); |
| 85 } | 101 } |
| 86 | 102 |
| 87 bool SocketStreamHost::ReceivedData(const char* data, int len) { | 103 bool SocketStreamHost::ReceivedData(const char* data, int len) { |
| 88 return receiver_->Send(new ViewMsg_SocketStream_ReceivedData( | 104 return receiver_->Send(new ViewMsg_SocketStream_ReceivedData( |
| 89 socket_id_, std::vector<char>(data, data + len))); | 105 socket_id_, std::vector<char>(data, data + len))); |
| 90 } | 106 } |
| OLD | NEW |