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

Side by Side Diff: net/quic/chromium/quic_stream_factory.cc

Issue 2794963002: Check callback is run in QuicStreamFactory::Job (Closed)
Patch Set: Address comment Created 3 years, 8 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/http/http_stream_factory_impl_job_controller_unittest.cc ('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/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
11 #include "base/callback_helpers.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
15 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
16 #include "base/rand_util.h" 17 #include "base/rand_util.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 verify_callback_ = verify_callback; 273 verify_callback_ = verify_callback;
273 callback_ = callback; 274 callback_ = callback;
274 } 275 }
275 return status; 276 return status;
276 } 277 }
277 278
278 void OnComplete() { 279 void OnComplete() {
279 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime", 280 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime",
280 base::TimeTicks::Now() - start_time_); 281 base::TimeTicks::Now() - start_time_);
281 if (!callback_.is_null()) 282 if (!callback_.is_null())
282 callback_.Run(OK); 283 base::ResetAndReturn(&callback_).Run(OK);
283 } 284 }
284 285
285 const QuicServerId& server_id() const { return server_id_; } 286 const QuicServerId& server_id() const { return server_id_; }
286 287
287 private: 288 private:
288 QuicServerId server_id_; 289 QuicServerId server_id_;
289 ProofVerifierCallbackImpl* verify_callback_; 290 ProofVerifierCallbackImpl* verify_callback_;
290 std::unique_ptr<ProofVerifyContext> verify_context_; 291 std::unique_ptr<ProofVerifyContext> verify_context_;
291 std::unique_ptr<ProofVerifyDetails> verify_details_; 292 std::unique_ptr<ProofVerifyDetails> verify_details_;
292 std::string verify_error_details_; 293 std::string verify_error_details_;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 key_(key), 406 key_(key),
406 cert_verify_flags_(0), // unused 407 cert_verify_flags_(0), // unused
407 was_alternative_service_recently_broken_(false), // unused 408 was_alternative_service_recently_broken_(false), // unused
408 started_another_job_(false), // unused 409 started_another_job_(false), // unused
409 net_log_(session->net_log()), // unused 410 net_log_(session->net_log()), // unused
410 num_sent_client_hellos_(0), 411 num_sent_client_hellos_(0),
411 session_(session), 412 session_(session),
412 weak_factory_(this) {} 413 weak_factory_(this) {}
413 414
414 QuicStreamFactory::Job::~Job() { 415 QuicStreamFactory::Job::~Job() {
416 DCHECK(callback_.is_null());
417
415 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. 418 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback.
416 if (server_info_) 419 if (server_info_)
417 server_info_->ResetWaitForDataReadyCallback(); 420 server_info_->ResetWaitForDataReadyCallback();
418 } 421 }
419 422
420 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { 423 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) {
421 int rv = DoLoop(OK); 424 int rv = DoLoop(OK);
422 if (rv == ERR_IO_PENDING) 425 if (rv == ERR_IO_PENDING)
423 callback_ = callback; 426 callback_ = callback;
424 427
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 default: 462 default:
460 NOTREACHED() << "io_state_: " << io_state_; 463 NOTREACHED() << "io_state_: " << io_state_;
461 break; 464 break;
462 } 465 }
463 } while (io_state_ != STATE_NONE && rv != ERR_IO_PENDING); 466 } while (io_state_ != STATE_NONE && rv != ERR_IO_PENDING);
464 return rv; 467 return rv;
465 } 468 }
466 469
467 void QuicStreamFactory::Job::OnIOComplete(int rv) { 470 void QuicStreamFactory::Job::OnIOComplete(int rv) {
468 rv = DoLoop(rv); 471 rv = DoLoop(rv);
469 if (rv != ERR_IO_PENDING && !callback_.is_null()) { 472 if (rv != ERR_IO_PENDING && !callback_.is_null())
470 callback_.Run(rv); 473 base::ResetAndReturn(&callback_).Run(rv);
471 }
472 } 474 }
473 475
474 void QuicStreamFactory::Job::RunAuxilaryJob() { 476 void QuicStreamFactory::Job::RunAuxilaryJob() {
475 int rv = Run(base::Bind(&QuicStreamFactory::OnJobComplete, 477 int rv = Run(base::Bind(&QuicStreamFactory::OnJobComplete,
476 base::Unretained(factory_), this)); 478 base::Unretained(factory_), this));
477 if (rv != ERR_IO_PENDING) 479 if (rv != ERR_IO_PENDING)
478 factory_->OnJobComplete(this, rv); 480 factory_->OnJobComplete(this, rv);
479 } 481 }
480 482
481 void QuicStreamFactory::Job::Cancel() { 483 void QuicStreamFactory::Job::Cancel() {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 return rv; 699 return rv;
698 } 700 }
699 701
700 void QuicStreamRequest::SetSession(QuicChromiumClientSession* session) { 702 void QuicStreamRequest::SetSession(QuicChromiumClientSession* session) {
701 DCHECK(session); 703 DCHECK(session);
702 session_ = session->GetWeakPtr(); 704 session_ = session->GetWeakPtr();
703 } 705 }
704 706
705 void QuicStreamRequest::OnRequestComplete(int rv) { 707 void QuicStreamRequest::OnRequestComplete(int rv) {
706 factory_ = nullptr; 708 factory_ = nullptr;
707 callback_.Run(rv); 709 base::ResetAndReturn(&callback_).Run(rv);
708 } 710 }
709 711
710 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { 712 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const {
711 if (!factory_) 713 if (!factory_)
712 return base::TimeDelta(); 714 return base::TimeDelta();
713 return factory_->GetTimeDelayForWaitingJob(server_id_); 715 return factory_->GetTimeDelayForWaitingJob(server_id_);
714 } 716 }
715 717
716 std::unique_ptr<QuicHttpStream> QuicStreamRequest::CreateStream() { 718 std::unique_ptr<QuicHttpStream> QuicStreamRequest::CreateStream() {
717 if (!session_) 719 if (!session_)
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 void QuicStreamFactory::OpenFactory() { 1989 void QuicStreamFactory::OpenFactory() {
1988 status_ = OPEN; 1990 status_ = OPEN;
1989 } 1991 }
1990 1992
1991 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { 1993 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() {
1992 if (status_ == OPEN) 1994 if (status_ == OPEN)
1993 consecutive_disabled_count_ = 0; 1995 consecutive_disabled_count_ = 0;
1994 } 1996 }
1995 1997
1996 } // namespace net 1998 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698