[email protected] | 1ad77dc | 2012-01-27 03:51:20 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
5 | #include "net/http/http_network_layer.h" | ||||
6 | |||||
[email protected] | 0dfc81b | 2008-08-25 03:44:40 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | 0c55b328 | 2013-11-27 04:18:11 | [diff] [blame] | 8 | #include "base/power_monitor/power_monitor.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 9 | #include "base/strings/string_number_conversions.h" |
[email protected] | d778e042 | 2013-03-06 18:10:22 | [diff] [blame] | 10 | #include "base/strings/string_split.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 11 | #include "base/strings/string_util.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 12 | #include "net/http/http_network_session.h" |
13 | #include "net/http/http_network_transaction.h" | ||||
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 14 | #include "net/http/http_server_properties_impl.h" |
[email protected] | f1e97e9 | 2012-12-16 04:53:25 | [diff] [blame] | 15 | #include "net/http/http_stream_factory_impl_job.h" |
[email protected] | dab9c7d | 2010-02-06 21:44:32 | [diff] [blame] | 16 | #include "net/spdy/spdy_framer.h" |
[email protected] | dab9c7d | 2010-02-06 21:44:32 | [diff] [blame] | 17 | #include "net/spdy/spdy_session.h" |
[email protected] | ea1cc2cd | 2011-02-22 16:47:38 | [diff] [blame] | 18 | #include "net/spdy/spdy_session_pool.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 19 | |
20 | namespace net { | ||||
21 | |||||
22 | //----------------------------------------------------------------------------- | ||||
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 23 | HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 24 | : session_(session), |
[email protected] | c689457 | 2009-06-16 17:10:10 | [diff] [blame] | 25 | suspended_(false) { |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 26 | DCHECK(session_.get()); |
[email protected] | 0c55b328 | 2013-11-27 04:18:11 | [diff] [blame] | 27 | #if defined(OS_WIN) |
[email protected] | ed3bf8a6 | 2014-04-05 18:55:57 | [diff] [blame^] | 28 | base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
29 | if (power_monitor) | ||||
30 | power_monitor->AddObserver(this); | ||||
[email protected] | 0c55b328 | 2013-11-27 04:18:11 | [diff] [blame] | 31 | #endif |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 32 | } |
33 | |||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 34 | HttpNetworkLayer::~HttpNetworkLayer() { |
[email protected] | 0c55b328 | 2013-11-27 04:18:11 | [diff] [blame] | 35 | #if defined(OS_WIN) |
[email protected] | ed3bf8a6 | 2014-04-05 18:55:57 | [diff] [blame^] | 36 | base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
37 | if (power_monitor) | ||||
38 | power_monitor->RemoveObserver(this); | ||||
[email protected] | 0c55b328 | 2013-11-27 04:18:11 | [diff] [blame] | 39 | #endif |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 40 | } |
41 | |||||
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 42 | //----------------------------------------------------------------------------- |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 43 | |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 44 | // static |
45 | HttpTransactionFactory* HttpNetworkLayer::CreateFactory( | ||||
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 46 | HttpNetworkSession* session) { |
47 | DCHECK(session); | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 48 | |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 49 | return new HttpNetworkLayer(session); |
[email protected] | e7f2964 | 2009-03-02 22:53:18 | [diff] [blame] | 50 | } |
51 | |||||
[email protected] | 7adaccb | 2009-10-13 04:43:21 | [diff] [blame] | 52 | // static |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 53 | void HttpNetworkLayer::ForceAlternateProtocol() { |
54 | PortAlternateProtocolPair pair; | ||||
55 | pair.port = 443; | ||||
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 56 | pair.protocol = NPN_SPDY_3; |
[email protected] | 443a30ed | 2012-11-30 02:56:46 | [diff] [blame] | 57 | HttpServerPropertiesImpl::ForceAlternateProtocol(pair); |
[email protected] | 7adaccb | 2009-10-13 04:43:21 | [diff] [blame] | 58 | } |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 59 | |
60 | //----------------------------------------------------------------------------- | ||||
61 | |||||
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 62 | int HttpNetworkLayer::CreateTransaction(RequestPriority priority, |
[email protected] | 027bd85a | 2013-12-27 22:39:10 | [diff] [blame] | 63 | scoped_ptr<HttpTransaction>* trans) { |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 64 | if (suspended_) |
65 | return ERR_NETWORK_IO_SUSPENDED; | ||||
66 | |||||
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 67 | trans->reset(new HttpNetworkTransaction(priority, GetSession())); |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 68 | return OK; |
69 | } | ||||
70 | |||||
71 | HttpCache* HttpNetworkLayer::GetCache() { | ||||
72 | return NULL; | ||||
73 | } | ||||
74 | |||||
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 75 | HttpNetworkSession* HttpNetworkLayer::GetSession() { return session_.get(); } |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 76 | |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 77 | void HttpNetworkLayer::OnSuspend() { |
78 | suspended_ = true; | ||||
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 79 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 80 | if (session_.get()) |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 81 | session_->CloseIdleConnections(); |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 82 | } |
83 | |||||
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 84 | void HttpNetworkLayer::OnResume() { |
85 | suspended_ = false; | ||||
86 | } | ||||
87 | |||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 88 | } // namespace net |