Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: net/spdy/chromium/spdy_session_pool.cc

Issue 2928763002: Move SpdySessionRequestMap to SpdySessionPool (Closed)
Patch Set: self Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/spdy/chromium/spdy_session_pool.h" 5 #include "net/spdy/chromium/spdy_session_pool.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/profiler/scoped_tracker.h" 12 #include "base/profiler/scoped_tracker.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/trace_event/memory_allocator_dump.h" 14 #include "base/trace_event/memory_allocator_dump.h"
15 #include "base/trace_event/process_memory_dump.h" 15 #include "base/trace_event/process_memory_dump.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "net/base/address_list.h" 18 #include "net/base/address_list.h"
19 #include "net/base/trace_constants.h" 19 #include "net/base/trace_constants.h"
20 #include "net/http/http_network_session.h" 20 #include "net/http/http_network_session.h"
21 #include "net/http/http_server_properties.h" 21 #include "net/http/http_server_properties.h"
22 #include "net/log/net_log_event_type.h" 22 #include "net/log/net_log_event_type.h"
23 #include "net/log/net_log_source.h" 23 #include "net/log/net_log_source.h"
24 #include "net/log/net_log_with_source.h" 24 #include "net/log/net_log_with_source.h"
25 #include "net/spdy/chromium/bidirectional_stream_spdy_impl.h"
26 #include "net/spdy/chromium/spdy_http_stream.h"
25 #include "net/spdy/chromium/spdy_session.h" 27 #include "net/spdy/chromium/spdy_session.h"
26 #include "net/spdy/core/hpack/hpack_constants.h" 28 #include "net/spdy/core/hpack/hpack_constants.h"
27 #include "net/spdy/core/hpack/hpack_huffman_table.h" 29 #include "net/spdy/core/hpack/hpack_huffman_table.h"
28 #include "net/spdy/core/hpack/hpack_static_table.h" 30 #include "net/spdy/core/hpack/hpack_static_table.h"
29 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" 31 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
30 #include "net/spdy/platform/api/spdy_string_utils.h" 32 #include "net/spdy/platform/api/spdy_string_utils.h"
31 33
32 namespace net { 34 namespace net {
33 35
34 namespace { 36 namespace {
(...skipping 30 matching lines...) Expand all
65 time_func_(time_func), 67 time_func_(time_func),
66 push_delegate_(nullptr), 68 push_delegate_(nullptr),
67 proxy_delegate_(proxy_delegate) { 69 proxy_delegate_(proxy_delegate) {
68 NetworkChangeNotifier::AddIPAddressObserver(this); 70 NetworkChangeNotifier::AddIPAddressObserver(this);
69 if (ssl_config_service_.get()) 71 if (ssl_config_service_.get())
70 ssl_config_service_->AddObserver(this); 72 ssl_config_service_->AddObserver(this);
71 CertDatabase::GetInstance()->AddObserver(this); 73 CertDatabase::GetInstance()->AddObserver(this);
72 } 74 }
73 75
74 SpdySessionPool::~SpdySessionPool() { 76 SpdySessionPool::~SpdySessionPool() {
77 DCHECK(spdy_session_request_map_.empty());
75 CloseAllSessions(); 78 CloseAllSessions();
76 79
77 while (!sessions_.empty()) { 80 while (!sessions_.empty()) {
78 // Destroy sessions to enforce that lifetime is scoped to SpdySessionPool. 81 // Destroy sessions to enforce that lifetime is scoped to SpdySessionPool.
79 // Write callbacks queued upon session drain are not invoked. 82 // Write callbacks queued upon session drain are not invoked.
80 RemoveUnavailableSession((*sessions_.begin())->GetWeakPtr()); 83 RemoveUnavailableSession((*sessions_.begin())->GetWeakPtr());
81 } 84 }
82 85
83 if (ssl_config_service_.get()) 86 if (ssl_config_service_.get())
84 ssl_config_service_->RemoveObserver(this); 87 ssl_config_service_->RemoveObserver(this);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 391 }
389 392
390 void SpdySessionPool::OnSSLConfigChanged() { 393 void SpdySessionPool::OnSSLConfigChanged() {
391 CloseCurrentSessions(ERR_NETWORK_CHANGED); 394 CloseCurrentSessions(ERR_NETWORK_CHANGED);
392 } 395 }
393 396
394 void SpdySessionPool::OnCertDBChanged() { 397 void SpdySessionPool::OnCertDBChanged() {
395 CloseCurrentSessions(ERR_CERT_DATABASE_CHANGED); 398 CloseCurrentSessions(ERR_CERT_DATABASE_CHANGED);
396 } 399 }
397 400
401 void SpdySessionPool::OnNewSpdySessionReady(
402 const base::WeakPtr<SpdySession>& spdy_session,
403 bool direct,
404 const SSLConfig& used_ssl_config,
405 const ProxyInfo& used_proxy_info,
406 bool was_alpn_negotiated,
407 NextProto negotiated_protocol,
408 bool using_spdy,
409 NetLogSource source_dependency) {
410 while (true) {
Bence 2017/06/07 17:41:43 Optional: while(spdy_session) {
xunjieli 2017/06/07 21:55:56 Done.
411 if (!spdy_session)
412 break;
413 const SpdySessionKey& spdy_session_key = spdy_session->spdy_session_key();
414 // Each iteration may empty out the RequestSet for |spdy_session_key| in
415 // |spdy_session_request_map_|. So each time, check for RequestSet and use
416 // the first one.
417 //
418 // TODO(willchan): If it's important, switch RequestSet out for a FIFO
419 // queue (Order by priority first, then FIFO within same priority). Unclear
420 // that it matters here.
421 if (!base::ContainsKey(spdy_session_request_map_, spdy_session_key))
Bence 2017/06/07 17:41:43 ContainsKey and operator[] below are two lookups,
xunjieli 2017/06/07 21:55:56 Done.
422 break;
Bence 2017/06/07 17:41:43 Optional: return instead of break might reflect ou
xunjieli 2017/06/07 21:55:56 Done.
423 HttpStreamFactoryImpl::Request* request =
424 *spdy_session_request_map_[spdy_session_key].begin();
425 request->Complete(was_alpn_negotiated, negotiated_protocol, using_spdy);
426 if (request->stream_type() == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
427 request->OnBidirectionalStreamImplReady(
428 used_ssl_config, used_proxy_info,
429 new BidirectionalStreamSpdyImpl(spdy_session, source_dependency));
430 } else {
431 bool use_relative_url =
432 direct || request->url().SchemeIs(url::kHttpsScheme);
433 request->OnStreamReady(used_ssl_config, used_proxy_info,
434 new SpdyHttpStream(spdy_session, use_relative_url,
435 source_dependency));
436 }
437 }
438 // TODO(mbelshe): Alert other valid requests.
439 }
440
441 void SpdySessionPool::RemoveRequestFromSpdySessionRequestMap(
442 HttpStreamFactoryImpl::Request* request) {
443 if (request->HasSpdySessionKey()) {
Bence 2017/06/07 17:41:43 Optional: early return instead of wrapping entire
xunjieli 2017/06/07 21:55:56 Done.
444 const SpdySessionKey& spdy_session_key = request->GetSpdySessionKey();
445 DCHECK(base::ContainsKey(spdy_session_request_map_, spdy_session_key));
Bence 2017/06/07 17:41:43 Optional: do only one lookup instead of two in deb
xunjieli 2017/06/07 21:55:56 Done.
446 RequestSet& request_set = spdy_session_request_map_[spdy_session_key];
447 DCHECK(base::ContainsKey(request_set, request));
Bence 2017/06/07 17:41:43 Optional: do only one lookup instead of two in deb
xunjieli 2017/06/07 21:55:56 Acknowledged. One lookup is in |request_set| and t
448 request_set.erase(request);
449 if (request_set.empty())
450 spdy_session_request_map_.erase(spdy_session_key);
451 request->ResetSpdySessionKey();
452 }
453 }
454
455 void SpdySessionPool::AddRequestToSpdySessionRequestMap(
456 const SpdySessionKey& spdy_session_key,
457 HttpStreamFactoryImpl::Request* request) {
458 if (!request->HasSpdySessionKey()) {
Bence 2017/06/07 17:41:43 Optional: early return instead of wrapping entire
xunjieli 2017/06/07 21:55:56 Done.
459 RequestSet& request_set = spdy_session_request_map_[spdy_session_key];
460 DCHECK(!base::ContainsKey(request_set, request));
Bence 2017/06/07 17:41:42 Optional: cut down on lookups by auto result = ins
xunjieli 2017/06/07 21:55:56 Acknowledged. One lookup is in |request_set| and t
461 request_set.insert(request);
462 request->SetSpdySessionKey(spdy_session_key);
463 }
464 }
465
398 void SpdySessionPool::DumpMemoryStats( 466 void SpdySessionPool::DumpMemoryStats(
399 base::trace_event::ProcessMemoryDump* pmd, 467 base::trace_event::ProcessMemoryDump* pmd,
400 const SpdyString& parent_dump_absolute_name) const { 468 const SpdyString& parent_dump_absolute_name) const {
401 if (sessions_.empty()) 469 if (sessions_.empty())
402 return; 470 return;
403 size_t total_size = 0; 471 size_t total_size = 0;
404 size_t buffer_size = 0; 472 size_t buffer_size = 0;
405 size_t cert_count = 0; 473 size_t cert_count = 0;
406 size_t cert_size = 0; 474 size_t cert_size = 0;
407 size_t num_active_sessions = 0; 475 size_t num_active_sessions = 0;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 573
506 if (idle_only && (*it)->is_active()) 574 if (idle_only && (*it)->is_active())
507 continue; 575 continue;
508 576
509 (*it)->CloseSessionOnError(error, description); 577 (*it)->CloseSessionOnError(error, description);
510 DCHECK(!IsSessionAvailable(*it)); 578 DCHECK(!IsSessionAvailable(*it));
511 } 579 }
512 } 580 }
513 581
514 } // namespace net 582 } // namespace net
OLDNEW
« net/spdy/chromium/spdy_session_pool.h ('K') | « net/spdy/chromium/spdy_session_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698