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

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

Issue 2928763002: Move SpdySessionRequestMap to SpdySessionPool (Closed)
Patch Set: address comment 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
« no previous file with comments | « net/spdy/chromium/spdy_session_pool.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 (spdy_session) {
411 const SpdySessionKey& spdy_session_key = spdy_session->spdy_session_key();
412 // Each iteration may empty out the RequestSet for |spdy_session_key| in
413 // |spdy_session_request_map_|. So each time, check for RequestSet and use
414 // the first one.
415 //
416 // TODO(willchan): If it's important, switch RequestSet out for a FIFO
417 // queue (Order by priority first, then FIFO within same priority). Unclear
418 // that it matters here.
419 auto iter = spdy_session_request_map_.find(spdy_session_key);
420 if (iter == spdy_session_request_map_.end())
421 return;
422 HttpStreamFactoryImpl::Request* request = *iter->second.begin();
423 request->Complete(was_alpn_negotiated, negotiated_protocol, using_spdy);
424 if (request->stream_type() == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
425 request->OnBidirectionalStreamImplReady(
426 used_ssl_config, used_proxy_info,
427 new BidirectionalStreamSpdyImpl(spdy_session, source_dependency));
428 } else {
429 bool use_relative_url =
430 direct || request->url().SchemeIs(url::kHttpsScheme);
431 request->OnStreamReady(used_ssl_config, used_proxy_info,
432 new SpdyHttpStream(spdy_session, use_relative_url,
433 source_dependency));
434 }
435 }
436 // TODO(mbelshe): Alert other valid requests.
437 }
438
439 void SpdySessionPool::AddRequestToSpdySessionRequestMap(
440 const SpdySessionKey& spdy_session_key,
441 HttpStreamFactoryImpl::Request* request) {
442 if (request->HasSpdySessionKey())
443 return;
444 RequestSet& request_set = spdy_session_request_map_[spdy_session_key];
445 DCHECK(!base::ContainsKey(request_set, request));
446 request_set.insert(request);
447 request->SetSpdySessionKey(spdy_session_key);
448 }
449
450 void SpdySessionPool::RemoveRequestFromSpdySessionRequestMap(
451 HttpStreamFactoryImpl::Request* request) {
452 if (!request->HasSpdySessionKey())
453 return;
454 const SpdySessionKey& spdy_session_key = request->GetSpdySessionKey();
455 auto iter = spdy_session_request_map_.find(spdy_session_key);
456 DCHECK(iter != spdy_session_request_map_.end());
457 RequestSet& request_set = iter->second;
458 DCHECK(base::ContainsKey(request_set, request));
459 request_set.erase(request);
460 if (request_set.empty())
461 spdy_session_request_map_.erase(spdy_session_key);
462 request->ResetSpdySessionKey();
463 }
464
398 void SpdySessionPool::DumpMemoryStats( 465 void SpdySessionPool::DumpMemoryStats(
399 base::trace_event::ProcessMemoryDump* pmd, 466 base::trace_event::ProcessMemoryDump* pmd,
400 const SpdyString& parent_dump_absolute_name) const { 467 const SpdyString& parent_dump_absolute_name) const {
401 if (sessions_.empty()) 468 if (sessions_.empty())
402 return; 469 return;
403 size_t total_size = 0; 470 size_t total_size = 0;
404 size_t buffer_size = 0; 471 size_t buffer_size = 0;
405 size_t cert_count = 0; 472 size_t cert_count = 0;
406 size_t cert_size = 0; 473 size_t cert_size = 0;
407 size_t num_active_sessions = 0; 474 size_t num_active_sessions = 0;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 572
506 if (idle_only && (*it)->is_active()) 573 if (idle_only && (*it)->is_active())
507 continue; 574 continue;
508 575
509 (*it)->CloseSessionOnError(error, description); 576 (*it)->CloseSessionOnError(error, description);
510 DCHECK(!IsSessionAvailable(*it)); 577 DCHECK(!IsSessionAvailable(*it));
511 } 578 }
512 } 579 }
513 580
514 } // namespace net 581 } // namespace net
OLDNEW
« no previous file with comments | « 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