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