blob: dfd9d559a7a17d16088297df7a6817bcb0936bd4 [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "peridot/bin/ledger/testing/cloud_provider/fake_device_set.h"
#include "peridot/lib/convert/convert.h"
namespace ledger {
FakeDeviceSet::FakeDeviceSet(CloudEraseOnCheck cloud_erase_on_check,
CloudEraseFromWatcher cloud_erase_from_watcher)
: cloud_erase_on_check_(cloud_erase_on_check),
cloud_erase_from_watcher_(cloud_erase_from_watcher) {}
FakeDeviceSet::~FakeDeviceSet() {}
void FakeDeviceSet::CheckFingerprint(std::vector<uint8_t> fingerprint,
CheckFingerprintCallback callback) {
if (cloud_erase_on_check_ == CloudEraseOnCheck::YES ||
!fingerprints_.count(convert::ToString(fingerprint))) {
callback(cloud_provider::Status::NOT_FOUND);
return;
}
callback(cloud_provider::Status::OK);
}
void FakeDeviceSet::SetFingerprint(std::vector<uint8_t> fingerprint,
SetFingerprintCallback callback) {
fingerprints_.insert(convert::ToString(fingerprint));
callback(cloud_provider::Status::OK);
}
void FakeDeviceSet::SetWatcher(
std::vector<uint8_t> /*fingerprint*/,
fidl::InterfaceHandle<cloud_provider::DeviceSetWatcher> watcher,
SetWatcherCallback callback) {
watcher_ = watcher.Bind();
callback(cloud_provider::Status::OK);
if (cloud_erase_from_watcher_ == CloudEraseFromWatcher::YES) {
watcher_->OnCloudErased();
}
}
void FakeDeviceSet::Erase(EraseCallback callback) {
fingerprints_.clear();
if (watcher_.is_bound()) {
watcher_->OnCloudErased();
}
callback(cloud_provider::Status::OK);
}
} // namespace ledger