Commit dfd1f9aa authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

[sync] Adopt std::unique_ptr instead of raw pointers

No behavioral differences: these appear to be old occurrences that
predate the broad adoption of std::unique_ptr in the codebase.

Change-Id: I28ff0e7ac91c8545b3b3cea748ba0681366b48a9
Bug: None
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556943
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarVictor Vianna <victorvianna@google.com>
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830725}
parent 9598919e
...@@ -23,17 +23,16 @@ std::unique_ptr<SyncScheduler> EngineComponentsFactoryImpl::BuildScheduler( ...@@ -23,17 +23,16 @@ std::unique_ptr<SyncScheduler> EngineComponentsFactoryImpl::BuildScheduler(
SyncCycleContext* context, SyncCycleContext* context,
CancelationSignal* cancelation_signal, CancelationSignal* cancelation_signal,
bool ignore_auth_credentials) { bool ignore_auth_credentials) {
std::unique_ptr<BackoffDelayProvider> delay( std::unique_ptr<BackoffDelayProvider> delay =
BackoffDelayProvider::FromDefaults()); (switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE)
? BackoffDelayProvider::WithShortInitialRetryOverride()
if (switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE) { : BackoffDelayProvider::FromDefaults();
delay.reset(BackoffDelayProvider::WithShortInitialRetryOverride());
}
std::unique_ptr<SyncSchedulerImpl> scheduler = std::unique_ptr<SyncSchedulerImpl> scheduler =
std::make_unique<SyncSchedulerImpl>(name, delay.release(), context, std::make_unique<SyncSchedulerImpl>(
new Syncer(cancelation_signal), name, std::move(delay), context,
ignore_auth_credentials); std::make_unique<Syncer>(cancelation_signal),
ignore_auth_credentials);
if (switches_.force_short_nudge_delay_for_test) { if (switches_.force_short_nudge_delay_for_test) {
scheduler->ForceShortNudgeDelayForTest(); scheduler->ForceShortNudgeDelayForTest();
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include "base/memory/ptr_util.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "components/sync/base/syncer_error.h" #include "components/sync/base/syncer_error.h"
#include "components/sync/engine/cycle/model_neutral_state.h" #include "components/sync/engine/cycle/model_neutral_state.h"
...@@ -18,17 +19,20 @@ using base::TimeDelta; ...@@ -18,17 +19,20 @@ using base::TimeDelta;
namespace syncer { namespace syncer {
// static // static
BackoffDelayProvider* BackoffDelayProvider::FromDefaults() { std::unique_ptr<BackoffDelayProvider> BackoffDelayProvider::FromDefaults() {
return new BackoffDelayProvider( // base::WrapUnique() used because the constructor is private.
return base::WrapUnique(new BackoffDelayProvider(
TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), TimeDelta::FromSeconds(kInitialBackoffRetrySeconds),
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)); TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)));
} }
// static // static
BackoffDelayProvider* BackoffDelayProvider::WithShortInitialRetryOverride() { std::unique_ptr<BackoffDelayProvider>
return new BackoffDelayProvider( BackoffDelayProvider::WithShortInitialRetryOverride() {
// base::WrapUnique() used because the constructor is private.
return base::WrapUnique(new BackoffDelayProvider(
TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds), TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds),
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)); TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)));
} }
BackoffDelayProvider::BackoffDelayProvider( BackoffDelayProvider::BackoffDelayProvider(
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ #ifndef COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_
#define COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_ #define COMPONENTS_SYNC_ENGINE_IMPL_BACKOFF_DELAY_PROVIDER_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -16,7 +18,7 @@ struct ModelNeutralState; ...@@ -16,7 +18,7 @@ struct ModelNeutralState;
class BackoffDelayProvider { class BackoffDelayProvider {
public: public:
// Factory function to create a standard BackoffDelayProvider. // Factory function to create a standard BackoffDelayProvider.
static BackoffDelayProvider* FromDefaults(); static std::unique_ptr<BackoffDelayProvider> FromDefaults();
// Similar to above, but causes sync to retry very quickly (see // Similar to above, but causes sync to retry very quickly (see
// polling_constants.h) when it encounters an error before exponential // polling_constants.h) when it encounters an error before exponential
...@@ -24,7 +26,7 @@ class BackoffDelayProvider { ...@@ -24,7 +26,7 @@ class BackoffDelayProvider {
// //
// *** NOTE *** This should only be used if kSyncShortInitialRetryOverride // *** NOTE *** This should only be used if kSyncShortInitialRetryOverride
// was passed to command line. // was passed to command line.
static BackoffDelayProvider* WithShortInitialRetryOverride(); static std::unique_ptr<BackoffDelayProvider> WithShortInitialRetryOverride();
virtual ~BackoffDelayProvider(); virtual ~BackoffDelayProvider();
......
...@@ -116,17 +116,18 @@ ConfigurationParams::~ConfigurationParams() = default; ...@@ -116,17 +116,18 @@ ConfigurationParams::~ConfigurationParams() = default;
#define SDVLOG_LOC(from_here, verbose_level) \ #define SDVLOG_LOC(from_here, verbose_level) \
DVLOG_LOC(from_here, verbose_level) << name_ << ": " DVLOG_LOC(from_here, verbose_level) << name_ << ": "
SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name, SyncSchedulerImpl::SyncSchedulerImpl(
BackoffDelayProvider* delay_provider, const std::string& name,
SyncCycleContext* context, std::unique_ptr<BackoffDelayProvider> delay_provider,
Syncer* syncer, SyncCycleContext* context,
bool ignore_auth_credentials) std::unique_ptr<Syncer> syncer,
bool ignore_auth_credentials)
: name_(name), : name_(name),
started_(false), started_(false),
syncer_poll_interval_seconds_(context->poll_interval()), syncer_poll_interval_seconds_(context->poll_interval()),
mode_(CONFIGURATION_MODE), mode_(CONFIGURATION_MODE),
delay_provider_(delay_provider), delay_provider_(std::move(delay_provider)),
syncer_(syncer), syncer_(std::move(syncer)),
cycle_context_(context), cycle_context_(context),
next_sync_cycle_job_priority_(NORMAL_PRIORITY), next_sync_cycle_job_priority_(NORMAL_PRIORITY),
ignore_auth_credentials_(ignore_auth_credentials) {} ignore_auth_credentials_(ignore_auth_credentials) {}
......
...@@ -33,12 +33,11 @@ struct ModelNeutralState; ...@@ -33,12 +33,11 @@ struct ModelNeutralState;
class SyncSchedulerImpl : public SyncScheduler { class SyncSchedulerImpl : public SyncScheduler {
public: public:
// |name| is a display string to identify the syncer thread. Takes // |name| is a display string to identify the syncer thread.
// ownership of |syncer| and |delay_provider|.
SyncSchedulerImpl(const std::string& name, SyncSchedulerImpl(const std::string& name,
BackoffDelayProvider* delay_provider, std::unique_ptr<BackoffDelayProvider> delay_provider,
SyncCycleContext* context, SyncCycleContext* context,
Syncer* syncer, std::unique_ptr<Syncer> syncer,
bool ignore_auth_credentials); bool ignore_auth_credentials);
// Calls Stop(). // Calls Stop().
...@@ -254,7 +253,7 @@ class SyncSchedulerImpl : public SyncScheduler { ...@@ -254,7 +253,7 @@ class SyncSchedulerImpl : public SyncScheduler {
NudgeTracker nudge_tracker_; NudgeTracker nudge_tracker_;
// Invoked to run through the sync cycle. // Invoked to run through the sync cycle.
std::unique_ptr<Syncer> syncer_; const std::unique_ptr<Syncer> syncer_;
SyncCycleContext* cycle_context_; SyncCycleContext* cycle_context_;
......
...@@ -282,11 +282,12 @@ class SyncSchedulerImplTest : public testing::Test { ...@@ -282,11 +282,12 @@ class SyncSchedulerImplTest : public testing::Test {
} }
void RebuildScheduler() { void RebuildScheduler() {
// The old syncer is destroyed with the scheduler that owns it. auto syncer = std::make_unique<testing::StrictMock<MockSyncer>>();
syncer_ = new testing::StrictMock<MockSyncer>(); // The syncer is destroyed with the scheduler that owns it.
syncer_ = syncer.get();
scheduler_ = std::make_unique<SyncSchedulerImpl>( scheduler_ = std::make_unique<SyncSchedulerImpl>(
"TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(),
syncer_, false); std::move(syncer), false);
scheduler_->nudge_tracker_.SetDefaultNudgeDelay(default_delay()); scheduler_->nudge_tracker_.SetDefaultNudgeDelay(default_delay());
} }
...@@ -407,11 +408,12 @@ class SyncSchedulerImplTest : public testing::Test { ...@@ -407,11 +408,12 @@ class SyncSchedulerImplTest : public testing::Test {
} }
void NewSchedulerForLocalBackend() { void NewSchedulerForLocalBackend() {
// The old syncer is destroyed with the scheduler that owns it. auto syncer = std::make_unique<testing::StrictMock<MockSyncer>>();
syncer_ = new testing::StrictMock<MockSyncer>(); // The syncer is destroyed with the scheduler that owns it.
syncer_ = syncer.get();
scheduler_ = std::make_unique<SyncSchedulerImpl>( scheduler_ = std::make_unique<SyncSchedulerImpl>(
"TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(),
syncer_, true); std::move(syncer), true);
scheduler_->nudge_tracker_.SetDefaultNudgeDelay(default_delay()); scheduler_->nudge_tracker_.SetDefaultNudgeDelay(default_delay());
} }
......
...@@ -169,12 +169,12 @@ class SyncerTest : public testing::Test, ...@@ -169,12 +169,12 @@ class SyncerTest : public testing::Test,
"fake_invalidator_client_id", local_cache_guid(), "fake_invalidator_client_id", local_cache_guid(),
mock_server_->store_birthday(), "fake_bag_of_chips", mock_server_->store_birthday(), "fake_bag_of_chips",
/*poll_interval=*/base::TimeDelta::FromMinutes(30)); /*poll_interval=*/base::TimeDelta::FromMinutes(30));
syncer_ = new Syncer(&cancelation_signal_); auto syncer = std::make_unique<Syncer>(&cancelation_signal_);
// The syncer is destroyed with the scheduler that owns it.
syncer_ = syncer.get();
scheduler_ = std::make_unique<SyncSchedulerImpl>( scheduler_ = std::make_unique<SyncSchedulerImpl>(
"TestSyncScheduler", BackoffDelayProvider::FromDefaults(), "TestSyncScheduler", BackoffDelayProvider::FromDefaults(),
context_.get(), context_.get(), std::move(syncer), false);
// scheduler_ owned syncer_ now and will manage the memory of syncer_
syncer_, false);
mock_server_->SetKeystoreKey("encryption_key"); mock_server_->SetKeystoreKey("encryption_key");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment