blob: 0704de420de32d29349e8e6d50f311387a362db3 [file] [log] [blame]
[email protected]1ad77dc2012-01-27 03:51:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
5#include "net/http/http_network_layer.h"
6
[email protected]0dfc81b2008-08-25 03:44:407#include "base/logging.h"
[email protected]0c55b3282013-11-27 04:18:118#include "base/power_monitor/power_monitor.h"
[email protected]125ef482013-06-11 18:32:479#include "base/strings/string_number_conversions.h"
[email protected]d778e0422013-03-06 18:10:2210#include "base/strings/string_split.h"
[email protected]125ef482013-06-11 18:32:4711#include "base/strings/string_util.h"
initial.commit586acc5fe2008-07-26 22:42:5212#include "net/http/http_network_session.h"
13#include "net/http/http_network_transaction.h"
[email protected]17291a022011-10-10 07:32:5314#include "net/http/http_server_properties_impl.h"
[email protected]f1e97e92012-12-16 04:53:2515#include "net/http/http_stream_factory_impl_job.h"
[email protected]dab9c7d2010-02-06 21:44:3216#include "net/spdy/spdy_framer.h"
[email protected]dab9c7d2010-02-06 21:44:3217#include "net/spdy/spdy_session.h"
[email protected]ea1cc2cd2011-02-22 16:47:3818#include "net/spdy/spdy_session_pool.h"
initial.commit586acc5fe2008-07-26 22:42:5219
20namespace net {
21
22//-----------------------------------------------------------------------------
[email protected]e7f29642009-03-02 22:53:1823HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
[email protected]57cb0f72011-01-28 06:33:5824 : session_(session),
[email protected]c6894572009-06-16 17:10:1025 suspended_(false) {
[email protected]e7f29642009-03-02 22:53:1826 DCHECK(session_.get());
[email protected]0c55b3282013-11-27 04:18:1127#if defined(OS_WIN)
[email protected]ed3bf8a62014-04-05 18:55:5728 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
29 if (power_monitor)
30 power_monitor->AddObserver(this);
[email protected]0c55b3282013-11-27 04:18:1131#endif
[email protected]e7f29642009-03-02 22:53:1832}
33
initial.commit586acc5fe2008-07-26 22:42:5234HttpNetworkLayer::~HttpNetworkLayer() {
[email protected]0c55b3282013-11-27 04:18:1135#if defined(OS_WIN)
[email protected]ed3bf8a62014-04-05 18:55:5736 base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
37 if (power_monitor)
38 power_monitor->RemoveObserver(this);
[email protected]0c55b3282013-11-27 04:18:1139#endif
initial.commit586acc5fe2008-07-26 22:42:5240}
41
[email protected]d100e44f2011-01-26 22:47:1142//-----------------------------------------------------------------------------
initial.commit586acc5fe2008-07-26 22:42:5243
[email protected]d100e44f2011-01-26 22:47:1144// static
45HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
[email protected]d100e44f2011-01-26 22:47:1146 HttpNetworkSession* session) {
47 DCHECK(session);
initial.commit586acc5fe2008-07-26 22:42:5248
[email protected]d100e44f2011-01-26 22:47:1149 return new HttpNetworkLayer(session);
[email protected]e7f29642009-03-02 22:53:1850}
51
[email protected]7adaccb2009-10-13 04:43:2152// static
[email protected]443a30ed2012-11-30 02:56:4653void HttpNetworkLayer::ForceAlternateProtocol() {
54 PortAlternateProtocolPair pair;
55 pair.port = 443;
[email protected]b05bcaa32013-10-06 05:26:0256 pair.protocol = NPN_SPDY_3;
[email protected]443a30ed2012-11-30 02:56:4657 HttpServerPropertiesImpl::ForceAlternateProtocol(pair);
[email protected]7adaccb2009-10-13 04:43:2158}
[email protected]d100e44f2011-01-26 22:47:1159
60//-----------------------------------------------------------------------------
61
[email protected]262eec82013-03-19 21:01:3662int HttpNetworkLayer::CreateTransaction(RequestPriority priority,
[email protected]027bd85a2013-12-27 22:39:1063 scoped_ptr<HttpTransaction>* trans) {
[email protected]d100e44f2011-01-26 22:47:1164 if (suspended_)
65 return ERR_NETWORK_IO_SUSPENDED;
66
[email protected]262eec82013-03-19 21:01:3667 trans->reset(new HttpNetworkTransaction(priority, GetSession()));
[email protected]d100e44f2011-01-26 22:47:1168 return OK;
69}
70
71HttpCache* HttpNetworkLayer::GetCache() {
72 return NULL;
73}
74
[email protected]90499482013-06-01 00:39:5075HttpNetworkSession* HttpNetworkLayer::GetSession() { return session_.get(); }
[email protected]d100e44f2011-01-26 22:47:1176
[email protected]8523ba52011-05-22 19:00:5877void HttpNetworkLayer::OnSuspend() {
78 suspended_ = true;
[email protected]d100e44f2011-01-26 22:47:1179
[email protected]90499482013-06-01 00:39:5080 if (session_.get())
[email protected]102e27c2011-02-23 01:01:3181 session_->CloseIdleConnections();
[email protected]d100e44f2011-01-26 22:47:1182}
83
[email protected]8523ba52011-05-22 19:00:5884void HttpNetworkLayer::OnResume() {
85 suspended_ = false;
86}
87
initial.commit586acc5fe2008-07-26 22:42:5288} // namespace net