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

Side by Side Diff: chrome/browser/renderer_host/socket_stream_host.cc

Issue 5406002: Use proper URLRequestContext for WebSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/profile.h" 8 #include "chrome/browser/profile.h"
9 #include "chrome/browser/net/chrome_url_request_context.h"
9 #include "chrome/common/net/socket_stream.h" 10 #include "chrome/common/net/socket_stream.h"
10 #include "chrome/common/net/url_request_context_getter.h" 11 #include "chrome/common/net/url_request_context_getter.h"
11 #include "chrome/common/render_messages.h" 12 #include "chrome/common/render_messages.h"
13 #include "chrome/common/render_messages_params.h"
12 #include "net/socket_stream/socket_stream_job.h" 14 #include "net/socket_stream/socket_stream_job.h"
13 15
16
14 static const char* kSocketHostKey = "socketHost"; 17 static const char* kSocketHostKey = "socketHost";
15 18
16 class SocketStreamInfo : public net::SocketStream::UserData { 19 class SocketStreamInfo : public net::SocketStream::UserData {
17 public: 20 public:
18 explicit SocketStreamInfo(SocketStreamHost* host) : host_(host) {} 21 explicit SocketStreamInfo(SocketStreamHost* host) : host_(host) {}
19 virtual ~SocketStreamInfo() {} 22 virtual ~SocketStreamInfo() {}
20 SocketStreamHost* host() const { return host_; } 23 SocketStreamHost* host() const { return host_; }
21 24
22 private: 25 private:
23 SocketStreamHost* host_; 26 SocketStreamHost* host_;
(...skipping 24 matching lines...) Expand all
48 SocketStreamHost::~SocketStreamHost() { 51 SocketStreamHost::~SocketStreamHost() {
49 VLOG(1) << "SocketStreamHost destructed socket_id=" << socket_id_; 52 VLOG(1) << "SocketStreamHost destructed socket_id=" << socket_id_;
50 if (!receiver_->Send(new ViewMsg_SocketStream_Closed(socket_id_))) 53 if (!receiver_->Send(new ViewMsg_SocketStream_Closed(socket_id_)))
51 LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; 54 LOG(ERROR) << "ViewMsg_SocketStream_Closed failed.";
52 socket_->DetachDelegate(); 55 socket_->DetachDelegate();
53 } 56 }
54 57
55 void SocketStreamHost::Connect(const GURL& url) { 58 void SocketStreamHost::Connect(const GURL& url) {
56 VLOG(1) << "SocketStreamHost::Connect url=" << url; 59 VLOG(1) << "SocketStreamHost::Connect url=" << url;
57 socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, delegate_); 60 socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, delegate_);
58 URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); 61
59 if (context_getter) 62 // We use request_id==0 and request_data.resource_type=ResourceType::LAST_TYPE
60 socket_->set_context(context_getter->GetURLRequestContext()); 63 // here.
64 // ResourceMessageFilter::GetReuqestContext() doesn't check request_id
eroman 2010/12/03 06:16:39 typo: RequestContext
ukai 2010/12/07 02:21:04 Done.
65 // and only checks request_data.resource_type is ResourceType::MEDIA or not.
66 // TODO(ukai): merge WebSocketStreamHandleBridge into ResourceLoaderBridge,
67 // so that we can use the same request_id.
Randy Smith (Not in Mondays) 2010/11/30 18:17:47 So the problem I have with this approach is that,
68 ViewHostMsg_Resource_Request request_data;
69 request_data.resource_type = ResourceType::LAST_TYPE;
70 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>(
Randy Smith (Not in Mondays) 2010/11/30 18:17:47 Why make context of type ChromeURLRequestContext r
ukai 2010/12/07 02:21:04 Done.
71 receiver_->GetRequestContext(0, request_data));
72 if (!context) {
73 URLRequestContextGetter* context_getter =
74 Profile::GetDefaultRequestContext();
75 if (context_getter)
76 context = static_cast<ChromeURLRequestContext*>(
77 context_getter->GetURLRequestContext());
78 }
79 socket_->set_context(context);
61 socket_->SetUserData(kSocketHostKey, new SocketStreamInfo(this)); 80 socket_->SetUserData(kSocketHostKey, new SocketStreamInfo(this));
62 socket_->Connect(); 81 socket_->Connect();
63 } 82 }
64 83
65 bool SocketStreamHost::SendData(const std::vector<char>& data) { 84 bool SocketStreamHost::SendData(const std::vector<char>& data) {
66 VLOG(1) << "SocketStreamHost::SendData"; 85 VLOG(1) << "SocketStreamHost::SendData";
67 return socket_ && socket_->SendData(&data[0], data.size()); 86 return socket_ && socket_->SendData(&data[0], data.size());
68 } 87 }
69 88
70 void SocketStreamHost::Close() { 89 void SocketStreamHost::Close() {
(...skipping 10 matching lines...) Expand all
81 100
82 bool SocketStreamHost::SentData(int amount_sent) { 101 bool SocketStreamHost::SentData(int amount_sent) {
83 return receiver_->Send(new ViewMsg_SocketStream_SentData( 102 return receiver_->Send(new ViewMsg_SocketStream_SentData(
84 socket_id_, amount_sent)); 103 socket_id_, amount_sent));
85 } 104 }
86 105
87 bool SocketStreamHost::ReceivedData(const char* data, int len) { 106 bool SocketStreamHost::ReceivedData(const char* data, int len) {
88 return receiver_->Send(new ViewMsg_SocketStream_ReceivedData( 107 return receiver_->Send(new ViewMsg_SocketStream_ReceivedData(
89 socket_id_, std::vector<char>(data, data + len))); 108 socket_id_, std::vector<char>(data, data + len)));
90 } 109 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698