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(
SyncCycleContext* context,
CancelationSignal* cancelation_signal,
bool ignore_auth_credentials) {
std::unique_ptr<BackoffDelayProvider> delay(
BackoffDelayProvider::FromDefaults());
if (switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE) {
delay.reset(BackoffDelayProvider::WithShortInitialRetryOverride());
}
std::unique_ptr<BackoffDelayProvider> delay =
(switches_.backoff_override == BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE)
? BackoffDelayProvider::WithShortInitialRetryOverride()
: BackoffDelayProvider::FromDefaults();
std::unique_ptr<SyncSchedulerImpl> scheduler =
std::make_unique<SyncSchedulerImpl>(name, delay.release(), context,
new Syncer(cancelation_signal),
ignore_auth_credentials);
std::make_unique<SyncSchedulerImpl>(
name, std::move(delay), context,
std::make_unique<Syncer>(cancelation_signal),
ignore_auth_credentials);
if (switches_.force_short_nudge_delay_for_test) {
scheduler->ForceShortNudgeDelayForTest();
}
......
......@@ -8,6 +8,7 @@
#include <algorithm>
#include "base/memory/ptr_util.h"
#include "base/rand_util.h"
#include "components/sync/base/syncer_error.h"
#include "components/sync/engine/cycle/model_neutral_state.h"
......@@ -18,17 +19,20 @@ using base::TimeDelta;
namespace syncer {
// static
BackoffDelayProvider* BackoffDelayProvider::FromDefaults() {
return new BackoffDelayProvider(
std::unique_ptr<BackoffDelayProvider> BackoffDelayProvider::FromDefaults() {
// base::WrapUnique() used because the constructor is private.
return base::WrapUnique(new BackoffDelayProvider(
TimeDelta::FromSeconds(kInitialBackoffRetrySeconds),
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds));
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)));
}
// static
BackoffDelayProvider* BackoffDelayProvider::WithShortInitialRetryOverride() {
return new BackoffDelayProvider(
std::unique_ptr<BackoffDelayProvider>
BackoffDelayProvider::WithShortInitialRetryOverride() {
// base::WrapUnique() used because the constructor is private.
return base::WrapUnique(new BackoffDelayProvider(
TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds),
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds));
TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)));
}
BackoffDelayProvider::BackoffDelayProvider(
......
......@@ -5,6 +5,8 @@
#ifndef 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/time/time.h"
......@@ -16,7 +18,7 @@ struct ModelNeutralState;
class BackoffDelayProvider {
public:
// 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
// polling_constants.h) when it encounters an error before exponential
......@@ -24,7 +26,7 @@ class BackoffDelayProvider {
//
// *** NOTE *** This should only be used if kSyncShortInitialRetryOverride
// was passed to command line.
static BackoffDelayProvider* WithShortInitialRetryOverride();
static std::unique_ptr<BackoffDelayProvider> WithShortInitialRetryOverride();
virtual ~BackoffDelayProvider();
......
......@@ -116,17 +116,18 @@ ConfigurationParams::~ConfigurationParams() = default;
#define SDVLOG_LOC(from_here, verbose_level) \
DVLOG_LOC(from_here, verbose_level) << name_ << ": "
SyncSchedulerImpl::SyncSchedulerImpl(const std::string& name,
BackoffDelayProvider* delay_provider,
SyncCycleContext* context,
Syncer* syncer,
bool ignore_auth_credentials)
SyncSchedulerImpl::SyncSchedulerImpl(
const std::string& name,
std::unique_ptr<BackoffDelayProvider> delay_provider,
SyncCycleContext* context,
std::unique_ptr<Syncer> syncer,
bool ignore_auth_credentials)
: name_(name),
started_(false),
syncer_poll_interval_seconds_(context->poll_interval()),
mode_(CONFIGURATION_MODE),
delay_provider_(delay_provider),
syncer_(syncer),
delay_provider_(std::move(delay_provider)),
syncer_(std::move(syncer)),
cycle_context_(context),
next_sync_cycle_job_priority_(NORMAL_PRIORITY),
ignore_auth_credentials_(ignore_auth_credentials) {}
......
......@@ -33,12 +33,11 @@ struct ModelNeutralState;
class SyncSchedulerImpl : public SyncScheduler {
public:
// |name| is a display string to identify the syncer thread. Takes
// ownership of |syncer| and |delay_provider|.
// |name| is a display string to identify the syncer thread.
SyncSchedulerImpl(const std::string& name,
BackoffDelayProvider* delay_provider,
std::unique_ptr<BackoffDelayProvider> delay_provider,
SyncCycleContext* context,
Syncer* syncer,
std::unique_ptr<Syncer> syncer,
bool ignore_auth_credentials);
// Calls Stop().
......@@ -254,7 +253,7 @@ class SyncSchedulerImpl : public SyncScheduler {
NudgeTracker nudge_tracker_;
// Invoked to run through the sync cycle.
std::unique_ptr<Syncer> syncer_;
const std::unique_ptr<Syncer> syncer_;
SyncCycleContext* cycle_context_;
......
......@@ -282,11 +282,12 @@ class SyncSchedulerImplTest : public testing::Test {
}
void RebuildScheduler() {
// The old syncer is destroyed with the scheduler that owns it.
syncer_ = new testing::StrictMock<MockSyncer>();
auto syncer = std::make_unique<testing::StrictMock<MockSyncer>>();
// The syncer is destroyed with the scheduler that owns it.
syncer_ = syncer.get();
scheduler_ = std::make_unique<SyncSchedulerImpl>(
"TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(),
syncer_, false);
std::move(syncer), false);
scheduler_->nudge_tracker_.SetDefaultNudgeDelay(default_delay());
}
......@@ -407,11 +408,12 @@ class SyncSchedulerImplTest : public testing::Test {
}
void NewSchedulerForLocalBackend() {
// The old syncer is destroyed with the scheduler that owns it.
syncer_ = new testing::StrictMock<MockSyncer>();
auto syncer = std::make_unique<testing::StrictMock<MockSyncer>>();
// The syncer is destroyed with the scheduler that owns it.
syncer_ = syncer.get();
scheduler_ = std::make_unique<SyncSchedulerImpl>(
"TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(),
syncer_, true);
std::move(syncer), true);
scheduler_->nudge_tracker_.SetDefaultNudgeDelay(default_delay());
}
......
......@@ -169,12 +169,12 @@ class SyncerTest : public testing::Test,
"fake_invalidator_client_id", local_cache_guid(),
mock_server_->store_birthday(), "fake_bag_of_chips",
/*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>(
"TestSyncScheduler", BackoffDelayProvider::FromDefaults(),
context_.get(),
// scheduler_ owned syncer_ now and will manage the memory of syncer_
syncer_, false);
context_.get(), std::move(syncer), false);
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