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_network_layer.h"
6
7#include "base/logging.h"
8#include "base/strings/string_number_conversions.h"
9#include "base/strings/string_split.h"
10#include "base/strings/string_util.h"
11#include "net/http/http_network_session.h"
12#include "net/http/http_network_transaction.h"
13#include "net/http/http_server_properties_impl.h"
14#include "net/http/http_stream_factory_impl_job.h"
15#include "net/spdy/spdy_framer.h"
16#include "net/spdy/spdy_session.h"
17#include "net/spdy/spdy_session_pool.h"
18
19namespace net {
20
21//-----------------------------------------------------------------------------
22HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
23    : session_(session),
24      suspended_(false) {
25  DCHECK(session_.get());
26}
27
28HttpNetworkLayer::~HttpNetworkLayer() {
29}
30
31//-----------------------------------------------------------------------------
32
33// static
34HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
35    HttpNetworkSession* session) {
36  DCHECK(session);
37
38  return new HttpNetworkLayer(session);
39}
40
41// static
42void HttpNetworkLayer::ForceAlternateProtocol() {
43  PortAlternateProtocolPair pair;
44  pair.port = 443;
45  pair.protocol = NPN_SPDY_2;
46  HttpServerPropertiesImpl::ForceAlternateProtocol(pair);
47}
48
49//-----------------------------------------------------------------------------
50
51int HttpNetworkLayer::CreateTransaction(RequestPriority priority,
52                                        scoped_ptr<HttpTransaction>* trans,
53                                        HttpTransactionDelegate* delegate) {
54  if (suspended_)
55    return ERR_NETWORK_IO_SUSPENDED;
56
57  trans->reset(new HttpNetworkTransaction(priority, GetSession()));
58  return OK;
59}
60
61HttpCache* HttpNetworkLayer::GetCache() {
62  return NULL;
63}
64
65HttpNetworkSession* HttpNetworkLayer::GetSession() { return session_.get(); }
66
67void HttpNetworkLayer::OnSuspend() {
68  suspended_ = true;
69
70  if (session_.get())
71    session_->CloseIdleConnections();
72}
73
74void HttpNetworkLayer::OnResume() {
75  suspended_ = false;
76}
77
78}  // namespace net
79