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