OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_network_layer.h" | 5 #include "net/http/http_network_layer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/power_monitor/power_monitor.h" | 8 #include "base/power_monitor/power_monitor.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
13 #include "net/http/http_network_transaction.h" | 13 #include "net/http/http_network_transaction.h" |
14 #include "net/http/http_server_properties_impl.h" | 14 #include "net/http/http_server_properties_impl.h" |
15 #include "net/http/http_stream_factory_impl_job.h" | 15 #include "net/http/http_stream_factory_impl_job.h" |
16 #include "net/spdy/spdy_framer.h" | 16 #include "net/spdy/spdy_framer.h" |
17 #include "net/spdy/spdy_session.h" | 17 #include "net/spdy/spdy_session.h" |
18 #include "net/spdy/spdy_session_pool.h" | 18 #include "net/spdy/spdy_session_pool.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) | 22 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
23 : session_(session), | 23 : session_(session), |
24 suspended_(false) { | 24 suspended_(false) { |
25 DCHECK(session_); | 25 DCHECK(session_.get()); |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 27 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
28 if (power_monitor) | 28 if (power_monitor) |
29 power_monitor->AddObserver(this); | 29 power_monitor->AddObserver(this); |
30 #endif | 30 #endif |
31 } | 31 } |
32 | 32 |
33 HttpNetworkLayer::~HttpNetworkLayer() { | 33 HttpNetworkLayer::~HttpNetworkLayer() { |
34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
35 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 35 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
36 if (power_monitor) | 36 if (power_monitor) |
37 power_monitor->RemoveObserver(this); | 37 power_monitor->RemoveObserver(this); |
38 #endif | 38 #endif |
39 } | 39 } |
40 | 40 |
| 41 // static |
| 42 HttpTransactionFactory* HttpNetworkLayer::CreateFactory( |
| 43 HttpNetworkSession* session) { |
| 44 DCHECK(session); |
| 45 |
| 46 return new HttpNetworkLayer(session); |
| 47 } |
| 48 |
41 int HttpNetworkLayer::CreateTransaction(RequestPriority priority, | 49 int HttpNetworkLayer::CreateTransaction(RequestPriority priority, |
42 scoped_ptr<HttpTransaction>* trans) { | 50 scoped_ptr<HttpTransaction>* trans) { |
43 if (suspended_) | 51 if (suspended_) |
44 return ERR_NETWORK_IO_SUSPENDED; | 52 return ERR_NETWORK_IO_SUSPENDED; |
45 | 53 |
46 trans->reset(new HttpNetworkTransaction(priority, GetSession())); | 54 trans->reset(new HttpNetworkTransaction(priority, GetSession())); |
47 return OK; | 55 return OK; |
48 } | 56 } |
49 | 57 |
50 HttpCache* HttpNetworkLayer::GetCache() { | 58 HttpCache* HttpNetworkLayer::GetCache() { |
51 return NULL; | 59 return NULL; |
52 } | 60 } |
53 | 61 |
54 HttpNetworkSession* HttpNetworkLayer::GetSession() { | 62 HttpNetworkSession* HttpNetworkLayer::GetSession() { return session_.get(); } |
55 return session_; | |
56 } | |
57 | 63 |
58 void HttpNetworkLayer::OnSuspend() { | 64 void HttpNetworkLayer::OnSuspend() { |
59 suspended_ = true; | 65 suspended_ = true; |
60 session_->CloseIdleConnections(); | 66 |
| 67 if (session_.get()) |
| 68 session_->CloseIdleConnections(); |
61 } | 69 } |
62 | 70 |
63 void HttpNetworkLayer::OnResume() { | 71 void HttpNetworkLayer::OnResume() { |
64 suspended_ = false; | 72 suspended_ = false; |
65 } | 73 } |
66 | 74 |
67 } // namespace net | 75 } // namespace net |
OLD | NEW |