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

Unified Diff: net/quic/core/crypto/quic_crypto_server_config.cc

Issue 2339433004: Use unique_ptrs to manage callback lifetimes in some QUIC code (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: net/quic/core/crypto/quic_crypto_server_config.cc
diff --git a/net/quic/core/crypto/quic_crypto_server_config.cc b/net/quic/core/crypto/quic_crypto_server_config.cc
index 27adc5d73bc54bea2385376a7b8081d666c8e987..dc5d4c0182295023fd80ac20585d8d063d85dffb 100644
--- a/net/quic/core/crypto/quic_crypto_server_config.cc
+++ b/net/quic/core/crypto/quic_crypto_server_config.cc
@@ -81,11 +81,11 @@ IPAddress DualstackIPAddress(const IPAddress& ip) {
class ValidateClientHelloHelper {
public:
- // Note: stores a pointer to a unique_ptr, and std::moves the unique_ptr when
+ // Note: stores pointers to unique_ptrs, and std::moves the unique_ptrs when
// ValidationComplete is called.
ValidateClientHelloHelper(
std::unique_ptr<ValidateClientHelloResultCallback::Result>* result,
- ValidateClientHelloResultCallback* done_cb)
+ std::unique_ptr<ValidateClientHelloResultCallback>* done_cb)
: result_(result), done_cb_(done_cb) {}
~ValidateClientHelloHelper() {
@@ -99,7 +99,7 @@ class ValidateClientHelloHelper {
std::unique_ptr<ProofSource::Details> proof_source_details) {
(*result_)->error_code = error_code;
(*result_)->error_details = error_details;
- done_cb_->Run(std::move(*result_), std::move(proof_source_details));
+ (*done_cb_)->Run(std::move(*result_), std::move(proof_source_details));
DetachCallback();
}
@@ -110,7 +110,7 @@ class ValidateClientHelloHelper {
private:
std::unique_ptr<ValidateClientHelloResultCallback::Result>* result_;
- ValidateClientHelloResultCallback* done_cb_;
+ std::unique_ptr<ValidateClientHelloResultCallback>* done_cb_;
DISALLOW_COPY_AND_ASSIGN(ValidateClientHelloHelper);
};
@@ -121,10 +121,10 @@ class VerifyNonceIsValidAndUniqueCallback
VerifyNonceIsValidAndUniqueCallback(
std::unique_ptr<ValidateClientHelloResultCallback::Result> result,
std::unique_ptr<ProofSource::Details> proof_source_details,
- ValidateClientHelloResultCallback* done_cb)
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb)
: result_(std::move(result)),
proof_source_details_(std::move(proof_source_details)),
- done_cb_(done_cb) {}
+ done_cb_(std::move(done_cb)) {}
protected:
void RunImpl(bool nonce_is_valid_and_unique,
@@ -169,7 +169,7 @@ class VerifyNonceIsValidAndUniqueCallback
private:
std::unique_ptr<ValidateClientHelloResultCallback::Result> result_;
std::unique_ptr<ProofSource::Details> proof_source_details_;
- ValidateClientHelloResultCallback* done_cb_;
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb_;
DISALLOW_COPY_AND_ASSIGN(VerifyNonceIsValidAndUniqueCallback);
};
@@ -201,13 +201,6 @@ ValidateClientHelloResultCallback::ValidateClientHelloResultCallback() {}
ValidateClientHelloResultCallback::~ValidateClientHelloResultCallback() {}
-void ValidateClientHelloResultCallback::Run(
- std::unique_ptr<Result> result,
- std::unique_ptr<ProofSource::Details> details) {
- RunImpl(std::move(result), std::move(details));
- delete this;
-}
-
QuicCryptoServerConfig::ConfigOptions::ConfigOptions()
: expiry_time(QuicWallTime::Zero()),
channel_id_enabled(false),
@@ -504,7 +497,7 @@ void QuicCryptoServerConfig::ValidateClientHello(
QuicVersion version,
const QuicClock* clock,
QuicCryptoProof* crypto_proof,
- ValidateClientHelloResultCallback* done_cb) const {
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb) const {
const QuicWallTime now(clock->WallNow());
std::unique_ptr<ValidateClientHelloResultCallback::Result> result(
@@ -549,7 +542,7 @@ void QuicCryptoServerConfig::ValidateClientHello(
}
EvaluateClientHello(server_ip, version, primary_orbit, requested_config,
primary_config, crypto_proof, std::move(result),
- done_cb);
+ std::move(done_cb));
} else {
done_cb->Run(std::move(result), /* details = */ nullptr);
}
@@ -1007,7 +1000,7 @@ class EvaluateClientHelloCallback : public ProofSource::Callback {
QuicCryptoProof* crypto_proof,
std::unique_ptr<ValidateClientHelloResultCallback::Result>
client_hello_state,
- ValidateClientHelloResultCallback* done_cb)
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb)
: config_(config),
found_error_(found_error),
server_ip_(server_ip),
@@ -1017,7 +1010,7 @@ class EvaluateClientHelloCallback : public ProofSource::Callback {
primary_config_(std::move(primary_config)),
crypto_proof_(crypto_proof),
client_hello_state_(std::move(client_hello_state)),
- done_cb_(done_cb) {}
+ done_cb_(std::move(done_cb)) {}
void Run(bool ok,
const scoped_refptr<ProofSource::Chain>& chain,
@@ -1032,7 +1025,7 @@ class EvaluateClientHelloCallback : public ProofSource::Callback {
config_.EvaluateClientHelloAfterGetProof(
found_error_, server_ip_, version_, primary_orbit_, requested_config_,
primary_config_, crypto_proof_, std::move(details), !ok,
- std::move(client_hello_state_), done_cb_);
+ std::move(client_hello_state_), std::move(done_cb_));
}
private:
@@ -1046,7 +1039,7 @@ class EvaluateClientHelloCallback : public ProofSource::Callback {
QuicCryptoProof* crypto_proof_;
std::unique_ptr<ValidateClientHelloResultCallback::Result>
client_hello_state_;
- ValidateClientHelloResultCallback* done_cb_;
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb_;
};
void QuicCryptoServerConfig::EvaluateClientHello(
@@ -1058,8 +1051,8 @@ void QuicCryptoServerConfig::EvaluateClientHello(
QuicCryptoProof* crypto_proof,
std::unique_ptr<ValidateClientHelloResultCallback::Result>
client_hello_state,
- ValidateClientHelloResultCallback* done_cb) const {
- ValidateClientHelloHelper helper(&client_hello_state, done_cb);
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb) const {
+ ValidateClientHelloHelper helper(&client_hello_state, &done_cb);
const CryptoHandshakeMessage& client_hello = client_hello_state->client_hello;
ClientHelloInfo* info = &(client_hello_state->info);
@@ -1137,7 +1130,7 @@ void QuicCryptoServerConfig::EvaluateClientHello(
new EvaluateClientHelloCallback(
*this, found_error, server_ip, version, primary_orbit,
requested_config, primary_config, crypto_proof,
- std::move(client_hello_state), done_cb));
+ std::move(client_hello_state), std::move(done_cb)));
proof_source_->GetProof(server_ip, info->sni.as_string(),
serialized_config, version, chlo_hash,
std::move(cb));
@@ -1160,7 +1153,7 @@ void QuicCryptoServerConfig::EvaluateClientHello(
EvaluateClientHelloAfterGetProof(
found_error, server_ip, version, primary_orbit, requested_config,
primary_config, crypto_proof, nullptr /* proof_source_details */,
- get_proof_failed, std::move(client_hello_state), done_cb);
+ get_proof_failed, std::move(client_hello_state), std::move(done_cb));
helper.DetachCallback();
}
@@ -1176,8 +1169,8 @@ void QuicCryptoServerConfig::EvaluateClientHelloAfterGetProof(
bool get_proof_failed,
std::unique_ptr<ValidateClientHelloResultCallback::Result>
client_hello_state,
- ValidateClientHelloResultCallback* done_cb) const {
- ValidateClientHelloHelper helper(&client_hello_state, done_cb);
+ std::unique_ptr<ValidateClientHelloResultCallback> done_cb) const {
+ ValidateClientHelloHelper helper(&client_hello_state, &done_cb);
const CryptoHandshakeMessage& client_hello = client_hello_state->client_hello;
ClientHelloInfo* info = &(client_hello_state->info);
@@ -1275,7 +1268,7 @@ void QuicCryptoServerConfig::EvaluateClientHelloAfterGetProof(
info->client_nonce, info->now,
new VerifyNonceIsValidAndUniqueCallback(std::move(client_hello_state),
std::move(proof_source_details),
- done_cb));
+ std::move(done_cb)));
helper.DetachCallback();
}
@@ -1824,9 +1817,9 @@ void QuicCryptoServerConfig::set_enable_serving_sct(bool enable_serving_sct) {
}
void QuicCryptoServerConfig::AcquirePrimaryConfigChangedCb(
- PrimaryConfigChangedCallback* cb) {
+ std::unique_ptr<PrimaryConfigChangedCallback> cb) {
base::AutoLock locked(configs_lock_);
- primary_config_changed_cb_.reset(cb);
+ primary_config_changed_cb_ = std::move(cb);
}
string QuicCryptoServerConfig::NewSourceAddressToken(

Powered by Google App Engine
This is Rietveld 408576698