xref: /aosp_15_r20/external/cronet/net/http/http_network_layer.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
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 <memory>
8 
9 #include "base/check_op.h"
10 #include "base/power_monitor/power_monitor.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h"
14 #include "build/build_config.h"
15 #include "net/http/http_network_session.h"
16 #include "net/http/http_network_transaction.h"
17 #include "net/http/http_server_properties.h"
18 #include "net/http/http_stream_factory_job.h"
19 #include "net/spdy/spdy_session.h"
20 #include "net/spdy/spdy_session_pool.h"
21 #include "net/third_party/quiche/src/quiche/spdy/core/spdy_framer.h"
22 
23 namespace net {
24 
HttpNetworkLayer(HttpNetworkSession * session)25 HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
26     : session_(session) {
27   DCHECK(session_);
28 #if BUILDFLAG(IS_WIN)
29   base::PowerMonitor::AddPowerSuspendObserver(this);
30 #endif
31 }
32 
~HttpNetworkLayer()33 HttpNetworkLayer::~HttpNetworkLayer() {
34   DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
35 #if BUILDFLAG(IS_WIN)
36   base::PowerMonitor::RemovePowerSuspendObserver(this);
37 #endif
38 }
39 
CreateTransaction(RequestPriority priority,std::unique_ptr<HttpTransaction> * trans)40 int HttpNetworkLayer::CreateTransaction(
41     RequestPriority priority,
42     std::unique_ptr<HttpTransaction>* trans) {
43   if (suspended_)
44     return ERR_NETWORK_IO_SUSPENDED;
45 
46   *trans = std::make_unique<HttpNetworkTransaction>(priority, GetSession());
47   return OK;
48 }
49 
GetCache()50 HttpCache* HttpNetworkLayer::GetCache() {
51   return nullptr;
52 }
53 
GetSession()54 HttpNetworkSession* HttpNetworkLayer::GetSession() {
55   return session_;
56 }
57 
OnSuspend()58 void HttpNetworkLayer::OnSuspend() {
59   suspended_ = true;
60   session_->CloseIdleConnections("Entering suspend mode");
61 }
62 
OnResume()63 void HttpNetworkLayer::OnResume() {
64   suspended_ = false;
65 }
66 
67 }  // namespace net
68