diff options
author | Ebrahem Qassem <ekassem@codeaurora.org> | 2011-11-20 14:57:09 +0200 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2012-09-11 13:20:30 -0700 |
commit | 5fbe95affc8eeed93c678b1d271f64dcc4dd919b (patch) | |
tree | 053d8358e76befa6fd95e7cef8319045e534167f /net/http | |
parent | a75b259c30d54752a0d42804631bcf309b381f90 (diff) | |
download | external_chromium-5fbe95affc8eeed93c678b1d271f64dcc4dd919b.zip external_chromium-5fbe95affc8eeed93c678b1d271f64dcc4dd919b.tar.gz external_chromium-5fbe95affc8eeed93c678b1d271f64dcc4dd919b.tar.bz2 |
net: networking optimizations
features:
- early connection
- memory cache
- caching of redirection
- request queue priority
- closing unused sockets
- SHUTR
- fin aggregation
- object prefetch
- dns host name prioritization
Change-Id: Ief90b8206ba48115eaeb12d554424d65f36427ac
Diffstat (limited to 'net/http')
26 files changed, 1175 insertions, 39 deletions
diff --git a/net/http/http_basic_stream.cc b/net/http/http_basic_stream.cc index 6501a59..f74614b 100644 --- a/net/http/http_basic_stream.cc +++ b/net/http/http_basic_stream.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -33,7 +34,7 @@ int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, DCHECK(!parser_.get()); request_info_ = request_info; parser_.reset(new HttpStreamParser(connection_.get(), request_info, - read_buf_, net_log)); + read_buf_, net_log, using_proxy_)); return OK; } diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index d53d525..4a2313c 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2011, 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,6 +36,9 @@ #include "net/http/http_util.h" #include "net/socket/ssl_host_info.h" +#include "net/disk_cache/stat_hub.h" +#include "net/disk_cache/hostres_plugin_bridge.h" + namespace net { namespace { @@ -85,8 +89,14 @@ HttpCache::BackendFactory* HttpCache::DefaultBackend::InMemory(int max_bytes) { int HttpCache::DefaultBackend::CreateBackend(NetLog* net_log, disk_cache::Backend** backend, - CompletionCallback* callback) { + CompletionCallback* callback, + FilePath** stat_db_path) { DCHECK_GE(max_bytes_, 0); + (*stat_db_path) = NULL; + if (type_ == net::DISK_CACHE) { + std::string dataPath = "/data/data/"; + (*stat_db_path) = new FilePath(dataPath + stat_hub::kEnabledAppName + "/databases"); + } return disk_cache::CreateCacheBackend(type_, path_, max_bytes_, true, thread_, net_log, backend, callback); } @@ -339,7 +349,8 @@ HttpCache::HttpCache(HostResolver* host_resolver, http_auth_handler_factory, network_delegate, net_log))), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) + , stat_db_path_(NULL) { } @@ -408,6 +419,10 @@ HttpCache::~HttpCache() { if (delete_pending_op) delete pending_op; } + + if (NULL!=stat_db_path_) { + delete stat_db_path_; + } } int HttpCache::GetBackend(disk_cache::Backend** backend, @@ -518,7 +533,7 @@ int HttpCache::CreateBackend(disk_cache::Backend** backend, pending_op->callback = my_callback; int rv = backend_factory_->CreateBackend(net_log_, &pending_op->backend, - my_callback); + my_callback, &stat_db_path_ ); if (rv != ERR_IO_PENDING) { pending_op->writer->ClearCallback(); my_callback->Run(rv); @@ -1143,8 +1158,21 @@ void HttpCache::OnBackendCreated(int result, PendingOp* pending_op) { } // The cache may be gone when we return from the callback. - if (!item->DoCallback(result, backend)) + if (!item->DoCallback(result, backend)) { item->NotifyTransaction(result, NULL); + if (NULL!=stat_db_path_) { + if(!stat_hub::StatHub::GetInstance()->IsReady()) { + stat_hub::StatProcessor* hp = StatHubCreateHostResPlugin(); + if (NULL!=hp) { + stat_hub::StatHub::GetInstance()->RegisterProcessor(hp); + LOG(INFO) << "HttpCache::OnBackendCreated HostStat created"; + } + if(stat_hub::StatHub::GetInstance()->Init(stat_db_path_->value(), MessageLoop::current(), this)) { + LOG(INFO) << "HttpCache::OnBackendCreated : StatHub is ready."; + } + } + } + } } } // namespace net diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 0c2dc35..2ff5eff 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -1,4 +1,6 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2011, Code Aurora Forum. All rights reserved + // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -88,7 +90,8 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // |callback| because the object can be deleted from within the callback. virtual int CreateBackend(NetLog* net_log, disk_cache::Backend** backend, - CompletionCallback* callback) = 0; + CompletionCallback* callback, + FilePath** stat_db_path) = 0; }; // A default backend factory for the common use cases. @@ -107,7 +110,8 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // BackendFactory implementation. virtual int CreateBackend(NetLog* net_log, disk_cache::Backend** backend, - CompletionCallback* callback); + CompletionCallback* callback, + FilePath** stat_db_path); private: CacheType type_; @@ -378,6 +382,8 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, scoped_ptr<PlaybackCacheMap> playback_cache_map_; + FilePath* stat_db_path_; + DISALLOW_COPY_AND_ASSIGN(HttpCache); }; diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index a12a64f..3fef3a7 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2011, 2012 Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,6 +35,8 @@ #include "net/http/http_transaction.h" #include "net/http/http_util.h" #include "net/http/partial_data.h" +#include "net/http/preconnect.h" +#include "net/http/net-plugin-bridge.h" using base::Time; @@ -1643,13 +1646,17 @@ bool HttpCache::Transaction::RequiresValidation() { return true; if (response_.headers->RequiresValidation( - response_.request_time, response_.response_time, Time::Now())) + response_.request_time, response_.response_time, Time::Now())) { + ObserveRevalidation(&response_, request_, cache_); return true; + } // Since Vary header computation is fairly expensive, we save it for last. if (response_.vary_data.is_valid() && - !response_.vary_data.MatchesRequest(*request_, *response_.headers)) + !response_.vary_data.MatchesRequest(*request_, *response_.headers)) { + ObserveRevalidation(&response_, request_, cache_); return true; + } return false; } diff --git a/net/http/http_getzip_bridge.cc b/net/http/http_getzip_bridge.cc new file mode 100644 index 0000000..9395c1e --- /dev/null +++ b/net/http/http_getzip_bridge.cc @@ -0,0 +1,142 @@ +/** + * Copyright (c) 2012, Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other *materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + **/ + +#include "net/http/http_getzip_bridge.h" +#include "net/http/http_request_headers.h" +#include "net/http/http_response_headers.h" + +namespace net +{ + +void GetNextHttpRequestHeader( void*& it) +{ + if (NULL == it)return; + + HttpRequestHeaders::Iterator* myIt = + (static_cast<HttpRequestHeaders::Iterator*> (it)); + + if (!myIt->GetNext()) + { + delete myIt; + it = NULL; + } +} + +void GetFirstHttpRequestHeader( + net::HttpRequestHeaders& req, void*& it) +{ + //create a new Iterator for the req + it = new net::HttpRequestHeaders::Iterator(req); + return GetNextHttpRequestHeader( it ); +} + +const std::string& GetHttpRequestHeaderName( void*& it ) +{ + net::HttpRequestHeaders::Iterator* myIt = + (static_cast<net::HttpRequestHeaders::Iterator*> (it)); + return myIt->name(); +} + +const std::string& GetHttpRequestHeaderValue( void*& it ) +{ + net::HttpRequestHeaders::Iterator* myIt = + (static_cast<net::HttpRequestHeaders::Iterator*> (it)); + return myIt->value(); +} + +bool GetHttpRequestHeaderByValue( + net::HttpRequestHeaders& req, + const std::string& headerName, + std::string* headerValue) +{ + return req.GetHeader(headerName, headerValue); +} + +void SetHttpRequestHeader(net::HttpRequestHeaders& req, + const std::string& headerName, const std::string& value) +{ + req.SetHeader(headerName, value); +} + +void RemoveHttpRequestHeader(net::HttpRequestHeaders& req, + const std::string& headerName) +{ + req.RemoveHeader(headerName); +} + +void RemoveHttpResponseHeader(net::HttpResponseHeaders* res, + const std::string& headerName) +{ + if (NULL == res) + return; + + res->RemoveHeader(headerName); +} + +std::string GetHttpResponseHeaderValue(net::HttpResponseHeaders* res, + const std::string& headerName) +{ + if (NULL == res) + return ""; + std::string value; + + void* iter = NULL; + std::string temp; + while (res->EnumerateHeader(&iter, headerName, &temp)) { + + value.append(temp); + value.append(", "); + } + if(value.size() > 2) + { + value.erase(value.size() - 2); + } + + return value; +} + +int GetHttpResponseCode(net::HttpResponseHeaders* res) +{ + if(NULL == res) return -1; + + return res->response_code(); +} + +bool HasHttpResponseHeader(net::HttpResponseHeaders* res, + const std::string& headerName) +{ + if(NULL == res) return false; + + return res->HasHeader(headerName); +} + +void initBridge(){ } + +}; //end net + diff --git a/net/http/http_getzip_bridge.h b/net/http/http_getzip_bridge.h new file mode 100644 index 0000000..c545b89 --- /dev/null +++ b/net/http/http_getzip_bridge.h @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2012, Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other *materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + **/ + +#ifndef HTTP_GETZIP_BRIDGE_H_ +#define HTTP_GETZIP_BRIDGE_H_ + + +#include <string> +#include "net/http/http_request_headers.h" +#include "net/http/http_response_headers.h" + +#define EXPORT __attribute__((visibility("default"), used)) + +namespace net +{ + //HttpRequestHeader method delegates + //@argument it - should be initialized to NULL + extern void GetFirstHttpRequestHeader(net::HttpRequestHeaders& req, void*& it) EXPORT; + extern const std::string& GetHttpRequestHeaderName( void*& it ) EXPORT; + extern const std::string& GetHttpRequestHeaderValue( void*& it ) EXPORT; + bool GetHttpRequestHeaderByValue( net::HttpRequestHeaders& req, + const std::string& headerName, + std::string* headerValue) EXPORT; + extern void GetNextHttpRequestHeader( void*& it ) EXPORT; + + extern void SetHttpRequestHeader(net::HttpRequestHeaders& req, const std::string& headerName, + const std::string& value) EXPORT; + extern void RemoveHttpRequestHeader(net::HttpRequestHeaders& req, const std::string& headerName) EXPORT; + + ////HttpResponseHeader method delegates + extern void RemoveHttpResponseHeader(net::HttpResponseHeaders* res, const std::string& headerName) EXPORT; + extern std::string GetHttpResponseHeaderValue(net::HttpResponseHeaders* res, const std::string& headerName) EXPORT; + extern int GetHttpResponseCode(net::HttpResponseHeaders* res) EXPORT; + extern bool HasHttpResponseHeader(net::HttpResponseHeaders* res, const std::string& headerName) EXPORT; + + extern void initBridge(); +}; + + +#endif /* HTTP_GETZIP_BRIDGE_H_ */ diff --git a/net/http/http_getzip_factory.cc b/net/http/http_getzip_factory.cc new file mode 100644 index 0000000..02948d8 --- /dev/null +++ b/net/http/http_getzip_factory.cc @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2012, Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other *materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + **/ + +#include "net/http/http_getzip_factory.h" +#include "net/socket/client_socket.h" +#include <cutils/log.h> +#include <dlfcn.h> + +namespace net +{ + +HttpGetZipFactory* HttpGetZipFactory::s_pFactory = NULL; + +typedef IGetZipManager* mngr_create_(); + +HttpGetZipFactory::HttpGetZipFactory() : + m_pMngr(NULL), libHandle(NULL) +{ +} + +HttpGetZipFactory::~HttpGetZipFactory() +{ + delete m_pMngr; + m_pMngr = NULL; + + if (NULL != libHandle) + { + ::dlclose(libHandle); + libHandle = NULL; + } +} + +void HttpGetZipFactory::InitGETZipManager() +{ + if (NULL != s_pFactory) + return; + + s_pFactory = new HttpGetZipFactory(); + + s_pFactory->libHandle = ::dlopen("libgetzip.so", RTLD_NOW); + + if (s_pFactory->libHandle) + { + SLOGD("%s: libgetzip.so successfully loaded", __FILE__); + dlerror(); + mngr_create_* mngrCreate = (mngr_create_*) dlsym(s_pFactory->libHandle, + "createGETZipManager"); + + if (mngrCreate) + { + SLOGD("%s,: GETzip initializing method was found in libgetzip.so", + __FILE__); + s_pFactory->m_pMngr = (IGetZipManager*) mngrCreate(); + if( NULL == s_pFactory->m_pMngr) + { + s_pFactory->m_pMngr = new GetZipManager(); + } + return; + } + SLOGD("netstack: Failed to find createGETZipManager sybmol in libgetzip.so"); + ::dlclose(s_pFactory->libHandle); + s_pFactory->libHandle = NULL; + s_pFactory->m_pMngr = new GetZipManager(); + return; + } + + SLOGD("%s: Failed to construct GETzip manager, didn't find the library!", + __FILE__); + s_pFactory->m_pMngr = new GetZipManager(); +} + +IGetZipManager* HttpGetZipFactory::GetGETZipManager() +{ + return s_pFactory->m_pMngr; +} + +void HttpGetZipFactory::StopGETZipManager() +{ + if (libHandle == NULL) + return; + + delete m_pMngr; + m_pMngr = new GetZipManager(); + ::dlclose(libHandle); + libHandle = NULL; +} + +IGetZipManager::IGetZipManager() +{ +} + +IGetZipManager::~IGetZipManager() +{ +} + +GetZipManager::GetZipManager() +{ +} + +} +; //end network diff --git a/net/http/http_getzip_factory.h b/net/http/http_getzip_factory.h new file mode 100644 index 0000000..f7cced0 --- /dev/null +++ b/net/http/http_getzip_factory.h @@ -0,0 +1,137 @@ +/** + * Copyright (c) 2012, Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other *materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + **/ + +#ifndef HTTP_GETZIP_FACTORY_H_ +#define HTTP_GETZIP_FACTORY_H_ + +#include "net/socket/client_socket.h" +#include <sys/types.h> +#include "base/basictypes.h" + +namespace net +{ + +//forward declarations +class HttpRequestHeaders; +class HttpResponseHeaders; + +typedef enum +{ + GETZIP_OK = 1, + REQUEST_RETRY_NEEDED = 2, //GETzip failure that requires last request retry + NULL_ARGUMENT = 3, //One of the passed argument was NULL + NO_GETZIP_CONNECTION = 4 //No GETzip connection was found +} GETZipDecompressionStatus; + +//Main GetZip interface +class IGetZipManager +{ +public: + IGetZipManager(); + virtual void CompressRequestHeaders(HttpRequestHeaders&, ClientSocket*) = 0; + virtual GETZipDecompressionStatus + DecompressResponseHeaders(HttpResponseHeaders*, ClientSocket*) = 0; + virtual void StopGetZipConnection(ClientSocket*) = 0; + virtual void OpenGetZipConnection(ClientSocket*) = 0; + virtual ~IGetZipManager() = 0; + +private: + DISALLOW_COPY_AND_ASSIGN(IGetZipManager); +}; + +//Simple, non private GetZip manager implementation +class GetZipManager: public IGetZipManager +{ +public: + + GetZipManager(); + virtual ~GetZipManager() + { + } + ; + + virtual void CompressRequestHeaders(HttpRequestHeaders&, ClientSocket*) + { + } + ; + virtual GETZipDecompressionStatus DecompressResponseHeaders(HttpResponseHeaders*, ClientSocket*) + { + return NO_GETZIP_CONNECTION; + } + ; + virtual void StopGetZipConnection(ClientSocket*) + { + } + ; + virtual void OpenGetZipConnection(ClientSocket*) + { + } + ; + +private: + DISALLOW_COPY_AND_ASSIGN(GetZipManager); +}; + +//This class is used to initialize GetZip manager +//First tries to initialize GetZipManager from proprietary library, +//if the library does not exist, creates GetZipManager +//Note: In the current implementation of network stack all the actions +//related to GetZipManager and GetZipFactory are carried out via IOThread +//hence, the implementation is not synchronized (this might change in the future). +class HttpGetZipFactory +{ + +public: + + //GetZipManager is kept within HttpGetZipFactory, + //which is singleton. + //This method is used to access the GetZipManager + //Don't use it before initializing HttpGetZipFactory object. + static IGetZipManager* GetGETZipManager(); + + //Initialization must be called before accessing + //GetZipManager for the first time. + static void InitGETZipManager(); + + void StopGETZipManager(); + +private: + IGetZipManager* m_pMngr; + static HttpGetZipFactory* s_pFactory; + + void* libHandle; + + HttpGetZipFactory(); + ~HttpGetZipFactory(); + + DISALLOW_COPY_AND_ASSIGN(HttpGetZipFactory); +}; + +}; //end network +#endif /* HTTP_GETZIP_FACTORY_H_ */ diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index 8253eac..5e212b2 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +11,7 @@ #include "base/string_util.h" #include "net/http/http_network_session.h" #include "net/http/http_network_transaction.h" +#include "net/http/http_getzip_factory.h" #include "net/spdy/spdy_framer.h" #include "net/spdy/spdy_session.h" #include "net/spdy/spdy_session_pool.h" @@ -21,6 +23,7 @@ HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) : session_(session), suspended_(false) { DCHECK(session_.get()); + HttpGetZipFactory::InitGETZipManager(); } HttpNetworkLayer::~HttpNetworkLayer() { diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index d13ec97..d36f22a 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2011, 2012 Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -39,7 +40,8 @@ HttpNetworkSession::HttpNetworkSession(const Params& params) params.dns_cert_checker, params.ssl_host_info_factory, params.proxy_service, - params.ssl_config_service), + params.ssl_config_service, + this), spdy_session_pool_(params.host_resolver, params.ssl_config_service), ALLOW_THIS_IN_INITIALIZER_LIST(http_stream_factory_( new HttpStreamFactoryImpl(this))) { diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 7f0ac4f..7ef80f7 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2011, 2012 Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -54,6 +55,7 @@ #include "net/spdy/spdy_http_stream.h" #include "net/spdy/spdy_session.h" #include "net/spdy/spdy_session_pool.h" +#include <cutils/log.h> using base::Time; @@ -245,8 +247,17 @@ int HttpNetworkTransaction::RestartWithAuth( void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) { DCHECK(HaveAuth(target)); - DCHECK(!stream_request_.get()); + PrepareForRetry(true); +} + +void HttpNetworkTransaction::PrepareForGetZipRetry() +{ + PrepareForRetry(false); +} +void HttpNetworkTransaction::PrepareForRetry(bool isForAuthentication) +{ + DCHECK(!stream_request_.get()); bool keep_alive = false; // Even if the server says the connection is keep-alive, we have to be // able to find the end of each response in order to reuse the connection. @@ -254,8 +265,10 @@ void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) { stream_->CanFindEndOfResponse()) { // If the response body hasn't been completely read, we need to drain // it first. + // goes to drain body first!!! if (!stream_->IsResponseBodyComplete()) { - next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; + next_state_ = isForAuthentication ? STATE_DRAIN_BODY_FOR_AUTH_RESTART: + STATE_DRAIN_BODY_FOR_GETZIP_RETRY; read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket. read_buf_len_ = kDrainBodyBufferSize; return; @@ -265,35 +278,58 @@ void HttpNetworkTransaction::PrepareForAuthRestart(HttpAuth::Target target) { // We don't need to drain the response body, so we act as if we had drained // the response body. - DidDrainBodyForAuthRestart(keep_alive); + isForAuthentication ? + DidDrainBodyForAuthRestart(keep_alive): + DidDrainBodyForGetZipRetry(keep_alive); } -void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { - DCHECK(!stream_request_.get()); +void HttpNetworkTransaction::DidDrainBodyForAuthRestart( bool keep_alive ) + { - if (stream_.get()) { + DidDrainBodyForRetry( keep_alive ); + // Reset the other member variables. + ResetStateForAuthRestart(); + } + +void HttpNetworkTransaction::DidDrainBodyForGetZipRetry( bool keep_alive ) +{ + DidDrainBodyForRetry( keep_alive ); + read_buf_ = NULL; + read_buf_len_ = 0; + headers_valid_ = false; + request_headers_.Clear(); + response_ = HttpResponseInfo(); +} + +void HttpNetworkTransaction::DidDrainBodyForRetry( bool keep_alive ) +{ + DCHECK( !stream_request_.get() ); + + if ( stream_.get() ) + { HttpStream* new_stream = NULL; - if (keep_alive && stream_->IsConnectionReusable()) { + if ( keep_alive && stream_->IsConnectionReusable() ) + { // We should call connection_->set_idle_time(), but this doesn't occur // often enough to be worth the trouble. stream_->SetConnectionReused(); new_stream = stream_->RenewStreamForAuth(); } - if (!new_stream) { + if ( !new_stream ) + { // Close the stream and mark it as not_reusable. Even in the // keep_alive case, we've determined that the stream_ is not // reusable if new_stream is NULL. - stream_->Close(true); + stream_->Close( true ); next_state_ = STATE_CREATE_STREAM; - } else { + } + else + { next_state_ = STATE_INIT_STREAM; } - stream_.reset(new_stream); + stream_.reset( new_stream ); } - - // Reset the other member variables. - ResetStateForAuthRestart(); } bool HttpNetworkTransaction::IsReadyToRestartForAuth() { @@ -559,6 +595,13 @@ int HttpNetworkTransaction::DoLoop(int result) { net_log_.EndEventWithNetErrorCode( NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, rv); break; + case STATE_DRAIN_BODY_FOR_GETZIP_RETRY: + DCHECK_EQ(OK, rv); + rv = DoDrainBodyForGetZipRetry(); + break; + case STATE_DRAIN_BODY_FOR_GETZIP_RETRY_COMPLETE: + rv = DoDrainBodyForGetZipRetryComplete(rv); + break; case STATE_DRAIN_BODY_FOR_AUTH_RESTART: DCHECK_EQ(OK, rv); net_log_.BeginEvent( @@ -963,9 +1006,28 @@ int HttpNetworkTransaction::DoDrainBodyForAuthRestart() { return rv; } +int HttpNetworkTransaction::DoDrainBodyForGetZipRetry() { + int rv = DoReadBody(); + DCHECK(next_state_ == STATE_READ_BODY_COMPLETE); + next_state_ = STATE_DRAIN_BODY_FOR_GETZIP_RETRY_COMPLETE; + return rv; +} + +int HttpNetworkTransaction::DoDrainBodyForGetZipRetryComplete(int result) { + DoDrainBodyForRetryComplete( result, false ); + return OK; +} + // TODO(wtc): This method and the DoReadBodyComplete method are almost // the same. Figure out a good way for these two methods to share code. int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { + DoDrainBodyForRetryComplete( result, true ); + return OK; +} + +void HttpNetworkTransaction::DoDrainBodyForRetryComplete( int result, + bool isForAuthentication ) +{ // keep_alive defaults to true because the very reason we're draining the // response body is to reuse the connection for auth restart. bool done = false, keep_alive = true; @@ -978,13 +1040,15 @@ int HttpNetworkTransaction::DoDrainBodyForAuthRestartComplete(int result) { } if (done) { - DidDrainBodyForAuthRestart(keep_alive); + isForAuthentication ? + DidDrainBodyForAuthRestart(keep_alive): + DidDrainBodyForGetZipRetry(keep_alive); } else { // Keep draining. - next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; + next_state_ = isForAuthentication ? + STATE_DRAIN_BODY_FOR_AUTH_RESTART : + STATE_DRAIN_BODY_FOR_GETZIP_RETRY ; } - - return OK; } void HttpNetworkTransaction::LogTransactionConnectedMetrics() { @@ -1190,8 +1254,12 @@ int HttpNetworkTransaction::HandleIOError(int error) { // cause SSL handshake errors to be delayed until the first or second Write // (Snap Start) or the first Read (False & Snap Start) on the underlying // connection. - error = HandleSSLHandshakeError(error); - + if(error != ERR_GETZIP) + error = HandleSSLHandshakeError(error); + else + { + SLOGD("%s:%s:: SHUTR protocol failure", __FILE__, __FUNCTION__); + } switch (error) { // If we try to reuse a connection that the server is in the process of // closing, we may end up successfully writing out our request (or a @@ -1209,6 +1277,10 @@ int HttpNetworkTransaction::HandleIOError(int error) { ResetConnectionAndRequestForResend(); error = OK; break; + case ERR_GETZIP: + PrepareForGetZipRetry(); + error = OK; + break; } return error; } @@ -1338,6 +1410,8 @@ std::string HttpNetworkTransaction::DescribeState(State state) { STATE_CASE(STATE_READ_HEADERS_COMPLETE); STATE_CASE(STATE_READ_BODY); STATE_CASE(STATE_READ_BODY_COMPLETE); + STATE_CASE(STATE_DRAIN_BODY_FOR_GETZIP_RETRY); + STATE_CASE(STATE_DRAIN_BODY_FOR_GETZIP_RETRY_COMPLETE); STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); STATE_CASE(STATE_NONE); diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h index 00e9a65..7abfcf9 100644 --- a/net/http/http_network_transaction.h +++ b/net/http/http_network_transaction.h @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -102,6 +103,8 @@ class HttpNetworkTransaction : public HttpTransaction, STATE_READ_HEADERS_COMPLETE, STATE_READ_BODY, STATE_READ_BODY_COMPLETE, + STATE_DRAIN_BODY_FOR_GETZIP_RETRY, + STATE_DRAIN_BODY_FOR_GETZIP_RETRY_COMPLETE, STATE_DRAIN_BODY_FOR_AUTH_RESTART, STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, STATE_NONE @@ -137,6 +140,9 @@ class HttpNetworkTransaction : public HttpTransaction, int DoReadBodyComplete(int result); int DoDrainBodyForAuthRestart(); int DoDrainBodyForAuthRestartComplete(int result); + int DoDrainBodyForGetZipRetry(); + int DoDrainBodyForGetZipRetryComplete(int result); + void DoDrainBodyForRetryComplete( int result, bool isForAuthentication ); void BuildRequestHeaders(bool using_proxy); @@ -182,10 +188,28 @@ class HttpNetworkTransaction : public HttpTransaction, // Sets up the state machine to restart the transaction with auth. void PrepareForAuthRestart(HttpAuth::Target target); + // Sets up the state machine to restart the transaction if + // GETzip error occurred. + void PrepareForGetZipRetry(); + + // Sets up the state machine to restart the transaction. + void PrepareForRetry(bool isForAuthentication); + // Called when we don't need to drain the response body or have drained it. + // Clears request info for transaction restart for auth. + // Uses DidDrainBodyForRetry to reset connection if needed and to + // set next_state_ + void DidDrainBodyForAuthRestart(bool keep_alive); + + // Called when we don't need to drain the response body or have drained it. + // Clears request info for transaction retry caused by GETzip error. + // Uses DidDrainBodyForRetry to reset connection if needed and to + // set next_state_ + void DidDrainBodyForGetZipRetry(bool keep_alive); + // Resets |connection_| unless |keep_alive| is true, then calls // ResetStateForRestart. Sets |next_state_| appropriately. - void DidDrainBodyForAuthRestart(bool keep_alive); + void DidDrainBodyForRetry( bool keep_alive ); // Resets the members of the transaction so it can be restarted. void ResetStateForRestart(); diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc index c28d0e6..94a51e1 100644 --- a/net/http/http_proxy_client_socket_pool.cc +++ b/net/http/http_proxy_client_socket_pool.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2011, 2012 Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -425,7 +426,8 @@ HttpProxyClientSocketPool::HttpProxyClientSocketPool( HostResolver* host_resolver, TransportClientSocketPool* transport_pool, SSLClientSocketPool* ssl_pool, - NetLog* net_log) + NetLog* net_log, + HttpNetworkSession *network_session) : transport_pool_(transport_pool), ssl_pool_(ssl_pool), base_(max_sockets, max_sockets_per_group, histograms, @@ -435,7 +437,8 @@ HttpProxyClientSocketPool::HttpProxyClientSocketPool( new HttpProxyConnectJobFactory(transport_pool, ssl_pool, host_resolver, - net_log)) {} + net_log), + network_session) {} HttpProxyClientSocketPool::~HttpProxyClientSocketPool() {} diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h index 2ab331e..c539ede 100644 --- a/net/http/http_proxy_client_socket_pool.h +++ b/net/http/http_proxy_client_socket_pool.h @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -31,6 +32,7 @@ class SpdySessionPool; class SpdyStream; class TransportClientSocketPool; class TransportSocketParams; +class HttpNetworkSession; // HttpProxySocketParams only needs the socket params for one of the proxy // types. The other param must be NULL. When using an HTTP Proxy, @@ -179,7 +181,8 @@ class HttpProxyClientSocketPool : public ClientSocketPool { HostResolver* host_resolver, TransportClientSocketPool* transport_pool, SSLClientSocketPool* ssl_pool, - NetLog* net_log); + NetLog* net_log, + HttpNetworkSession *network_session); virtual ~HttpProxyClientSocketPool(); diff --git a/net/http/http_request_headers.cc b/net/http/http_request_headers.cc index 9d523c1..9cb3a83 100644 --- a/net/http/http_request_headers.cc +++ b/net/http/http_request_headers.cc @@ -1,4 +1,5 @@ // Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,6 +13,7 @@ namespace net { const char HttpRequestHeaders::kGetMethod[] = "GET"; +const char HttpRequestHeaders::kHeadMethod[] = "HEAD"; const char HttpRequestHeaders::kAcceptCharset[] = "Accept-Charset"; const char HttpRequestHeaders::kAcceptEncoding[] = "Accept-Encoding"; const char HttpRequestHeaders::kAcceptLanguage[] = "Accept-Language"; diff --git a/net/http/http_request_headers.h b/net/http/http_request_headers.h index d574ae4..e130ab1 100644 --- a/net/http/http_request_headers.h +++ b/net/http/http_request_headers.h @@ -1,4 +1,5 @@ // Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -55,6 +56,7 @@ class NET_EXPORT HttpRequestHeaders { }; static const char kGetMethod[]; + static const char kHeadMethod[]; static const char kAcceptCharset[]; static const char kAcceptEncoding[]; diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc index 0649bce..5d0d9ed 100644 --- a/net/http/http_stream_parser.cc +++ b/net/http/http_stream_parser.cc @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,13 +19,15 @@ #include "net/http/http_util.h" #include "net/socket/ssl_client_socket.h" #include "net/socket/client_socket_handle.h" +#include "net/http/http_getzip_factory.h" namespace net { HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, const HttpRequestInfo* request, GrowableIOBuffer* read_buffer, - const BoundNetLog& net_log) + const BoundNetLog& net_log, + bool using_proxy) : io_state_(STATE_NONE), request_(request), request_headers_(NULL), @@ -44,7 +47,10 @@ HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, io_callback_(this, &HttpStreamParser::OnIOComplete)), chunk_length_(0), chunk_length_without_encoding_(0), - sent_last_chunk_(false) { + sent_last_chunk_(false), + using_proxy_(using_proxy), + has_to_retry_(false){ + DCHECK_EQ(0, read_buffer->offset()); } @@ -62,7 +68,7 @@ int HttpStreamParser::SendRequest(const std::string& request_line, DCHECK(!user_callback_); DCHECK(callback); DCHECK(response); - + has_to_retry_ = false; if (net_log_.IsLoggingAllEvents()) { net_log_.AddEvent( NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, @@ -78,6 +84,15 @@ int HttpStreamParser::SendRequest(const std::string& request_line, return result; response_->socket_address = HostPortPair::FromAddrInfo(address.head()); + //Shutr only for GET/HEAD requests + if((!(using_proxy_)) && ((request_line.find(HttpRequestHeaders::kGetMethod) == 0) || + (request_line.find(HttpRequestHeaders::kHeadMethod) == 0))) + { + HttpGetZipFactory::GetGETZipManager()->CompressRequestHeaders( + const_cast<HttpRequestHeaders &>(headers), + connection_->socket()); + } + std::string request = request_line + headers.ToString(); scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); request_headers_ = new DrainableIOBuffer(headers_io_buf, @@ -161,6 +176,11 @@ void HttpStreamParser::OnIOComplete(int result) { if (result != ERR_IO_PENDING && user_callback_) { CompletionCallback* c = user_callback_; user_callback_ = NULL; + if(has_to_retry_ ) + { + result = ERR_GETZIP; + has_to_retry_ = false; + } c->Run(result); } } @@ -201,8 +221,19 @@ int HttpStreamParser::DoLoop(int result) { break; case STATE_READ_HEADERS_COMPLETE: result = DoReadHeadersComplete(result); + if(!using_proxy_) + { + GETZipDecompressionStatus st = + HttpGetZipFactory::GetGETZipManager()->DecompressResponseHeaders( + response_->headers.get(), + connection_->socket()); + if( st == REQUEST_RETRY_NEEDED ) + { + has_to_retry_ = true; + } + } net_log_.EndEventWithNetErrorCode( - NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS, result); + NetLog::TYPE_HTTP_STREAM_PARSER_READ_HEADERS, result); break; case STATE_BODY_PENDING: DCHECK(result != ERR_IO_PENDING); diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h index 2192eff..fa3e6fc 100644 --- a/net/http/http_stream_parser.h +++ b/net/http/http_stream_parser.h @@ -1,4 +1,5 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,7 +37,9 @@ class HttpStreamParser : public ChunkCallback { HttpStreamParser(ClientSocketHandle* connection, const HttpRequestInfo* request, GrowableIOBuffer* read_buffer, - const BoundNetLog& net_log); + const BoundNetLog& net_log, + bool using_proxy = false); + ~HttpStreamParser(); // These functions implement the interface described in HttpStream with @@ -186,6 +189,10 @@ class HttpStreamParser : public ChunkCallback { // The underlying socket. ClientSocketHandle* const connection_; + bool using_proxy_; + + bool has_to_retry_; + BoundNetLog net_log_; // Callback to be used when doing IO. diff --git a/net/http/net-plugin-bridge-exports.h b/net/http/net-plugin-bridge-exports.h new file mode 100644 index 0000000..773602a --- /dev/null +++ b/net/http/net-plugin-bridge-exports.h @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Code Aurora Forum, Inc. nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +// API for the network plug-in +#ifndef NET_HTTP_NET_PLUGIN_BRIDGE_EXPORTS_H_ +#define NET_HTTP_NET_PLUGIN_BRIDGE_EXPORTS_H_ + +// export these functions from libwebcore, may be used by the plug-in +extern bool HeadersIsRedirect(const net::HttpResponseHeaders* h, std::string& s) + __attribute__ ((visibility ("default"), used)); +extern GURL GurlResolveOrigin(const net::HttpRequestInfo* req, std::string& s) + __attribute__ ((visibility ("default"), used)); +extern GURL GurlOrigin(const net::HttpRequestInfo* req) + __attribute__ ((visibility ("default"), used)); +extern void NetPreconnect(net::HttpNetworkSession*, GURL const&) + __attribute__ ((visibility ("default"), used)); + +#endif /* NET_HTTP_NET_PLUGIN_BRIDGE_EXPORTS_H_ */ diff --git a/net/http/net-plugin-bridge.cc b/net/http/net-plugin-bridge.cc new file mode 100644 index 0000000..42019ca --- /dev/null +++ b/net/http/net-plugin-bridge.cc @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2011, 2012 Code Aurora Forum. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Code Aurora Forum, Inc. nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "net/http/http_cache_transaction.h" + +#include "build/build_config.h" + +#include <unistd.h> + +#include <string> + +#include "base/compiler_specific.h" +#include "net/http/http_response_headers.h" +#include "net/http/preconnect.h" + +#include "net/http/net-plugin-bridge.h" +#include "net/http/net-plugin-bridge-exports.h" +#include <dlfcn.h> +#include <cutils/log.h> + +static void (*DoObserveRevalidation)(const net::HttpResponseInfo* resp, + const net::HttpRequestInfo* req, net::HttpCache* cache) = NULL; + +static void InitOnce() { + static bool initialized = false; + if (!initialized) { + initialized = true; + void* fh = dlopen("qnet-plugin.so", RTLD_LAZY); + if (fh) { + const char *error; + + dlerror(); //see man dlopen + *(void **)(&DoObserveRevalidation) = dlsym(fh, "DoObserveRevalidation"); + if (NULL != (error = dlerror())) { + DoObserveRevalidation = NULL; + } + } + if (NULL == DoObserveRevalidation) { + SLOGD("Failed to load DoObserveRevalidation symbol in qnet-plugin.so"); + } + } +} + +void ObserveRevalidation(const net::HttpResponseInfo* resp, + const net::HttpRequestInfo* req, net::HttpCache* cache) { + InitOnce(); + if (DoObserveRevalidation) { + DoObserveRevalidation(resp, req, cache); + } +} + + +bool HeadersIsRedirect(const net::HttpResponseHeaders* headers, + std::string& location) { + return headers->IsRedirect(&location); +} + +GURL GurlResolveOrigin(const net::HttpRequestInfo* req, + std::string& location) { + return req->url.Resolve(location).GetOrigin(); +} + +GURL GurlOrigin(const net::HttpRequestInfo* req) { + return req->url.GetOrigin(); +} + +void NetPreconnect(net::HttpNetworkSession* session, GURL const& url) { + net::Preconnect::DoPreconnect(session, url); +} diff --git a/net/http/net-plugin-bridge.h b/net/http/net-plugin-bridge.h new file mode 100644 index 0000000..09f45e9 --- /dev/null +++ b/net/http/net-plugin-bridge.h @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2011, Code Aurora Forum. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* * Neither the name of Code Aurora Forum, Inc. nor the names of its +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef NET_HTTP_NET_PLUGIN_BRIDGE_H_ +#define NET_HTTP_NET_PLUGIN_BRIDGE_H_ + +// revalidated cache entries observer +extern void ObserveRevalidation(const net::HttpResponseInfo* resp, + const net::HttpRequestInfo* req, net::HttpCache* cache); + +#endif /* NET_HTTP_NET_PLUGIN_BRIDGE_H_ */ diff --git a/net/http/preconnect.cc b/net/http/preconnect.cc new file mode 100644 index 0000000..929b627 --- /dev/null +++ b/net/http/preconnect.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2012, Code Aurora Forum. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/http/preconnect.h" + +#include "base/logging.h" +#include "net/proxy/proxy_info.h" +#include "net/http/http_stream_factory.h" +#include "net/http/http_network_session.h" + +namespace net { + + +// static +void Preconnect::DoPreconnect(HttpNetworkSession* session, + const GURL& url, int count, + HttpRequestInfo::RequestMotivation motivation ) { + Preconnect* preconnect = new Preconnect(session); + preconnect->Connect(url, count, motivation); +} + +Preconnect::Preconnect(HttpNetworkSession* session) + : session_(session), + ALLOW_THIS_IN_INITIALIZER_LIST( + io_callback_(this, &Preconnect::OnPreconnectComplete)) {} + +Preconnect::~Preconnect() {} + +void Preconnect::Connect(const GURL& url, int count, + HttpRequestInfo::RequestMotivation motivation) { + + request_info_.reset(new HttpRequestInfo()); + request_info_->url = url; + request_info_->method = "GET"; + // It almost doesn't matter whether we use net::LOWEST or net::HIGHEST + // priority here, as we won't make a request, and will surrender the created + // socket to the pool as soon as we can. However, we would like to mark the + // speculative socket as such, and IF we use a net::LOWEST priority, and if + // a navigation asked for a socket (after us) then it would get our socket, + // and we'd get its later-arriving socket, which might make us record that + // the speculation didn't help :-/. By using net::HIGHEST, we ensure that + // a socket is given to us if "we asked first" and this allows us to mark it + // as speculative, and better detect stats (if it gets used). + // TODO(jar): histogram to see how often we accidentally use a previously- + // unused socket, when a previously used socket was available. + request_info_->priority = HIGHEST; + request_info_->motivation = motivation; + + // Setup the SSL Configuration. + ssl_config_.reset(new SSLConfig()); + session_->ssl_config_service()->GetSSLConfig(ssl_config_.get()); + if (session_->http_stream_factory()->next_protos()) + ssl_config_->next_protos = *session_->http_stream_factory()->next_protos(); + + // All preconnects should perform EV certificate verification. + ssl_config_->verify_ev_cert = true; + + proxy_info_.reset(new ProxyInfo()); + HttpStreamFactory* stream_factory = session_->http_stream_factory(); + stream_factory->PreconnectStreams(count, *(request_info_.get()), + *(ssl_config_.get()), net_log_); +} + +void Preconnect::OnPreconnectComplete(int error_code) { + delete this; +} + +} // namespace net diff --git a/net/http/preconnect.h b/net/http/preconnect.h new file mode 100644 index 0000000..e7e1914 --- /dev/null +++ b/net/http/preconnect.h @@ -0,0 +1,66 @@ +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// A Preconnect instance maintains state while a TCP/IP connection is made, and +// and then released into the pool of available connections for future use. + +#ifndef NET_HTTP_PRECONNECT_H__ +#define NET_HTTP_PRECONNECT_H__ +#pragma once + +#include "base/scoped_ptr.h" +#include "net/base/completion_callback.h" +#include "net/base/net_log.h" +#include "net/http/http_request_info.h" +#include "net/http/http_stream_factory.h" + +namespace net { + +class ProxyInfo; +struct SSLConfig; + +class Preconnect { + public: + // Try to preconnect. Typically used by predictor when a subresource probably + // needs a connection. |count| may be used to request more than one connection + // be established in parallel. + static void DoPreconnect(HttpNetworkSession* session, const GURL& url, + int count = 1, HttpRequestInfo::RequestMotivation motivation = + HttpRequestInfo::PRECONNECT_MOTIVATED); + + private: + explicit Preconnect(HttpNetworkSession* session); + virtual ~Preconnect(); + + void OnPreconnectComplete(int error_code); + + // Request actual connection, via interface that tags request as needed for + // preconnect only (so that they can be merged with connections needed for + // navigations). + void Connect(const GURL& url, int count, + HttpRequestInfo::RequestMotivation motivation); + + HttpNetworkSession * session_; + // HttpRequestInfo used for connecting. + scoped_ptr<HttpRequestInfo> request_info_; + + // SSLConfig used for connecting. + scoped_ptr<SSLConfig> ssl_config_; + + // ProxyInfo used for connecting. + scoped_ptr<ProxyInfo> proxy_info_; + + // A net log to use for this preconnect. + BoundNetLog net_log_; + + // Our preconnect. + scoped_ptr<HttpStreamRequest> stream_request_; + + CompletionCallbackImpl<Preconnect> io_callback_; + + DISALLOW_COPY_AND_ASSIGN(Preconnect); +}; +} // namespace net +#endif // NET_HTTP_HTTP_REQUEST_INFO_H__ + diff --git a/net/http/tcp-connections-bridge-exports.h b/net/http/tcp-connections-bridge-exports.h new file mode 100644 index 0000000..3d873cd --- /dev/null +++ b/net/http/tcp-connections-bridge-exports.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011, Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// API for the network plug-in +#ifndef NET_HTTP_TCP_CONNECTIONS_BRIDGE_EXPORTS_H_ +#define NET_HTTP_TCP_CONNECTIONS_BRIDGE_EXPORTS_H_ + +// export these functions from libwebcore, may be used by the plug-in +extern void NetPreconnect(net::HttpNetworkSession*, GURL const&, int numOfConnections) + __attribute__ ((visibility ("default"), used)); + +#endif /* NET_HTTP_NET_PLUGIN_BRIDGE_EXPORTS_H_ */ diff --git a/net/http/tcp-connections-bridge.cc b/net/http/tcp-connections-bridge.cc new file mode 100644 index 0000000..3201b3d --- /dev/null +++ b/net/http/tcp-connections-bridge.cc @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2011, 2012 Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "build/build_config.h" + +#include <unistd.h> + +#include <string> + +#include "base/compiler_specific.h" +#include "net/http/http_response_headers.h" +#include "net/http/preconnect.h" + +#include "net/http/tcp-connections-bridge.h" +#include "net/http/tcp-connections-bridge-exports.h" +#include "net/http/http_network_session.h" +#include <dlfcn.h> +#include <cutils/log.h> + +static void (*DoObserveConnections)( + net::HttpNetworkSession* session, + const GURL& url) = NULL; + +static void InitOnce() { + static bool initialized = false; + if (!initialized) { + initialized = true; + void* fh = dlopen("tcp-connections.so", RTLD_LAZY); + if (fh) { + dlerror(); //see man dlopen + *(void **)(&DoObserveConnections) = dlsym(fh, "DoObserveConnections"); + } + if (NULL == DoObserveConnections) { + SLOGD("Failed to load DoObserveConnections symbol in tcp-connections.so"); + } + } +} + +void ObserveConnections( + net::HttpNetworkSession *session, + const GURL& url +) +{ + InitOnce(); + if (DoObserveConnections) { + DoObserveConnections(session, url); + } +} + +void NetPreconnect(net::HttpNetworkSession* session, GURL const& url, int numOfConnections) { + net::Preconnect::DoPreconnect(session, url, numOfConnections); +} diff --git a/net/http/tcp-connections-bridge.h b/net/http/tcp-connections-bridge.h new file mode 100644 index 0000000..94f5501 --- /dev/null +++ b/net/http/tcp-connections-bridge.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011, Code Aurora Forum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Code Aurora Forum, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef NET_HTTP_TCP_CONNECTIONS_BRIDGE_H_ +#define NET_HTTP_TCP_CONNECTIONS_BRIDGE_H_ + +// revalidated cache entries observer +extern void ObserveConnections +( + net::HttpNetworkSession *session, + const GURL& url +); + +#endif /* NET_HTTP_NET_PLUGIN_BRIDGE_H_ */ |