OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
7 | 7 |
8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() {} | 82 SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() {} |
83 | 83 |
84 void SocketStream::ResponseHeaders::Realloc(size_t new_size) { | 84 void SocketStream::ResponseHeaders::Realloc(size_t new_size) { |
85 headers_.reset(static_cast<char*>(realloc(headers_.release(), new_size))); | 85 headers_.reset(static_cast<char*>(realloc(headers_.release(), new_size))); |
86 } | 86 } |
87 | 87 |
88 SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } | 88 SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } |
89 | 89 |
90 SocketStream::SocketStream(const GURL& url, Delegate* delegate) | 90 SocketStream::SocketStream(const GURL& url, Delegate* delegate, |
| 91 URLRequestContext* context, |
| 92 CookieStore* cookie_store) |
91 : delegate_(delegate), | 93 : delegate_(delegate), |
92 url_(url), | 94 url_(url), |
93 max_pending_send_allowed_(kMaxPendingSendAllowed), | 95 max_pending_send_allowed_(kMaxPendingSendAllowed), |
94 context_(NULL), | 96 context_(context), |
95 next_state_(STATE_NONE), | 97 next_state_(STATE_NONE), |
96 factory_(ClientSocketFactory::GetDefaultFactory()), | 98 factory_(ClientSocketFactory::GetDefaultFactory()), |
97 proxy_mode_(kDirectConnection), | 99 proxy_mode_(kDirectConnection), |
98 proxy_url_(url), | 100 proxy_url_(url), |
99 pac_request_(NULL), | 101 pac_request_(NULL), |
100 connection_(new ClientSocketHandle), | 102 connection_(new ClientSocketHandle), |
101 privacy_mode_(kPrivacyModeDisabled), | 103 privacy_mode_(kPrivacyModeDisabled), |
102 // Unretained() is required; without it, Bind() creates a circular | 104 // Unretained() is required; without it, Bind() creates a circular |
103 // dependency and the SocketStream object will not be freed. | 105 // dependency and the SocketStream object will not be freed. |
104 io_callback_(base::Bind(&SocketStream::OnIOCompleted, | 106 io_callback_(base::Bind(&SocketStream::OnIOCompleted, |
105 base::Unretained(this))), | 107 base::Unretained(this))), |
106 read_buf_(NULL), | 108 read_buf_(NULL), |
107 current_write_buf_(NULL), | 109 current_write_buf_(NULL), |
108 waiting_for_write_completion_(false), | 110 waiting_for_write_completion_(false), |
109 closing_(false), | 111 closing_(false), |
110 server_closed_(false), | 112 server_closed_(false), |
111 metrics_(new SocketStreamMetrics(url)) { | 113 metrics_(new SocketStreamMetrics(url)), |
| 114 cookie_store_(cookie_store) { |
112 DCHECK(base::MessageLoop::current()) | 115 DCHECK(base::MessageLoop::current()) |
113 << "The current base::MessageLoop must exist"; | 116 << "The current base::MessageLoop must exist"; |
114 DCHECK(base::MessageLoopForIO::IsCurrent()) | 117 DCHECK(base::MessageLoopForIO::IsCurrent()) |
115 << "The current base::MessageLoop must be TYPE_IO"; | 118 << "The current base::MessageLoop must be TYPE_IO"; |
116 DCHECK(delegate_); | 119 DCHECK(delegate_); |
| 120 |
| 121 if (context_) { |
| 122 if (!cookie_store_) |
| 123 cookie_store_ = context_->cookie_store(); |
| 124 |
| 125 net_log_ = BoundNetLog::Make( |
| 126 context->net_log(), |
| 127 NetLog::SOURCE_SOCKET_STREAM); |
| 128 |
| 129 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
| 130 } |
117 } | 131 } |
118 | 132 |
119 SocketStream::UserData* SocketStream::GetUserData( | 133 SocketStream::UserData* SocketStream::GetUserData( |
120 const void* key) const { | 134 const void* key) const { |
121 UserDataMap::const_iterator found = user_data_.find(key); | 135 UserDataMap::const_iterator found = user_data_.find(key); |
122 if (found != user_data_.end()) | 136 if (found != user_data_.end()) |
123 return found->second.get(); | 137 return found->second.get(); |
124 return NULL; | 138 return NULL; |
125 } | 139 } |
126 | 140 |
127 void SocketStream::SetUserData(const void* key, UserData* data) { | 141 void SocketStream::SetUserData(const void* key, UserData* data) { |
128 user_data_[key] = linked_ptr<UserData>(data); | 142 user_data_[key] = linked_ptr<UserData>(data); |
129 } | 143 } |
130 | 144 |
131 bool SocketStream::is_secure() const { | 145 bool SocketStream::is_secure() const { |
132 return url_.SchemeIs("wss"); | 146 return url_.SchemeIs("wss"); |
133 } | 147 } |
134 | 148 |
135 void SocketStream::set_context(URLRequestContext* context) { | 149 void SocketStream::DetachContext() { |
136 const URLRequestContext* prev_context = context_; | 150 if (!context_) |
| 151 return; |
137 | 152 |
138 context_ = context; | 153 if (pac_request_) { |
| 154 context_->proxy_service()->CancelPacRequest(pac_request_); |
| 155 pac_request_ = NULL; |
| 156 } |
139 | 157 |
140 if (prev_context != context) { | 158 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); |
141 if (prev_context && pac_request_) { | 159 net_log_ = BoundNetLog(); |
142 prev_context->proxy_service()->CancelPacRequest(pac_request_); | |
143 pac_request_ = NULL; | |
144 } | |
145 | 160 |
146 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); | 161 context_ = NULL; |
147 net_log_ = BoundNetLog(); | 162 cookie_store_ = NULL; |
148 | |
149 if (context) { | |
150 net_log_ = BoundNetLog::Make( | |
151 context->net_log(), | |
152 NetLog::SOURCE_SOCKET_STREAM); | |
153 | |
154 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | |
155 } | |
156 } | |
157 } | 163 } |
158 | 164 |
159 void SocketStream::CheckPrivacyMode() { | 165 void SocketStream::CheckPrivacyMode() { |
160 if (context_ && context_->network_delegate()) { | 166 if (context_ && context_->network_delegate()) { |
161 bool enable = context_->network_delegate()->CanEnablePrivacyMode(url_, | 167 bool enable = context_->network_delegate()->CanEnablePrivacyMode(url_, |
162 url_); | 168 url_); |
163 privacy_mode_ = enable ? kPrivacyModeEnabled : kPrivacyModeDisabled; | 169 privacy_mode_ = enable ? kPrivacyModeEnabled : kPrivacyModeDisabled; |
164 // Disable Channel ID if privacy mode is enabled. | 170 // Disable Channel ID if privacy mode is enabled. |
165 if (enable) | 171 if (enable) |
166 server_ssl_config_.channel_id_enabled = false; | 172 server_ssl_config_.channel_id_enabled = false; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 void SocketStream::CancelWithSSLError(const SSLInfo& ssl_info) { | 317 void SocketStream::CancelWithSSLError(const SSLInfo& ssl_info) { |
312 CancelWithError(MapCertStatusToNetError(ssl_info.cert_status)); | 318 CancelWithError(MapCertStatusToNetError(ssl_info.cert_status)); |
313 } | 319 } |
314 | 320 |
315 void SocketStream::ContinueDespiteError() { | 321 void SocketStream::ContinueDespiteError() { |
316 base::MessageLoop::current()->PostTask( | 322 base::MessageLoop::current()->PostTask( |
317 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); | 323 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); |
318 } | 324 } |
319 | 325 |
320 SocketStream::~SocketStream() { | 326 SocketStream::~SocketStream() { |
321 set_context(NULL); | 327 DetachContext(); |
322 DCHECK(!delegate_); | 328 DCHECK(!delegate_); |
323 DCHECK(!pac_request_); | 329 DCHECK(!pac_request_); |
324 } | 330 } |
325 | 331 |
326 SocketStream::RequestHeaders::~RequestHeaders() { data_ = NULL; } | 332 SocketStream::RequestHeaders::~RequestHeaders() { data_ = NULL; } |
327 | 333 |
328 void SocketStream::set_addresses(const AddressList& addresses) { | 334 void SocketStream::set_addresses(const AddressList& addresses) { |
329 addresses_ = addresses; | 335 addresses_ = addresses; |
330 } | 336 } |
331 | 337 |
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 const bool fatal = context_->transport_security_state() && | 1341 const bool fatal = context_->transport_security_state() && |
1336 context_->transport_security_state()->GetDomainState(url_.host(), | 1342 context_->transport_security_state()->GetDomainState(url_.host(), |
1337 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), | 1343 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), |
1338 &domain_state) && | 1344 &domain_state) && |
1339 domain_state.ShouldSSLErrorsBeFatal(); | 1345 domain_state.ShouldSSLErrorsBeFatal(); |
1340 | 1346 |
1341 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 1347 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
1342 return ERR_IO_PENDING; | 1348 return ERR_IO_PENDING; |
1343 } | 1349 } |
1344 | 1350 |
| 1351 CookieStore* SocketStream::cookie_store() const { |
| 1352 return cookie_store_; |
| 1353 } |
| 1354 |
1345 } // namespace net | 1355 } // namespace net |
OLD | NEW |