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