update_engine: Replace scoped_refptr with shared_ptr in update_manager
It seems like scoped_refptr was a substitute for shared_ptr before
chromium was on C++11:
https://www.chromium.org/developers/smart-pointer-guidelines
But that is not the case anymore as we are already on C++14. So just
replace it in update_manager with shared_ptr.
There is still another use case of it for keeping dbus connections but
that can't easily be changed because brillo::DBusConnection is still
using scoped_refptr.
BUG=chromium:994048
TEST=FEATURES=test emerge update_engine
Change-Id: I1fab0408399d678d2851731aea40fc02be459295
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1755262
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/update_manager/update_manager-inl.h b/update_manager/update_manager-inl.h
index e9dee3f..a1d172d 100644
--- a/update_manager/update_manager-inl.h
+++ b/update_manager/update_manager-inl.h
@@ -78,7 +78,7 @@
template <typename R, typename... Args>
void UpdateManager::OnPolicyReadyToEvaluate(
- scoped_refptr<EvaluationContext> ec,
+ std::shared_ptr<EvaluationContext> ec,
base::Callback<void(EvalStatus status, const R& result)> callback,
EvalStatus (Policy::*policy_method)(
EvaluationContext*, State*, std::string*, R*, Args...) const,
@@ -119,8 +119,7 @@
EvaluationContext*, State*, std::string*, R*, ExpectedArgs...) const,
R* result,
ActualArgs... args) {
- scoped_refptr<EvaluationContext> ec(
- new EvaluationContext(clock_, evaluation_timeout_));
+ auto ec = std::make_shared<EvaluationContext>(clock_, evaluation_timeout_);
// A PolicyRequest always consists on a single evaluation on a new
// EvaluationContext.
// IMPORTANT: To ensure that ActualArgs can be converted to ExpectedArgs, we
@@ -141,7 +140,7 @@
EvalStatus (Policy::*policy_method)(
EvaluationContext*, State*, std::string*, R*, ExpectedArgs...) const,
ActualArgs... args) {
- scoped_refptr<EvaluationContext> ec = new EvaluationContext(
+ auto ec = std::make_shared<EvaluationContext>(
clock_,
evaluation_timeout_,
expiration_timeout_,
@@ -149,7 +148,7 @@
new base::Callback<void(EvaluationContext*)>(
base::Bind(&UpdateManager::UnregisterEvalContext,
weak_ptr_factory_.GetWeakPtr()))));
- if (!ec_repo_.insert(ec.get()).second) {
+ if (!ec_repo_.insert(ec).second) {
LOG(ERROR) << "Failed to register evaluation context; this is a bug.";
}