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/quic/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 #include "net/socket/udp_client_socket.h" | 60 #include "net/socket/udp_client_socket.h" |
61 #include "net/ssl/token_binding.h" | 61 #include "net/ssl/token_binding.h" |
62 #include "third_party/boringssl/src/include/openssl/aead.h" | 62 #include "third_party/boringssl/src/include/openssl/aead.h" |
63 #include "url/gurl.h" | 63 #include "url/gurl.h" |
64 #include "url/url_constants.h" | 64 #include "url/url_constants.h" |
65 | 65 |
66 using NetworkHandle = net::NetworkChangeNotifier::NetworkHandle; | 66 using NetworkHandle = net::NetworkChangeNotifier::NetworkHandle; |
67 | 67 |
68 namespace net { | 68 namespace net { |
69 | 69 |
70 // Returns the estimate of dynamically allocated memory of an IPEndPoint. Used | |
Zhongyi Shi
2017/04/11 18:04:39
nit: Returns the estimate of dynamically allocated
xunjieli
2017/04/11 21:51:44
Done.
| |
71 // in tracking IPAliasMap. | |
72 size_t EstimateMemoryUsage(const IPEndPoint& end_point) { | |
73 return 0; | |
74 } | |
75 | |
70 namespace { | 76 namespace { |
71 | 77 |
72 enum CreateSessionFailure { | 78 enum CreateSessionFailure { |
73 CREATION_ERROR_CONNECTING_SOCKET, | 79 CREATION_ERROR_CONNECTING_SOCKET, |
74 CREATION_ERROR_SETTING_RECEIVE_BUFFER, | 80 CREATION_ERROR_SETTING_RECEIVE_BUFFER, |
75 CREATION_ERROR_SETTING_SEND_BUFFER, | 81 CREATION_ERROR_SETTING_SEND_BUFFER, |
76 CREATION_ERROR_SETTING_DO_NOT_FRAGMENT, | 82 CREATION_ERROR_SETTING_DO_NOT_FRAGMENT, |
77 CREATION_ERROR_MAX | 83 CREATION_ERROR_MAX |
78 }; | 84 }; |
79 | 85 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 | 281 |
276 void OnComplete() { | 282 void OnComplete() { |
277 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime", | 283 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime", |
278 base::TimeTicks::Now() - start_time_); | 284 base::TimeTicks::Now() - start_time_); |
279 if (!callback_.is_null()) | 285 if (!callback_.is_null()) |
280 base::ResetAndReturn(&callback_).Run(OK); | 286 base::ResetAndReturn(&callback_).Run(OK); |
281 } | 287 } |
282 | 288 |
283 const QuicServerId& server_id() const { return server_id_; } | 289 const QuicServerId& server_id() const { return server_id_; } |
284 | 290 |
291 size_t EstimateMemoryUsage() const { | |
292 // TODO(xunjieli): crbug.com/669108. Track |verify_context_| and | |
293 // |verify_details_|. | |
294 return base::trace_event::EstimateMemoryUsage(verify_error_details_); | |
295 } | |
296 | |
285 private: | 297 private: |
286 const QuicServerId server_id_; | 298 const QuicServerId server_id_; |
287 ProofVerifierCallbackImpl* verify_callback_; | 299 ProofVerifierCallbackImpl* verify_callback_; |
288 std::unique_ptr<ProofVerifyContext> verify_context_; | 300 std::unique_ptr<ProofVerifyContext> verify_context_; |
289 std::unique_ptr<ProofVerifyDetails> verify_details_; | 301 std::unique_ptr<ProofVerifyDetails> verify_details_; |
290 std::string verify_error_details_; | 302 std::string verify_error_details_; |
291 const base::TimeTicks start_time_; | 303 const base::TimeTicks start_time_; |
292 const NetLogWithSource net_log_; | 304 const NetLogWithSource net_log_; |
293 CompletionCallback callback_; | 305 CompletionCallback callback_; |
294 base::WeakPtrFactory<CertVerifierJob> weak_factory_; | 306 base::WeakPtrFactory<CertVerifierJob> weak_factory_; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 void RunAuxilaryJob(); | 344 void RunAuxilaryJob(); |
333 | 345 |
334 void Cancel(); | 346 void Cancel(); |
335 | 347 |
336 void CancelWaitForDataReadyCallback(); | 348 void CancelWaitForDataReadyCallback(); |
337 | 349 |
338 const QuicSessionKey& key() const { return key_; } | 350 const QuicSessionKey& key() const { return key_; } |
339 | 351 |
340 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 352 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
341 | 353 |
354 // Returns the estimate of dynamically allocated memory in bytes. | |
355 size_t EstimateMemoryUsage() const; | |
356 | |
342 private: | 357 private: |
343 enum IoState { | 358 enum IoState { |
344 STATE_NONE, | 359 STATE_NONE, |
345 STATE_RESOLVE_HOST, | 360 STATE_RESOLVE_HOST, |
346 STATE_RESOLVE_HOST_COMPLETE, | 361 STATE_RESOLVE_HOST_COMPLETE, |
347 STATE_LOAD_SERVER_INFO, | 362 STATE_LOAD_SERVER_INFO, |
348 STATE_LOAD_SERVER_INFO_COMPLETE, | 363 STATE_LOAD_SERVER_INFO_COMPLETE, |
349 STATE_CONNECT, | 364 STATE_CONNECT, |
350 STATE_CONNECT_COMPLETE, | 365 STATE_CONNECT_COMPLETE, |
351 }; | 366 }; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 } | 479 } |
465 | 480 |
466 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { | 481 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
467 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. | 482 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. |
468 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) | 483 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) |
469 return; | 484 return; |
470 server_info_->CancelWaitForDataReadyCallback(); | 485 server_info_->CancelWaitForDataReadyCallback(); |
471 OnIOComplete(OK); | 486 OnIOComplete(OK); |
472 } | 487 } |
473 | 488 |
489 size_t QuicStreamFactory::Job::EstimateMemoryUsage() const { | |
490 return base::trace_event::EstimateMemoryUsage(key_) + | |
491 base::trace_event::EstimateMemoryUsage(server_info_); | |
492 } | |
493 | |
474 int QuicStreamFactory::Job::DoResolveHost() { | 494 int QuicStreamFactory::Job::DoResolveHost() { |
475 dns_resolution_start_time_ = base::TimeTicks::Now(); | 495 dns_resolution_start_time_ = base::TimeTicks::Now(); |
476 // Start loading the data now, and wait for it after we resolve the host. | 496 // Start loading the data now, and wait for it after we resolve the host. |
477 if (server_info_) | 497 if (server_info_) |
478 server_info_->Start(); | 498 server_info_->Start(); |
479 | 499 |
480 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 500 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
481 return host_resolver_->Resolve( | 501 return host_resolver_->Resolve( |
482 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, | 502 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, |
483 &address_list_, | 503 &address_list_, |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 } | 904 } |
885 | 905 |
886 void QuicStreamFactory::set_quic_server_info_factory( | 906 void QuicStreamFactory::set_quic_server_info_factory( |
887 QuicServerInfoFactory* quic_server_info_factory) { | 907 QuicServerInfoFactory* quic_server_info_factory) { |
888 quic_server_info_factory_.reset(quic_server_info_factory); | 908 quic_server_info_factory_.reset(quic_server_info_factory); |
889 } | 909 } |
890 | 910 |
891 void QuicStreamFactory::DumpMemoryStats( | 911 void QuicStreamFactory::DumpMemoryStats( |
892 base::trace_event::ProcessMemoryDump* pmd, | 912 base::trace_event::ProcessMemoryDump* pmd, |
893 const std::string& parent_absolute_name) const { | 913 const std::string& parent_absolute_name) const { |
894 if (all_sessions_.empty()) | 914 if (all_sessions_.empty() && active_jobs_.empty()) |
895 return; | 915 return; |
896 base::trace_event::MemoryAllocatorDump* factory_dump = | 916 base::trace_event::MemoryAllocatorDump* factory_dump = |
897 pmd->CreateAllocatorDump(parent_absolute_name + "/quic_stream_factory"); | 917 pmd->CreateAllocatorDump(parent_absolute_name + "/quic_stream_factory"); |
898 size_t memory_estimate = | 918 size_t memory_estimate = |
899 base::trace_event::EstimateMemoryUsage(all_sessions_); | 919 base::trace_event::EstimateMemoryUsage(all_sessions_) + |
920 base::trace_event::EstimateMemoryUsage(active_sessions_) + | |
921 base::trace_event::EstimateMemoryUsage(session_aliases_) + | |
922 base::trace_event::EstimateMemoryUsage(ip_aliases_) + | |
923 base::trace_event::EstimateMemoryUsage(session_peer_ip_) + | |
924 base::trace_event::EstimateMemoryUsage(gone_away_aliases_) + | |
925 base::trace_event::EstimateMemoryUsage(active_jobs_) + | |
926 base::trace_event::EstimateMemoryUsage(job_requests_map_) + | |
927 base::trace_event::EstimateMemoryUsage(active_cert_verifier_jobs_); | |
900 factory_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 928 factory_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
901 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 929 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
902 memory_estimate); | 930 memory_estimate); |
903 factory_dump->AddScalar( | 931 factory_dump->AddScalar("all_sessions", |
904 base::trace_event::MemoryAllocatorDump::kNameObjectCount, | 932 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
905 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 933 all_sessions_.size()); |
906 all_sessions_.size()); | 934 factory_dump->AddScalar("active_jobs", |
935 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | |
936 active_jobs_.size()); | |
937 factory_dump->AddScalar("active_cert_jobs", | |
938 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | |
939 active_cert_verifier_jobs_.size()); | |
907 } | 940 } |
908 | 941 |
909 bool QuicStreamFactory::CanUseExistingSession(const QuicServerId& server_id, | 942 bool QuicStreamFactory::CanUseExistingSession(const QuicServerId& server_id, |
910 const HostPortPair& destination) { | 943 const HostPortPair& destination) { |
911 // TODO(zhongyi): delete active_sessions_.empty() checks once the | 944 // TODO(zhongyi): delete active_sessions_.empty() checks once the |
912 // android crash issue(crbug.com/498823) is resolved. | 945 // android crash issue(crbug.com/498823) is resolved. |
913 if (active_sessions_.empty()) | 946 if (active_sessions_.empty()) |
914 return false; | 947 return false; |
915 | 948 |
916 if (base::ContainsKey(active_sessions_, server_id)) | 949 if (base::ContainsKey(active_sessions_, server_id)) |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1885 // Since the session was active, there's no longer an | 1918 // Since the session was active, there's no longer an |
1886 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1919 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1887 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1920 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1888 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1921 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1889 // still race. | 1922 // still race. |
1890 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1923 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1891 alternative_service); | 1924 alternative_service); |
1892 } | 1925 } |
1893 | 1926 |
1894 } // namespace net | 1927 } // namespace net |
OLD | NEW |