Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/http/http_pipelined_host_forced.h" | |
| 6 | |
| 7 #include "base/values.h" | |
| 8 #include "net/http/http_pipelined_connection_impl.h" | |
| 9 #include "net/http/http_pipelined_stream.h" | |
| 10 #include "net/socket/buffered_write_stream_socket.h" | |
| 11 #include "net/socket/client_socket_handle.h" | |
| 12 | |
| 13 using base::DictionaryValue; | |
| 14 using base::ListValue; | |
| 15 using base::Value; | |
|
mmenke
2012/02/23 18:54:58
These aren't needed - they're already in base/valu
James Simonsen
2012/02/23 23:49:46
values.h says not to rely on that in new code.
| |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 HttpPipelinedHostForced::HttpPipelinedHostForced( | |
| 20 HttpPipelinedHost::Delegate* delegate, | |
| 21 const Key& key, | |
| 22 HttpPipelinedConnection::Factory* factory) | |
| 23 : delegate_(delegate), | |
| 24 key_(key), | |
| 25 factory_(factory) { | |
|
mmenke
2012/02/23 18:54:58
Think you should DCHECK for unexpected key.force_p
James Simonsen
2012/02/23 23:49:46
Done.
| |
| 26 if (!factory) { | |
| 27 factory_.reset(new HttpPipelinedConnectionImpl::Factory()); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 HttpPipelinedHostForced::~HttpPipelinedHostForced() { | |
| 32 CHECK(!pipeline_.get()); | |
| 33 } | |
| 34 | |
| 35 HttpPipelinedStream* HttpPipelinedHostForced::CreateStreamOnNewPipeline( | |
| 36 ClientSocketHandle* connection, | |
| 37 const SSLConfig& used_ssl_config, | |
| 38 const ProxyInfo& used_proxy_info, | |
| 39 const BoundNetLog& net_log, | |
| 40 bool was_npn_negotiated, | |
| 41 SSLClientSocket::NextProto protocol_negotiated) { | |
| 42 CHECK(!pipeline_.get()); | |
| 43 StreamSocket* wrapped_socket = connection->release_socket(); | |
| 44 BufferedWriteStreamSocket* buffered_socket = new BufferedWriteStreamSocket( | |
| 45 wrapped_socket); | |
| 46 connection->set_socket(buffered_socket); | |
| 47 pipeline_.reset(factory_->CreateNewPipeline( | |
| 48 connection, this, key_.origin(), used_ssl_config, used_proxy_info, | |
| 49 net_log, was_npn_negotiated, protocol_negotiated)); | |
| 50 return pipeline_->CreateNewStream(); | |
| 51 } | |
| 52 | |
| 53 HttpPipelinedStream* HttpPipelinedHostForced::CreateStreamOnExistingPipeline() { | |
| 54 if (!pipeline_.get()) { | |
| 55 return NULL; | |
| 56 } | |
| 57 return pipeline_->CreateNewStream(); | |
| 58 } | |
| 59 | |
| 60 bool HttpPipelinedHostForced::IsExistingPipelineAvailable() const { | |
| 61 return pipeline_.get() != NULL; | |
| 62 } | |
| 63 | |
| 64 const HttpPipelinedHost::Key& HttpPipelinedHostForced::key() const { | |
| 65 return key_; | |
| 66 } | |
| 67 | |
| 68 void HttpPipelinedHostForced::OnPipelineEmpty( | |
| 69 HttpPipelinedConnection* pipeline) { | |
| 70 CHECK_EQ(pipeline_.get(), pipeline); | |
| 71 pipeline_.reset(); | |
| 72 delegate_->OnHostIdle(this); | |
| 73 // WARNING: We'll probably be deleted here. | |
| 74 } | |
| 75 | |
| 76 void HttpPipelinedHostForced::OnPipelineHasCapacity( | |
| 77 HttpPipelinedConnection* pipeline) { | |
| 78 CHECK_EQ(pipeline_.get(), pipeline); | |
| 79 delegate_->OnHostHasAdditionalCapacity(this); | |
| 80 if (!pipeline->depth()) { | |
| 81 OnPipelineEmpty(pipeline); | |
| 82 // WARNING: We might be deleted here. | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 void HttpPipelinedHostForced::OnPipelineFeedback( | |
| 87 HttpPipelinedConnection* pipeline, | |
| 88 HttpPipelinedConnection::Feedback feedback) { | |
| 89 // We don't care. We always pipeline. | |
| 90 } | |
| 91 | |
| 92 Value* HttpPipelinedHostForced::PipelineInfoToValue() const { | |
| 93 ListValue* list_value = new ListValue(); | |
| 94 if (pipeline_.get()) { | |
| 95 DictionaryValue* pipeline_dict = new DictionaryValue; | |
| 96 pipeline_dict->SetString("host", key_.origin().ToString()); | |
| 97 pipeline_dict->SetBoolean("forced", key_.force_pipelining()); | |
| 98 pipeline_dict->SetInteger("depth", pipeline_->depth()); | |
| 99 pipeline_dict->SetInteger("capacity", 1000); | |
| 100 pipeline_dict->SetBoolean("usable", pipeline_->usable()); | |
| 101 pipeline_dict->SetBoolean("active", pipeline_->active()); | |
| 102 pipeline_dict->SetInteger("source_id", pipeline_->net_log().source().id); | |
| 103 list_value->Append(pipeline_dict); | |
| 104 } | |
| 105 return list_value; | |
| 106 } | |
| 107 | |
| 108 } // namespace net | |
| OLD | NEW |