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::TransactionFactory* g_network_transaction_factory_ = NULL; |
| 23 |
22 //----------------------------------------------------------------------------- | 24 //----------------------------------------------------------------------------- |
23 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) | 25 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
24 : session_(session), | 26 : session_(session), |
25 suspended_(false) { | 27 suspended_(false) { |
26 DCHECK(session_.get()); | 28 DCHECK(session_.get()); |
27 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
28 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 30 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
29 if (power_monitor) | 31 if (power_monitor) |
30 power_monitor->AddObserver(this); | 32 power_monitor->AddObserver(this); |
31 #endif | 33 #endif |
(...skipping 18 matching lines...) Expand all Loading... |
50 } | 52 } |
51 | 53 |
52 // static | 54 // static |
53 void HttpNetworkLayer::ForceAlternateProtocol() { | 55 void HttpNetworkLayer::ForceAlternateProtocol() { |
54 PortAlternateProtocolPair pair; | 56 PortAlternateProtocolPair pair; |
55 pair.port = 443; | 57 pair.port = 443; |
56 pair.protocol = NPN_SPDY_3; | 58 pair.protocol = NPN_SPDY_3; |
57 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); | 59 HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
58 } | 60 } |
59 | 61 |
| 62 // static |
| 63 void HttpNetworkLayer::SetTransactionFactory( |
| 64 HttpNetworkLayer::TransactionFactory* factory) { |
| 65 g_network_transaction_factory_ = factory; |
| 66 } |
| 67 |
60 //----------------------------------------------------------------------------- | 68 //----------------------------------------------------------------------------- |
61 | 69 |
62 int HttpNetworkLayer::CreateTransaction(RequestPriority priority, | 70 int HttpNetworkLayer::CreateTransaction(RequestPriority priority, |
63 scoped_ptr<HttpTransaction>* trans) { | 71 scoped_ptr<HttpTransaction>* trans) { |
64 if (suspended_) | 72 if (suspended_) |
65 return ERR_NETWORK_IO_SUSPENDED; | 73 return ERR_NETWORK_IO_SUSPENDED; |
66 | 74 |
| 75 if (g_network_transaction_factory_) |
| 76 return g_network_transaction_factory_->CreateTransaction( |
| 77 priority, GetSession(), trans); |
| 78 |
67 trans->reset(new HttpNetworkTransaction(priority, GetSession())); | 79 trans->reset(new HttpNetworkTransaction(priority, GetSession())); |
68 return OK; | 80 return OK; |
69 } | 81 } |
70 | 82 |
71 HttpCache* HttpNetworkLayer::GetCache() { | 83 HttpCache* HttpNetworkLayer::GetCache() { |
72 return NULL; | 84 return NULL; |
73 } | 85 } |
74 | 86 |
75 HttpNetworkSession* HttpNetworkLayer::GetSession() { return session_.get(); } | 87 HttpNetworkSession* HttpNetworkLayer::GetSession() { return session_.get(); } |
76 | 88 |
77 void HttpNetworkLayer::OnSuspend() { | 89 void HttpNetworkLayer::OnSuspend() { |
78 suspended_ = true; | 90 suspended_ = true; |
79 | 91 |
80 if (session_.get()) | 92 if (session_.get()) |
81 session_->CloseIdleConnections(); | 93 session_->CloseIdleConnections(); |
82 } | 94 } |
83 | 95 |
84 void HttpNetworkLayer::OnResume() { | 96 void HttpNetworkLayer::OnResume() { |
85 suspended_ = false; | 97 suspended_ = false; |
86 } | 98 } |
87 | 99 |
88 } // namespace net | 100 } // namespace net |
OLD | NEW |